|
@@ -1,8 +1,8 @@
|
|
|
-import { useEffect, useMemo, useState } from 'react';
|
|
|
|
|
|
|
+import { useEffect, useState } from 'react';
|
|
|
|
|
|
|
|
-import { PlanTagType, PayMethodType } from '@/defines';
|
|
|
|
|
|
|
+import { PlanTagType } from '@/defines';
|
|
|
import { userConfigModel } from '@/models/userConfigModel';
|
|
import { userConfigModel } from '@/models/userConfigModel';
|
|
|
-import { fetchGetUserConfig, fetchPlanList } from '@/services/config';
|
|
|
|
|
|
|
+import { fetchGetUserConfig, fetchPlanList, fetchPayTypeList } from '@/services/config';
|
|
|
import { setToken, userKey } from '@/utils/authUtils';
|
|
import { setToken, userKey } from '@/utils/authUtils';
|
|
|
import { secureLocalStorage as ls } from '@/utils/localUtils';
|
|
import { secureLocalStorage as ls } from '@/utils/localUtils';
|
|
|
import { getUniqueSign } from '@/utils/stringUtils';
|
|
import { getUniqueSign } from '@/utils/stringUtils';
|
|
@@ -20,13 +20,15 @@ export interface Plan {
|
|
|
|
|
|
|
|
export interface UseServiceReturn {
|
|
export interface UseServiceReturn {
|
|
|
plans: Plan[];
|
|
plans: Plan[];
|
|
|
- payMethods: PayMethodType[];
|
|
|
|
|
|
|
+ payMethods: API.PayTypeItem[];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export function useService(): UseServiceReturn {
|
|
export function useService(): UseServiceReturn {
|
|
|
const { setUserConfig } = userConfigModel.useModel();
|
|
const { setUserConfig } = userConfigModel.useModel();
|
|
|
|
|
|
|
|
const [plans, setPlans] = useState<Plan[]>([]);
|
|
const [plans, setPlans] = useState<Plan[]>([]);
|
|
|
|
|
+ const [payMethods, setPayMethods] = useState<API.PayTypeItem[]>([]);
|
|
|
|
|
+
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
const userinfo = ls.getLocal<API.UserInfo>(userKey);
|
|
const userinfo = ls.getLocal<API.UserInfo>(userKey);
|
|
|
const expired = (userinfo?.accessExpires ?? 0) - currentUnixTimestamp() <= 0;
|
|
const expired = (userinfo?.accessExpires ?? 0) - currentUnixTimestamp() <= 0;
|
|
@@ -61,16 +63,14 @@ export function useService(): UseServiceReturn {
|
|
|
.catch(() => {});
|
|
.catch(() => {});
|
|
|
}, []);
|
|
}, []);
|
|
|
|
|
|
|
|
- const payMethods = useMemo<PayMethodType[]>(
|
|
|
|
|
- () => [
|
|
|
|
|
- PayMethodType.APPLE_PAY,
|
|
|
|
|
- PayMethodType.GOOGLE_PAY,
|
|
|
|
|
- // PayMethodType.PAYPAL,
|
|
|
|
|
- // PayMethodType.WECHAT,
|
|
|
|
|
- // PayMethodType.ALIPAY,
|
|
|
|
|
- ],
|
|
|
|
|
- []
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ fetchPayTypeList({})
|
|
|
|
|
+ .then((res) => {
|
|
|
|
|
+ const list = res?.data?.payTypeList ?? [];
|
|
|
|
|
+ setPayMethods(list);
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch(() => {});
|
|
|
|
|
+ }, []);
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
plans,
|
|
plans,
|