Skip to content

Commit

Permalink
fix: load new account assets error in all networks (#6262)
Browse files Browse the repository at this point in the history
* fix: load new account assets error in all networks

* fix: lint

* fix: lint

* fix: lint
  • Loading branch information
weatherstar authored Nov 22, 2024
1 parent 5c1c3f7 commit 68a1bbc
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 42 deletions.
52 changes: 25 additions & 27 deletions packages/kit/src/hooks/useAllNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@ import { useEffect, useRef, useState } from 'react';

import { isEmpty } from 'lodash';

import type {
IDBAccount,
IDBWallet,
} from '@onekeyhq/kit-bg/src/dbs/local/types';
import type { IDBAccount } from '@onekeyhq/kit-bg/src/dbs/local/types';
import type { ISimpleDBLocalTokens } from '@onekeyhq/kit-bg/src/dbs/simple/entity/SimpleDbEntityLocalTokens';
import type { IAllNetworkAccountInfo } from '@onekeyhq/kit-bg/src/services/ServiceAllNetwork/ServiceAllNetwork';
import { POLLING_DEBOUNCE_INTERVAL } from '@onekeyhq/shared/src/consts/walletConsts';
import { generateUUID } from '@onekeyhq/shared/src/utils/miscUtils';
import perfUtils, {
EPerformanceTimerLogNames,
} from '@onekeyhq/shared/src/utils/perfUtils';
import type { IServerNetwork } from '@onekeyhq/shared/types';
import type { INetworkAccount } from '@onekeyhq/shared/types/account';

import backgroundApiProxy from '../background/instance/backgroundApiProxy';

Expand Down Expand Up @@ -52,9 +47,10 @@ const currentRequestsUUID = { current: '' };
// };

function useAllNetworkRequests<T>(params: {
account: INetworkAccount | undefined;
network: IServerNetwork | undefined;
wallet: IDBWallet | undefined;
accountId: string | undefined;
networkId: string | undefined;
walletId: string | undefined;
isAllNetworks: boolean | undefined;
allNetworkRequests: ({
accountId,
networkId,
Expand Down Expand Up @@ -119,9 +115,10 @@ function useAllNetworkRequests<T>(params: {
}) => void;
}) {
const {
account,
network,
wallet,
accountId: currentAccountId,
networkId: currentNetworkId,
walletId: currentWalletId,
isAllNetworks,
allNetworkRequests,
allNetworkCacheRequests,
allNetworkCacheData,
Expand All @@ -146,8 +143,8 @@ function useAllNetworkRequests<T>(params: {

if (disabled) return;
if (isFetching.current) return;
if (!account || !network || !wallet) return;
if (!network.isAllNetworks) return;
if (!currentAccountId || !currentNetworkId || !currentWalletId) return;
if (!isAllNetworks) return;
isFetching.current = true;

if (!allNetworkDataInit.current) {
Expand All @@ -169,8 +166,8 @@ function useAllNetworkRequests<T>(params: {
} =
await backgroundApiProxy.serviceAllNetwork.getAllNetworkAccountsWithEnabledNetworks(
{
accountId: account.id,
networkId: network.id,
accountId: currentAccountId,
networkId: currentNetworkId,
deriveType: undefined,
nftEnabledOnly: isNFTRequests,
},
Expand Down Expand Up @@ -198,8 +195,8 @@ function useAllNetworkRequests<T>(params: {
setIsEmptyAccount(false);

onStarted?.({
accountId: account.id,
networkId: network.id,
accountId: currentAccountId,
networkId: currentNetworkId,
});

if (!allNetworkDataInit.current) {
Expand Down Expand Up @@ -239,8 +236,8 @@ function useAllNetworkRequests<T>(params: {
perf.done();
allNetworkCacheData?.({
data: cachedData,
accountId: account.id,
networkId: network.id,
accountId: currentAccountId,
networkId: currentNetworkId,
});
}
} catch (e) {
Expand Down Expand Up @@ -356,17 +353,18 @@ function useAllNetworkRequests<T>(params: {
allNetworkDataInit.current = true;
isFetching.current = false;
onFinished?.({
accountId: account.id,
networkId: network.id,
accountId: currentAccountId,
networkId: currentNetworkId,
});

return resp;
},
[
disabled,
account,
network,
wallet,
currentAccountId,
currentNetworkId,
currentWalletId,
isAllNetworks,
abortAllNetworkRequests,
isNFTRequests,
allNetworkAccountsData,
Expand All @@ -385,10 +383,10 @@ function useAllNetworkRequests<T>(params: {
);

useEffect(() => {
if (account?.id && network?.id && wallet?.id) {
if (currentAccountId && currentNetworkId && currentWalletId) {
allNetworkDataInit.current = false;
}
}, [account?.id, network?.id, wallet?.id]);
}, [currentAccountId, currentNetworkId, currentWalletId]);

return {
run,
Expand Down
7 changes: 4 additions & 3 deletions packages/kit/src/views/Home/pages/NFTListContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,10 @@ function NFTListContainer(props: ITabPageProps) {
result: allNetworksResult,
isEmptyAccount,
} = useAllNetworkRequests<IFetchAccountNFTsResp>({
account,
network,
wallet,
accountId: account?.id,
networkId: network?.id,
walletId: wallet?.id,
isAllNetworks: network?.isAllNetworks,
allNetworkRequests: handleAllNetworkRequests,
allNetworkCacheRequests: handleAllNetworkCacheRequests,
allNetworkCacheData: handleAllNetworkCacheData,
Expand Down
7 changes: 4 additions & 3 deletions packages/kit/src/views/Home/pages/TokenListContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -787,9 +787,10 @@ function TokenListContainer(props: ITabPageProps) {
result: allNetworksResult,
isEmptyAccount,
} = useAllNetworkRequests<IFetchAccountTokensResp>({
account,
network,
wallet,
accountId: account?.id,
networkId: network?.id,
walletId: wallet?.id,
isAllNetworks: network?.isAllNetworks,
allNetworkRequests: handleAllNetworkRequests,
allNetworkCacheRequests: handleAllNetworkCacheRequests,
allNetworkCacheData: handleAllNetworkCacheData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ export function TokenListContainerPerfTest(props: ITabPageProps) {
}, [setOverview]);

useAllNetworkRequests<IFetchAccountTokensResp>({
account,
network,
wallet,
accountId: account?.id,
networkId: network?.id,
walletId: wallet?.id,
isAllNetworks: network?.isAllNetworks,
allNetworkRequests: empty as any,
allNetworkCacheRequests: handleAllNetworkCacheRequests,
allNetworkCacheData: handleAllNetworkCacheData,
Expand Down
3 changes: 0 additions & 3 deletions packages/kit/src/views/Home/pages/TxHistoryContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ import {
EModalAssetDetailRoutes,
EModalRoutes,
} from '@onekeyhq/shared/src/routes';
// import { sortHistoryTxsByTime } from '@onekeyhq/shared/src/utils/historyUtils';
import networkUtils from '@onekeyhq/shared/src/utils/networkUtils';
import { EHomeTab } from '@onekeyhq/shared/types';
import type { IAccountHistoryTx } from '@onekeyhq/shared/types/history';
import { EDecodedTxStatus } from '@onekeyhq/shared/types/tx';

import { TxHistoryListView } from '../../../components/TxHistoryListView';
// import { useAllNetworkRequests } from '../../../hooks/useAllNetwork';
import useAppNavigation from '../../../hooks/useAppNavigation';
import { usePromiseResult } from '../../../hooks/usePromiseResult';
import { useAccountOverviewActions } from '../../../states/jotai/contexts/accountOverview';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -769,9 +769,7 @@ function WalletAddress({
).length > 0
) {
// TODO performance, always emit when Modal open
setTimeout(() => {
appEventBus.emit(EAppEventBusNames.AccountDataUpdate, undefined);
}, 300);
appEventBus.emit(EAppEventBusNames.AccountDataUpdate, undefined);
}
}, [
accountsCreated,
Expand Down

0 comments on commit 68a1bbc

Please sign in to comment.