From 24bf7054a7c277fa223556391363bc44b3753f46 Mon Sep 17 00:00:00 2001 From: zhouhanseng Date: Mon, 14 Mar 2022 12:35:34 +0800 Subject: [PATCH 1/4] refactor: use native token hook --- .../Wallets/components/Transfer/TransferERC20.tsx | 4 ++-- .../pages/Wallets/components/Transfer/index.tsx | 2 +- .../pages/Wallets/hooks/useERC20TokensDetailed.ts | 2 +- .../pages/Wallet/ContractInteraction/index.tsx | 2 +- .../pages/Wallet/GasSetting/GasSetting1559.tsx | 2 +- .../Wallet/GasSetting/Prior1559GasSetting.tsx | 2 +- .../pages/Wallet/ReplaceTransaction/index.tsx | 2 +- .../popups/pages/Wallet/TokenDetail/index.tsx | 2 +- .../popups/pages/Wallet/Transfer/Transfer1559.tsx | 2 +- .../src/plugins/NextID/contexts/TipContext.tsx | 2 +- .../RedPacket/SNSAdaptor/RedPacketERC20Form.tsx | 2 +- .../src/plugins/Savings/SNSAdaptor/SavingsForm.tsx | 2 +- .../SNSAdaptor/trader/GasPrior1559Settings.tsx | 2 +- .../SNSAdaptor/trader/hooks/useSortedTrades.ts | 2 +- .../SNSAdaptor/GasSettingDialog/GasSetting1559.tsx | 2 +- .../SNSAdaptor/GasSettingDialog/GasSettingBar.tsx | 2 +- .../GasSettingDialog/Prior1559GasSetting.tsx | 4 ++-- .../WalletStatusDialog/TransactionDescription.tsx | 4 ++-- .../getRedpacketDescription.tsx | 2 +- .../src/UI/components/ERC20TokenList/index.tsx | 2 +- packages/web3-shared/evm/hooks/useAssets.ts | 14 ++++---------- .../evm/hooks/useFungibleTokenDetailed.ts | 4 +++- .../evm/hooks/useFungibleTokenWatched.tsx | 2 +- .../evm/hooks/useNativeTokenDetailed.ts | 4 ++-- 24 files changed, 33 insertions(+), 37 deletions(-) diff --git a/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC20.tsx b/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC20.tsx index 10d552a65597..683edbba90d0 100644 --- a/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC20.tsx +++ b/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC20.tsx @@ -105,7 +105,7 @@ export const TransferERC20 = memo(({ token }) => { const transferAmount = rightShift(amount || '0', selectedToken.decimals).toFixed() const erc20GasLimit = useGasLimit( selectedToken.type === TokenType.Fungible - ? selectedToken.symbol === nativeToken.value?.symbol + ? selectedToken.symbol === nativeToken.symbol ? EthereumTokenType.Native : EthereumTokenType.ERC20 : selectedToken.type, @@ -314,7 +314,7 @@ export const TransferERC20 = memo(({ token }) => { {t.transfer_cost({ gasFee: formatWeiToEther(gasFee).toFixed(6), - symbol: nativeToken.value?.symbol ?? '', + symbol: nativeToken.symbol ?? '', usd: gasFeeInUsd.toFixed(2), })} diff --git a/packages/dashboard/src/pages/Wallets/components/Transfer/index.tsx b/packages/dashboard/src/pages/Wallets/components/Transfer/index.tsx index 6a6fbaafdcc0..3a3b1b471d60 100644 --- a/packages/dashboard/src/pages/Wallets/components/Transfer/index.tsx +++ b/packages/dashboard/src/pages/Wallets/components/Transfer/index.tsx @@ -19,7 +19,7 @@ export const Transfer = memo(() => { const { state } = useLocation() as { state: { token?: Web3Plugin.FungibleToken; erc721Token?: ERC721TokenDetailed; type?: TransferTab } | null } - const { value: nativeToken } = useNativeTokenDetailed() + const nativeToken = useNativeTokenDetailed() const transferTabsLabel: Record = { [TransferTab.Token]: t.wallets_assets_token(), [TransferTab.Collectibles]: t.wallets_assets_collectibles(), diff --git a/packages/dashboard/src/pages/Wallets/hooks/useERC20TokensDetailed.ts b/packages/dashboard/src/pages/Wallets/hooks/useERC20TokensDetailed.ts index 3d5d5cad4ab0..3c99c96ef49d 100644 --- a/packages/dashboard/src/pages/Wallets/hooks/useERC20TokensDetailed.ts +++ b/packages/dashboard/src/pages/Wallets/hooks/useERC20TokensDetailed.ts @@ -12,7 +12,7 @@ import { useMemo } from 'react' export function useERC20TokensDetailed() { const { ERC20 } = useTokenListConstants() - const { value: nativeTokenDetailed } = useNativeTokenDetailed() + const nativeTokenDetailed = useNativeTokenDetailed() const { value: erc20TokensDetailed = [], loading: erc20TokensDetailedLoading } = useERC20TokensDetailedFromTokenLists(ERC20) diff --git a/packages/mask/src/extension/popups/pages/Wallet/ContractInteraction/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/ContractInteraction/index.tsx index 7042c2d50e17..fded25e4517c 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/ContractInteraction/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/ContractInteraction/index.tsx @@ -231,7 +231,7 @@ const ContractInteraction = memo(() => { }, [request, t]) // token detailed - const { value: nativeToken } = useNativeTokenDetailed() + const nativeToken = useNativeTokenDetailed() const { value: token } = useERC20TokenDetailed(isNativeTokenInteraction ? '' : tokenAddress) // gas price diff --git a/packages/mask/src/extension/popups/pages/Wallet/GasSetting/GasSetting1559.tsx b/packages/mask/src/extension/popups/pages/Wallet/GasSetting/GasSetting1559.tsx index 88f025173e76..aada266b4a26 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/GasSetting/GasSetting1559.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/GasSetting/GasSetting1559.tsx @@ -120,7 +120,7 @@ export const GasSetting1559 = memo(() => { const navigate = useNavigate() const [selected, setOption] = useState(null) const [getGasLimitError, setGetGasLimitError] = useState(false) - const { value: nativeToken } = useNativeTokenDetailed() + const nativeToken = useNativeTokenDetailed() const nativeTokenPrice = useNativeTokenPrice(nativeToken?.chainId) const { value, loading: getValueLoading } = useUnconfirmedRequest() diff --git a/packages/mask/src/extension/popups/pages/Wallet/GasSetting/Prior1559GasSetting.tsx b/packages/mask/src/extension/popups/pages/Wallet/GasSetting/Prior1559GasSetting.tsx index 1399b1d08445..412816f6c0ef 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/GasSetting/Prior1559GasSetting.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/GasSetting/Prior1559GasSetting.tsx @@ -104,7 +104,7 @@ export const Prior1559GasSetting = memo(() => { const [getGasLimitError, setGetGasLimitError] = useState(false) const navigate = useNavigate() const [selected, setOption] = useState(null) - const { value: nativeToken } = useNativeTokenDetailed() + const nativeToken = useNativeTokenDetailed() const nativeTokenPrice = useNativeTokenPrice(nativeToken?.chainId) diff --git a/packages/mask/src/extension/popups/pages/Wallet/ReplaceTransaction/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/ReplaceTransaction/index.tsx index d5576acf57ea..ee8d2c7efb6b 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/ReplaceTransaction/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/ReplaceTransaction/index.tsx @@ -76,7 +76,7 @@ const ReplaceTransaction = memo(() => { const defaultMaxPriorityFeePerGas = (transaction?.computedPayload?._tx as EthereumTransactionConfig).maxPriorityFeePerGas ?? 0 - const { value: nativeToken } = useNativeTokenDetailed() + const nativeToken = useNativeTokenDetailed() const nativeTokenPrice = useNativeTokenPrice(nativeToken?.chainId) const networkType = useNetworkType() const is1559 = isEIP1559Supported(getChainIdFromNetworkType(networkType)) diff --git a/packages/mask/src/extension/popups/pages/Wallet/TokenDetail/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/TokenDetail/index.tsx index 42840cfa30f6..b48d7516b37c 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/TokenDetail/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/TokenDetail/index.tsx @@ -70,7 +70,7 @@ const TokenDetail = memo(() => { const wallet = useWallet() const navigate = useNavigate() const { currentToken } = useContainer(WalletContext) - const { value: nativeToken } = useNativeTokenDetailed() + const nativeToken = useNativeTokenDetailed() const { value: isActiveSocialNetwork } = useAsync(async () => { const urls = compact((await browser.tabs.query({ active: true })).map((tab) => tab.url)) diff --git a/packages/mask/src/extension/popups/pages/Wallet/Transfer/Transfer1559.tsx b/packages/mask/src/extension/popups/pages/Wallet/Transfer/Transfer1559.tsx index 74a1e8e69671..41c2e988fe76 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/Transfer/Transfer1559.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/Transfer/Transfer1559.tsx @@ -189,7 +189,7 @@ export const Transfer1559 = memo(({ selectedAsset, openAssetM const [minGasLimitContext, setMinGasLimitContext] = useState(0) const [addressTip, setAddressTip] = useState<{ type: TransferAddressError; message: string } | null>() - const { value: nativeToken } = useNativeTokenDetailed() + const nativeToken = useNativeTokenDetailed() const etherPrice = useNativeTokenPrice(nativeToken?.chainId) diff --git a/packages/mask/src/plugins/NextID/contexts/TipContext.tsx b/packages/mask/src/plugins/NextID/contexts/TipContext.tsx index 580d300c3e3a..ecfe34d3db75 100644 --- a/packages/mask/src/plugins/NextID/contexts/TipContext.tsx +++ b/packages/mask/src/plugins/NextID/contexts/TipContext.tsx @@ -67,7 +67,7 @@ export const TipTaskProvider: FC = ({ children, task }) => { const [tipType, setTipType] = useState(TipType.Token) const [amount, setAmount] = useState('0') const [erc721Contract, setErc721Contract] = useState(null) - const { value: nativeTokenDetailed = null } = useNativeTokenDetailed() + const nativeTokenDetailed = useNativeTokenDetailed() const [token, setToken] = useState(nativeTokenDetailed) const [erc721TokenId, setErc721TokenId] = useState(null) diff --git a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketERC20Form.tsx b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketERC20Form.tsx index 3e2d45bbf009..d599483a9d01 100644 --- a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketERC20Form.tsx +++ b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketERC20Form.tsx @@ -94,7 +94,7 @@ export function RedPacketERC20Form(props: RedPacketFormProps) { const { HAPPY_RED_PACKET_ADDRESS_V4 } = useRedPacketConstants() // #region select token - const { value: nativeTokenDetailed } = useNativeTokenDetailed() + const nativeTokenDetailed = useNativeTokenDetailed() const [token = nativeTokenDetailed, setToken] = useState(origin?.token) const [id] = useState(uuid) const { setDialog: setSelectTokenDialog } = useRemoteControlledDialog( diff --git a/packages/mask/src/plugins/Savings/SNSAdaptor/SavingsForm.tsx b/packages/mask/src/plugins/Savings/SNSAdaptor/SavingsForm.tsx index 27e8febf9945..b361771d72e2 100644 --- a/packages/mask/src/plugins/Savings/SNSAdaptor/SavingsForm.tsx +++ b/packages/mask/src/plugins/Savings/SNSAdaptor/SavingsForm.tsx @@ -39,7 +39,7 @@ export function SavingsForm({ chainId, selectedProtocol, tab, onClose }: Savings const protocol = SavingsProtocols[selectedProtocol] const targetChainId = chainId - const { value: nativeTokenDetailed } = useNativeTokenDetailed() + const nativeTokenDetailed = useNativeTokenDetailed() const web3 = useWeb3({ chainId }) const account = useAccount() diff --git a/packages/mask/src/plugins/Trader/SNSAdaptor/trader/GasPrior1559Settings.tsx b/packages/mask/src/plugins/Trader/SNSAdaptor/trader/GasPrior1559Settings.tsx index d7cf98a8ac0f..a8a1b50cae62 100644 --- a/packages/mask/src/plugins/Trader/SNSAdaptor/trader/GasPrior1559Settings.tsx +++ b/packages/mask/src/plugins/Trader/SNSAdaptor/trader/GasPrior1559Settings.tsx @@ -156,7 +156,7 @@ export const GasPrior1559Settings = memo( [gasOptions, customGasPrice], ) - const { value: nativeToken } = useNativeTokenDetailed() + const nativeToken = useNativeTokenDetailed() const nativeTokenPrice = useNativeTokenPrice(nativeToken?.chainId) // #region Confirm function diff --git a/packages/mask/src/plugins/Trader/SNSAdaptor/trader/hooks/useSortedTrades.ts b/packages/mask/src/plugins/Trader/SNSAdaptor/trader/hooks/useSortedTrades.ts index 7c9de8b7597e..a9930c24f072 100644 --- a/packages/mask/src/plugins/Trader/SNSAdaptor/trader/hooks/useSortedTrades.ts +++ b/packages/mask/src/plugins/Trader/SNSAdaptor/trader/hooks/useSortedTrades.ts @@ -8,7 +8,7 @@ import { ChainId, EthereumTokenType, formatBalance, useNativeTokenDetailed } fro import { AllProviderTradeContext } from '../../../trader/useAllProviderTradeContext' export function useSortedTrades(traders: TradeInfo[], chainId: ChainId, gasPrice?: string) { - const { value: nativeToken } = useNativeTokenDetailed(chainId) + const nativeToken = useNativeTokenDetailed(chainId) const nativeTokenPrice = useNativeTokenPrice(chainId) const { diff --git a/packages/mask/src/plugins/Wallet/SNSAdaptor/GasSettingDialog/GasSetting1559.tsx b/packages/mask/src/plugins/Wallet/SNSAdaptor/GasSettingDialog/GasSetting1559.tsx index 460fa722c2c8..f44c52223e64 100644 --- a/packages/mask/src/plugins/Wallet/SNSAdaptor/GasSettingDialog/GasSetting1559.tsx +++ b/packages/mask/src/plugins/Wallet/SNSAdaptor/GasSettingDialog/GasSetting1559.tsx @@ -38,7 +38,7 @@ export const GasSetting1559: FC = memo( const { t } = useI18N() const chainId = useChainId() const [selectedGasOption, setGasOption] = useState(gasOption) - const { value: nativeToken } = useNativeTokenDetailed() + const nativeToken = useNativeTokenDetailed() const nativeTokenPrice = useNativeTokenPrice(nativeToken?.chainId) // #region Get suggest gas options data from meta swap api diff --git a/packages/mask/src/plugins/Wallet/SNSAdaptor/GasSettingDialog/GasSettingBar.tsx b/packages/mask/src/plugins/Wallet/SNSAdaptor/GasSettingDialog/GasSettingBar.tsx index 76b3ab4c6fb5..bcb68395ea22 100644 --- a/packages/mask/src/plugins/Wallet/SNSAdaptor/GasSettingDialog/GasSettingBar.tsx +++ b/packages/mask/src/plugins/Wallet/SNSAdaptor/GasSettingDialog/GasSettingBar.tsx @@ -28,7 +28,7 @@ export function GasSettingBar(props: GasSettingBarProps) { const { gasLimit, gasPrice, maxFee, priorityFee, onChange } = props const chainId = useChainId() - const { value: nativeTokenDetailed } = useNativeTokenDetailed() + const nativeTokenDetailed = useNativeTokenDetailed() const { value: gasPriceDefault = '0' } = useGasPrice() const [gasOption, setGasOption] = useState(GasOption.Medium) diff --git a/packages/mask/src/plugins/Wallet/SNSAdaptor/GasSettingDialog/Prior1559GasSetting.tsx b/packages/mask/src/plugins/Wallet/SNSAdaptor/GasSettingDialog/Prior1559GasSetting.tsx index 112764214583..5d88d3748fbb 100644 --- a/packages/mask/src/plugins/Wallet/SNSAdaptor/GasSettingDialog/Prior1559GasSetting.tsx +++ b/packages/mask/src/plugins/Wallet/SNSAdaptor/GasSettingDialog/Prior1559GasSetting.tsx @@ -28,9 +28,9 @@ export const Prior1559GasSetting: FC = memo( const { t } = useI18N() const chainId = useChainId() const [selectedGasOption, setGasOption] = useState(gasOption) - const { value: nativeToken } = useNativeTokenDetailed() + const nativeToken = useNativeTokenDetailed() - const nativeTokenPrice = useNativeTokenPrice(nativeToken?.chainId) + const nativeTokenPrice = useNativeTokenPrice(nativeToken.chainId) // #region Get gas options from debank const { value: gasOptions, loading: getGasOptionsLoading } = useAsync(async () => { diff --git a/packages/mask/src/plugins/Wallet/SNSAdaptor/WalletStatusDialog/TransactionDescription.tsx b/packages/mask/src/plugins/Wallet/SNSAdaptor/WalletStatusDialog/TransactionDescription.tsx index a1047d645e3d..257cf61ab527 100644 --- a/packages/mask/src/plugins/Wallet/SNSAdaptor/WalletStatusDialog/TransactionDescription.tsx +++ b/packages/mask/src/plugins/Wallet/SNSAdaptor/WalletStatusDialog/TransactionDescription.tsx @@ -119,7 +119,7 @@ export interface RecentTransactionDescriptionProps { export function RecentTransactionDescription(props: RecentTransactionDescriptionProps) { const chainId = useChainId() const { hash, computedPayload } = props - const { loading: getNativeTokenLoading, value: nativeTokenDetailed } = useNativeTokenDetailed() + const nativeTokenDetailed = useNativeTokenDetailed() let inputTokenAddress: string | undefined = '' let tokenAddress: string | undefined = '' @@ -152,7 +152,7 @@ export function RecentTransactionDescription(props: RecentTransactionDescription const { loading: getERC20TokenLoading, value: tokenDetailed } = useERC20TokenDetailed(tokenAddress) - return !getNativeTokenLoading && !getERC20TokenLoading && !getInputERC20TokenLoading ? ( + return !getERC20TokenLoading && !getInputERC20TokenLoading ? ( {getTransactionDescription( chainId, diff --git a/packages/mask/src/plugins/Wallet/SNSAdaptor/WalletStatusDialog/contractMethodDescription/getRedpacketDescription.tsx b/packages/mask/src/plugins/Wallet/SNSAdaptor/WalletStatusDialog/contractMethodDescription/getRedpacketDescription.tsx index 205141462a99..d446258a424a 100644 --- a/packages/mask/src/plugins/Wallet/SNSAdaptor/WalletStatusDialog/contractMethodDescription/getRedpacketDescription.tsx +++ b/packages/mask/src/plugins/Wallet/SNSAdaptor/WalletStatusDialog/contractMethodDescription/getRedpacketDescription.tsx @@ -39,7 +39,7 @@ export function CreateRedpacketDescription(props: CreateRedpacketDescriptionProp const { tokenAddress, tokenAmount } = props const { t } = useI18N() - const { value: nativeToken } = useNativeTokenDetailed() + const nativeToken = useNativeTokenDetailed() const { value: tokenDetailed } = useERC20TokenDetailed(tokenAddress) const token = isNativeTokenAddress(tokenAddress) ? nativeToken : tokenDetailed diff --git a/packages/shared/src/UI/components/ERC20TokenList/index.tsx b/packages/shared/src/UI/components/ERC20TokenList/index.tsx index b02a1ebe0565..a5ff53e2188e 100644 --- a/packages/shared/src/UI/components/ERC20TokenList/index.tsx +++ b/packages/shared/src/UI/components/ERC20TokenList/index.tsx @@ -51,7 +51,7 @@ export const ERC20TokenList = memo((props) => { const currentChainId = useChainId() const chainId = props.targetChainId ?? currentChainId const trustedERC20Tokens = useTrustedERC20Tokens() - const { value: nativeToken } = useNativeTokenDetailed(chainId) + const nativeToken = useNativeTokenDetailed(chainId) const [keyword, setKeyword] = useState('') const { diff --git a/packages/web3-shared/evm/hooks/useAssets.ts b/packages/web3-shared/evm/hooks/useAssets.ts index 9ca15511ba4b..c1a645dfe984 100644 --- a/packages/web3-shared/evm/hooks/useAssets.ts +++ b/packages/web3-shared/evm/hooks/useAssets.ts @@ -9,12 +9,7 @@ import { formatEthereumAddress, EMPTY_LIST } from '../utils' export function useAssets(tokens: FungibleTokenDetailed[], chainId?: ChainId | 'all') { const wallet = useWallet() - const { - value: nativeTokenDetailed, - loading: nativeTokenDetailedLoading, - error: nativeTokenDetailedError, - retry: retryNativeTokenDetailed, - } = useNativeTokenDetailed(chainId === 'all' ? undefined : chainId) + const nativeTokenDetailed = useNativeTokenDetailed(chainId === 'all' ? undefined : chainId) const { value: assetsFromChain = EMPTY_LIST, @@ -31,10 +26,9 @@ export function useAssets(tokens: FungibleTokenDetailed[], chainId?: ChainId | ' } = useAssetsFromProvider(chainId) const detailedTokensRetry = useCallback(() => { - retryNativeTokenDetailed() retryAssetsDetailedChain() retryAssetsDetailedDebank() - }, [retryNativeTokenDetailed, retryAssetsDetailedChain, retryAssetsDetailedDebank]) + }, [retryAssetsDetailedChain, retryAssetsDetailedDebank]) const matchedAssetsFromChain = useMemo( () => assetsFromChain.filter((x) => !chainId || chainId === 'all' || x.token.chainId === chainId), @@ -49,8 +43,8 @@ export function useAssets(tokens: FungibleTokenDetailed[], chainId?: ChainId | ' return { value: assets, - error: nativeTokenDetailedError || assetsDetailedChainError || assetsDetailedProviderError, - loading: nativeTokenDetailedLoading || assetsDetailedChainLoading || assetsDetailedProviderLoading, + error: assetsDetailedChainError || assetsDetailedProviderError, + loading: assetsDetailedChainLoading || assetsDetailedProviderLoading, retry: detailedTokensRetry, } } diff --git a/packages/web3-shared/evm/hooks/useFungibleTokenDetailed.ts b/packages/web3-shared/evm/hooks/useFungibleTokenDetailed.ts index 005f17304a3d..f6409564a70e 100644 --- a/packages/web3-shared/evm/hooks/useFungibleTokenDetailed.ts +++ b/packages/web3-shared/evm/hooks/useFungibleTokenDetailed.ts @@ -3,6 +3,7 @@ import { unreachable } from '@dimensiondev/kit' import { ERC20TokenDetailed, EthereumTokenDetailedType, EthereumTokenType } from '../types' import { useERC20TokenDetailed } from './useERC20TokenDetailed' import { useNativeTokenDetailed } from './useNativeTokenDetailed' +import { useAsyncRetry } from 'react-use' export function useFungibleTokenDetailed< P extends EthereumTokenDetailedType, @@ -11,7 +12,8 @@ export function useFungibleTokenDetailed< address: string, token?: Partial

, ): AsyncStateRetry

{ - const r1 = useNativeTokenDetailed() + const _r1 = useNativeTokenDetailed() + const r1 = useAsyncRetry(async () => _r1, [address, type, token]) const r2 = useERC20TokenDetailed( type === EthereumTokenType.ERC20 ? address : '', token as unknown as ERC20TokenDetailed, diff --git a/packages/web3-shared/evm/hooks/useFungibleTokenWatched.tsx b/packages/web3-shared/evm/hooks/useFungibleTokenWatched.tsx index b81e12a41788..7929c4ae1cdc 100644 --- a/packages/web3-shared/evm/hooks/useFungibleTokenWatched.tsx +++ b/packages/web3-shared/evm/hooks/useFungibleTokenWatched.tsx @@ -9,7 +9,7 @@ export function useFungibleTokenWatched(initialToken?: { address: string }) { const nativeToken = useNativeTokenDetailed() - const [token = nativeToken.value, setToken] = useState(initialToken) + const [token = nativeToken, setToken] = useState(initialToken) const [amount, setAmount] = useState('') const balance = useFungibleTokenBalance(token?.type ?? EthereumTokenType.Native, token?.address ?? '') diff --git a/packages/web3-shared/evm/hooks/useNativeTokenDetailed.ts b/packages/web3-shared/evm/hooks/useNativeTokenDetailed.ts index 5dfa38d313da..81e7285e5083 100644 --- a/packages/web3-shared/evm/hooks/useNativeTokenDetailed.ts +++ b/packages/web3-shared/evm/hooks/useNativeTokenDetailed.ts @@ -1,9 +1,9 @@ -import { useAsyncRetry } from 'react-use' +import { useMemo } from 'react' import { createNativeToken } from '../utils' import { useChainId } from './useChainId' import type { ChainId } from '../types' export function useNativeTokenDetailed(chainId?: ChainId) { const currentChainId = useChainId() - return useAsyncRetry(async () => createNativeToken(chainId ?? currentChainId), [currentChainId, chainId]) + return useMemo(() => createNativeToken(chainId ?? currentChainId), [currentChainId, chainId]) } From 4bd6c8e75225250a2aed498217b83b2caae3d48c Mon Sep 17 00:00:00 2001 From: zhouhanseng Date: Mon, 14 Mar 2022 12:44:11 +0800 Subject: [PATCH 2/4] refactor: use native token hook --- .../src/pages/Wallets/components/Transfer/TransferERC721.tsx | 2 +- packages/mask/src/plugins/Gitcoin/SNSAdaptor/DonateDialog.tsx | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC721.tsx b/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC721.tsx index 44c193e60884..b4660540ba23 100644 --- a/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC721.tsx +++ b/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC721.tsx @@ -405,7 +405,7 @@ export const TransferERC721 = memo(() => { {t.transfer_cost({ gasFee: formatWeiToEther(gasFee).toFixed(6), - symbol: nativeToken.value?.symbol ?? '', + symbol: nativeToken.symbol ?? '', usd: gasFeeInUsd.toFixed(2), })} diff --git a/packages/mask/src/plugins/Gitcoin/SNSAdaptor/DonateDialog.tsx b/packages/mask/src/plugins/Gitcoin/SNSAdaptor/DonateDialog.tsx index 9a17ec04a39b..6bf57a94567d 100644 --- a/packages/mask/src/plugins/Gitcoin/SNSAdaptor/DonateDialog.tsx +++ b/packages/mask/src/plugins/Gitcoin/SNSAdaptor/DonateDialog.tsx @@ -80,9 +80,7 @@ export function DonateDialog(props: DonateDialogProps) { // #endregion // #region the selected token - const [token = nativeTokenDetailed.value, setToken] = useState( - nativeTokenDetailed.value, - ) + const [token = nativeTokenDetailed, setToken] = useState(nativeTokenDetailed) const tokenBalance = useFungibleTokenBalance(token?.type ?? EthereumTokenType.Native, token?.address ?? '') // #endregion From af7409dccd556d4a9360cdd9649352c44985c152 Mon Sep 17 00:00:00 2001 From: zhouhanseng Date: Mon, 14 Mar 2022 14:14:34 +0800 Subject: [PATCH 3/4] chore: reply code review --- packages/web3-shared/evm/hooks/useFungibleTokenDetailed.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web3-shared/evm/hooks/useFungibleTokenDetailed.ts b/packages/web3-shared/evm/hooks/useFungibleTokenDetailed.ts index f6409564a70e..095fbc681e57 100644 --- a/packages/web3-shared/evm/hooks/useFungibleTokenDetailed.ts +++ b/packages/web3-shared/evm/hooks/useFungibleTokenDetailed.ts @@ -13,7 +13,7 @@ export function useFungibleTokenDetailed< token?: Partial

, ): AsyncStateRetry

{ const _r1 = useNativeTokenDetailed() - const r1 = useAsyncRetry(async () => _r1, [address, type, token]) + const r1 = useAsyncRetry(async () => _r1, []) const r2 = useERC20TokenDetailed( type === EthereumTokenType.ERC20 ? address : '', token as unknown as ERC20TokenDetailed, From ea8817d3068b86e5671362aabbc5a6cc6fbae31a Mon Sep 17 00:00:00 2001 From: zhouhanseng Date: Wed, 30 Mar 2022 18:31:52 +0800 Subject: [PATCH 4/4] chore: solve conflict --- .../mask/src/plugins/NextID/contexts/Tip/TipTaskProvider.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mask/src/plugins/NextID/contexts/Tip/TipTaskProvider.tsx b/packages/mask/src/plugins/NextID/contexts/Tip/TipTaskProvider.tsx index de39fd31f565..d8135c1ee163 100644 --- a/packages/mask/src/plugins/NextID/contexts/Tip/TipTaskProvider.tsx +++ b/packages/mask/src/plugins/NextID/contexts/Tip/TipTaskProvider.tsx @@ -16,7 +16,7 @@ export const TipTaskProvider: FC = ({ children, task }) => { const [amount, setAmount] = useState('') const { targetChainId } = TargetChainIdContext.useContainer() const [erc721Contract, setErc721Contract] = useState(null) - const { value: nativeTokenDetailed = null } = useNativeTokenDetailed(targetChainId) + const nativeTokenDetailed = useNativeTokenDetailed(targetChainId) const [token, setToken] = useState(nativeTokenDetailed) const [erc721TokenId, setErc721TokenId] = useState(null)