diff --git a/packages/plugins/Claim/src/SNSAdaptor/components/ITOActivities/index.tsx b/packages/plugins/Claim/src/SNSAdaptor/components/ITOActivities/index.tsx index 8dc0d4be2da..67f64f873a2 100644 --- a/packages/plugins/Claim/src/SNSAdaptor/components/ITOActivities/index.tsx +++ b/packages/plugins/Claim/src/SNSAdaptor/components/ITOActivities/index.tsx @@ -1,9 +1,8 @@ -import { useChainContext, useFungibleTokens } from '@masknet/web3-hooks-base' +import { useChainContext } from '@masknet/web3-hooks-base' import { memo, useCallback } from 'react' import { useClaimAll } from '../../../hooks/useClaimAll.js' -import { EMPTY_LIST, NetworkPluginID } from '@masknet/shared-base' -import { isSameAddress, type FungibleToken } from '@masknet/web3-shared-base' -import { useITOConstants, type ChainId, type SchemaType } from '@masknet/web3-shared-evm' +import { type NetworkPluginID } from '@masknet/shared-base' +import { useITOConstants } from '@masknet/web3-shared-evm' import { makeStyles, LoadingBase } from '@masknet/theme' import { Box } from '@mui/material' import { useI18N } from '../../../locales/i18n_generated.js' @@ -35,26 +34,7 @@ export const ITOActivities = memo(() => { const { classes } = useStyles() const { account, chainId } = useChainContext() - const { value: _swappedTokens, loading: _loading, retry } = useClaimAll(account, chainId) - - const { value: swappedTokensWithDetailed = EMPTY_LIST, loading: loadingTokenDetailed } = useFungibleTokens( - NetworkPluginID.PLUGIN_EVM, - (_swappedTokens ?? EMPTY_LIST).map((t) => t.token.address) ?? EMPTY_LIST, - { - chainId, - }, - ) - - const loading = _loading || loadingTokenDetailed - - const swappedTokens = _swappedTokens?.map((t) => { - const tokenDetailed = swappedTokensWithDetailed.find((v) => isSameAddress(t.token.address, v.address)) - - return { - ...t, - token: (tokenDetailed as FungibleToken) ?? t.token, - } - }) + const { value: swappedTokens, loading: _loading, retry } = useClaimAll(account, chainId) const { ITO2_CONTRACT_ADDRESS } = useITOConstants(chainId) const handleClaim = useClaimCallback(ITO2_CONTRACT_ADDRESS) @@ -68,7 +48,7 @@ export const ITOActivities = memo(() => { [handleClaim], ) - if (loading) + if (_loading) return ( diff --git a/packages/plugins/Claim/src/hooks/useClaimAll.ts b/packages/plugins/Claim/src/hooks/useClaimAll.ts index 24dddcd4a16..df53a47d73a 100644 --- a/packages/plugins/Claim/src/hooks/useClaimAll.ts +++ b/packages/plugins/Claim/src/hooks/useClaimAll.ts @@ -1,10 +1,11 @@ import { NetworkPluginID } from '@masknet/shared-base' import { useChainContext, useNetworkContext, useWeb3Connection } from '@masknet/web3-hooks-base' -import type { ChainId } from '@masknet/web3-shared-evm' +import type { ChainId, SchemaType } from '@masknet/web3-shared-evm' import { useRef, useEffect } from 'react' import { useAsyncRetry } from 'react-use' import { getClaimAllPools } from '../utils/index.js' import type { SwappedTokenType } from '../types.js' +import type { FungibleToken } from '@masknet/web3-shared-base' export function useClaimAll(swapperAddress: string, chainId: ChainId) { const { account } = useChainContext() @@ -21,8 +22,17 @@ export function useClaimAll(swapperAddress: string, chainId: ChainId) { if (allPoolsRef.current.length > 0 || !connection) return allPoolsRef.current const blockNumber = await connection.getBlockNumber() const results = await getClaimAllPools(chainId, blockNumber, swapperAddress, connection) + const resultsWithToken = await Promise.all( + results.map(async (x) => { + const tokenDetailed = await connection.getFungibleToken(x.token.address) - allPoolsRef.current = results + return { + ...x, + token: (tokenDetailed as FungibleToken) ?? x.token, + } + }), + ) + allPoolsRef.current = resultsWithToken return allPoolsRef.current }, [swapperAddress, chainId, connection, pluginID, account])