diff --git a/packages/kit/src/hooks/useAllNetwork.ts b/packages/kit/src/hooks/useAllNetwork.ts index 5a0051dd202..996dfb857ee 100644 --- a/packages/kit/src/hooks/useAllNetwork.ts +++ b/packages/kit/src/hooks/useAllNetwork.ts @@ -2,10 +2,7 @@ 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'; @@ -13,8 +10,6 @@ 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'; @@ -52,9 +47,10 @@ const currentRequestsUUID = { current: '' }; // }; function useAllNetworkRequests(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, @@ -119,9 +115,10 @@ function useAllNetworkRequests(params: { }) => void; }) { const { - account, - network, - wallet, + accountId: currentAccountId, + networkId: currentNetworkId, + walletId: currentWalletId, + isAllNetworks, allNetworkRequests, allNetworkCacheRequests, allNetworkCacheData, @@ -146,8 +143,8 @@ function useAllNetworkRequests(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) { @@ -169,8 +166,8 @@ function useAllNetworkRequests(params: { } = await backgroundApiProxy.serviceAllNetwork.getAllNetworkAccountsWithEnabledNetworks( { - accountId: account.id, - networkId: network.id, + accountId: currentAccountId, + networkId: currentNetworkId, deriveType: undefined, nftEnabledOnly: isNFTRequests, }, @@ -198,8 +195,8 @@ function useAllNetworkRequests(params: { setIsEmptyAccount(false); onStarted?.({ - accountId: account.id, - networkId: network.id, + accountId: currentAccountId, + networkId: currentNetworkId, }); if (!allNetworkDataInit.current) { @@ -239,8 +236,8 @@ function useAllNetworkRequests(params: { perf.done(); allNetworkCacheData?.({ data: cachedData, - accountId: account.id, - networkId: network.id, + accountId: currentAccountId, + networkId: currentNetworkId, }); } } catch (e) { @@ -356,17 +353,18 @@ function useAllNetworkRequests(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, @@ -385,10 +383,10 @@ function useAllNetworkRequests(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, diff --git a/packages/kit/src/views/Home/pages/NFTListContainer.tsx b/packages/kit/src/views/Home/pages/NFTListContainer.tsx index 4e0d89ccbcc..fc727065b50 100644 --- a/packages/kit/src/views/Home/pages/NFTListContainer.tsx +++ b/packages/kit/src/views/Home/pages/NFTListContainer.tsx @@ -212,9 +212,10 @@ function NFTListContainer(props: ITabPageProps) { result: allNetworksResult, isEmptyAccount, } = useAllNetworkRequests({ - account, - network, - wallet, + accountId: account?.id, + networkId: network?.id, + walletId: wallet?.id, + isAllNetworks: network?.isAllNetworks, allNetworkRequests: handleAllNetworkRequests, allNetworkCacheRequests: handleAllNetworkCacheRequests, allNetworkCacheData: handleAllNetworkCacheData, diff --git a/packages/kit/src/views/Home/pages/TokenListContainer.tsx b/packages/kit/src/views/Home/pages/TokenListContainer.tsx index 2259a9bd1e3..69991c05851 100644 --- a/packages/kit/src/views/Home/pages/TokenListContainer.tsx +++ b/packages/kit/src/views/Home/pages/TokenListContainer.tsx @@ -787,9 +787,10 @@ function TokenListContainer(props: ITabPageProps) { result: allNetworksResult, isEmptyAccount, } = useAllNetworkRequests({ - account, - network, - wallet, + accountId: account?.id, + networkId: network?.id, + walletId: wallet?.id, + isAllNetworks: network?.isAllNetworks, allNetworkRequests: handleAllNetworkRequests, allNetworkCacheRequests: handleAllNetworkCacheRequests, allNetworkCacheData: handleAllNetworkCacheData, diff --git a/packages/kit/src/views/Home/pages/TokenListContainerPerfTest.tsx b/packages/kit/src/views/Home/pages/TokenListContainerPerfTest.tsx index bee2d5570bf..887539ec7b8 100644 --- a/packages/kit/src/views/Home/pages/TokenListContainerPerfTest.tsx +++ b/packages/kit/src/views/Home/pages/TokenListContainerPerfTest.tsx @@ -99,9 +99,10 @@ export function TokenListContainerPerfTest(props: ITabPageProps) { }, [setOverview]); useAllNetworkRequests({ - account, - network, - wallet, + accountId: account?.id, + networkId: network?.id, + walletId: wallet?.id, + isAllNetworks: network?.isAllNetworks, allNetworkRequests: empty as any, allNetworkCacheRequests: handleAllNetworkCacheRequests, allNetworkCacheData: handleAllNetworkCacheData, diff --git a/packages/kit/src/views/Home/pages/TxHistoryContainer.tsx b/packages/kit/src/views/Home/pages/TxHistoryContainer.tsx index ef4741d1a7e..248a1dfe7a8 100644 --- a/packages/kit/src/views/Home/pages/TxHistoryContainer.tsx +++ b/packages/kit/src/views/Home/pages/TxHistoryContainer.tsx @@ -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'; diff --git a/packages/kit/src/views/WalletAddress/pages/WalletAddress/index.tsx b/packages/kit/src/views/WalletAddress/pages/WalletAddress/index.tsx index 87a7e851930..c0e443f238d 100644 --- a/packages/kit/src/views/WalletAddress/pages/WalletAddress/index.tsx +++ b/packages/kit/src/views/WalletAddress/pages/WalletAddress/index.tsx @@ -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,