Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/gas-account' into tmp/20240830
Browse files Browse the repository at this point in the history
  • Loading branch information
dmy147 committed Sep 3, 2024
2 parents 76147aa + 5e8cfb1 commit 6e94a39
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
28 changes: 13 additions & 15 deletions src/ui/views/GasAccount/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const useGasAccountInfo = () => {
dispatch.gasAccount.setGasAccountSig({});
return undefined;
});
}, [sig, refreshId]);
}, [sig, accountId, refreshId]);

if (error?.message?.includes('failed') && sig && accountId) {
dispatch.gasAccount.setGasAccountSig({});
Expand Down Expand Up @@ -80,15 +80,17 @@ export const useGasAccountMethods = () => {
return { login, logout };
};

export const useGasAccountLogin = () => {
export const useGasAccountLogin = ({
loading,
value,
}: ReturnType<typeof useGasAccountInfo>) => {
const { sig, accountId } = useGasAccountSign();
const { loading, value } = useGasAccountInfo();

const { login, logout } = useGasAccountMethods();

const isLogin = useMemo(
() => (!loading ? !!value?.account?.id : !!sig && !!accountId),
[sig, accountId, loading, value]
[sig, accountId, loading, value?.account?.id]
);

return { login, logout, isLogin };
Expand All @@ -104,7 +106,7 @@ export const useGasAccountHistory = () => {
setRefreshListTx((e) => e + 1);
}, []);

const { refresh } = useGasAccountRefresh();
const { refresh: refreshGasAccountBalance } = useGasAccountRefresh();

type History = Awaited<
ReturnType<typeof wallet.openapi.getGasAccountHistory>
Expand Down Expand Up @@ -144,16 +146,16 @@ export const useGasAccountHistory = () => {
reloadDeps: [sig],
isNoMore(data) {
if (data) {
return data?.list.length >= data?.totalCount;
return !(!!data?.rechargeList && data?.rechargeList?.length > 0);
}
return true;
},
manual: !sig,
manual: !sig || !accountId,
}
);

const { value } = useAsync(async () => {
if (sig && accountId) {
if (sig && accountId && refreshTxListCount) {
return wallet.openapi.getGasAccountHistory({
sig,
account_id: accountId,
Expand All @@ -170,8 +172,8 @@ export const useGasAccountHistory = () => {
return;
}

if (d.rechargeList.length !== value?.recharge_list?.length) {
refresh();
if (value?.recharge_list?.length !== d.rechargeList.length) {
refreshGasAccountBalance();
}
return {
rechargeList: value?.recharge_list,
Expand All @@ -182,10 +184,6 @@ export const useGasAccountHistory = () => {
),
};
});

if (!value?.recharge_list?.length) {
refresh();
}
}
}, [mutate, value]);

Expand All @@ -209,7 +207,7 @@ export const useGasAccountHistory = () => {
clearTimeout(timer);
}
};
}, [loading, loadingMore, refreshListTx, txList?.list]);
}, [loading, loadingMore, refreshListTx, txList]);

return {
loading,
Expand Down
2 changes: 1 addition & 1 deletion src/ui/views/GasAccount/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const GasAccountInner = () => {
setDepositVisible(true);
};
const { value, loading } = useGasAccountInfo();
const { isLogin } = useGasAccountLogin();
const { isLogin } = useGasAccountLogin({ value, loading });

const wallet = useWallet();

Expand Down

0 comments on commit 6e94a39

Please sign in to comment.