Skip to content

Commit

Permalink
chore: code style (#9501)
Browse files Browse the repository at this point in the history
  • Loading branch information
nuanyang233 committed May 4, 2023
1 parent 2c1e024 commit 0fc5d10
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
@@ -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'
Expand Down Expand Up @@ -35,26 +34,7 @@ export const ITOActivities = memo(() => {
const { classes } = useStyles()
const { account, chainId } = useChainContext<NetworkPluginID.PLUGIN_EVM>()

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<ChainId, SchemaType.ERC20 | SchemaType.Native>) ?? t.token,
}
})
const { value: swappedTokens, loading: _loading, retry } = useClaimAll(account, chainId)

const { ITO2_CONTRACT_ADDRESS } = useITOConstants(chainId)
const handleClaim = useClaimCallback(ITO2_CONTRACT_ADDRESS)
Expand All @@ -68,7 +48,7 @@ export const ITOActivities = memo(() => {
[handleClaim],
)

if (loading)
if (_loading)
return (
<Box className={classes.placeholder}>
<LoadingBase size={24} />
Expand Down
14 changes: 12 additions & 2 deletions 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()
Expand All @@ -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<ChainId, SchemaType.ERC20 | SchemaType.Native>) ?? x.token,
}
}),
)
allPoolsRef.current = resultsWithToken
return allPoolsRef.current
}, [swapperAddress, chainId, connection, pluginID, account])

Expand Down

0 comments on commit 0fc5d10

Please sign in to comment.