Skip to content

Commit

Permalink
fix: auto loading (#10480)
Browse files Browse the repository at this point in the history
  • Loading branch information
guanbinrui committed Aug 18, 2023
1 parent 735dd6f commit 68e6c90
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { useEffect } from 'react'
import { useAsync, useAsyncFn } from 'react-use'
import { toNumber } from 'lodash-es'
import { InjectedDialog } from '@masknet/shared'
import { NetworkPluginID } from '@masknet/shared-base'
import { makeStyles } from '@masknet/theme'
import { LoadingBase, makeStyles } from '@masknet/theme'
import { useFungibleToken, useFungibleTokenPrice } from '@masknet/web3-hooks-base'
import { CoinGeckoTrending, GoPlusLabs } from '@masknet/web3-providers'
import type { SecurityAPI } from '@masknet/web3-providers/types'
import { isSameAddress } from '@masknet/web3-shared-base'
import { ChainId, ZERO_ADDRESS } from '@masknet/web3-shared-evm'
import { Box, DialogActions, DialogContent, Stack } from '@mui/material'
import { toNumber } from 'lodash-es'
import { useEffect } from 'react'
import { useAsync, useAsyncFn } from 'react-use'
import { useI18N } from '../locales/index.js'
import { DefaultPlaceholder } from './components/DefaultPlaceholder.js'
import { Footer } from './components/Footer.js'
import { NotFound } from './components/NotFound.js'
import { SearchBox } from './components/SearchBox.js'
import { Searching } from './components/Searching.js'
import { SecurityPanel } from './components/SecurityPanel.js'

const useStyles = makeStyles()((theme) => ({
Expand Down Expand Up @@ -63,10 +62,10 @@ export function CheckSecurityDialog({ open, onClose, searchHidden, chainId, toke
NetworkPluginID.PLUGIN_EVM,
value?.contract,
)

const { data: tokenPrice } = useFungibleTokenPrice(NetworkPluginID.PLUGIN_EVM, value?.contract, { chainId })
const { value: tokenMarketCap } = useAsync(async () => {
if (!value?.contract || !value.token_symbol) return

const marketInfo = await CoinGeckoTrending.getCoinMarketInfo(value.contract)
return marketInfo?.market_cap ? toNumber(marketInfo.market_cap) : undefined
}, [value?.contract, !value?.token_symbol])
Expand All @@ -83,7 +82,7 @@ export function CheckSecurityDialog({ open, onClose, searchHidden, chainId, toke
<Stack flex={1}>
{searching || loadingToken ? (
<Stack height="100%" justifyContent="center" alignItems="center">
<Searching />
<LoadingBase size={36} />
</Stack>
) : null}
{error && !searching && !loadingToken ? <NotFound /> : null}
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion packages/web3-hooks/base/src/useFungibleToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function useFungibleToken<S extends 'all' | void = void, T extends Networ
const networks = useNetworks(pluginID)

return useQuery({
enabled: !!address,
enabled: true,
queryKey: ['fungible-token', pluginID, address, chainId, options],
queryFn: async () => {
if (!address) return
Expand Down

0 comments on commit 68e6c90

Please sign in to comment.