From 8f6862d3095840132c5a624ddd5656f35023ecdf Mon Sep 17 00:00:00 2001 From: Bartek Date: Tue, 11 Jun 2024 12:14:08 +0200 Subject: [PATCH] update usdc balances hook --- .../src/hooks/CCTP/useUpdateUSDCBalances.ts | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/packages/arb-token-bridge-ui/src/hooks/CCTP/useUpdateUSDCBalances.ts b/packages/arb-token-bridge-ui/src/hooks/CCTP/useUpdateUSDCBalances.ts index c1b50f9cf1..2d0093aa3c 100644 --- a/packages/arb-token-bridge-ui/src/hooks/CCTP/useUpdateUSDCBalances.ts +++ b/packages/arb-token-bridge-ui/src/hooks/CCTP/useUpdateUSDCBalances.ts @@ -1,10 +1,10 @@ import { useCallback } from 'react' import { CommonAddress } from '../../util/CommonAddressUtils' -import { getL2ERC20Address } from '../../util/TokenUtils' import { useBalance } from '../useBalance' import { useNetworks } from '../useNetworks' import { useNetworksRelationship } from '../useNetworksRelationship' import { isNetwork } from '../../util/networks' +import { useTokensFromLists } from '../../components/TransferPanel/TokenSearchUtils' export function useUpdateUSDCBalances({ walletAddress @@ -27,6 +27,8 @@ export function useUpdateUSDCBalances({ walletAddress }) + const tokensFromLists = useTokensFromLists() + const updateUSDCBalances = useCallback(async () => { const { isEthereumMainnet, isSepolia, isArbitrumOne, isArbitrumSepolia } = isNetwork(parentChain.id) @@ -58,27 +60,15 @@ export function useUpdateUSDCBalances({ // we don't have native USDC addresses for Orbit chains, we need to fetch it if (!childChainUsdcAddress) { - try { - childChainUsdcAddress = ( - await getL2ERC20Address({ - erc20L1Address: parentChainUsdcAddress, - l1Provider: parentChainProvider, - l2Provider: childChainProvider - }) - ).toLowerCase() - } catch { - // could be never bridged before - return - } + childChainUsdcAddress = tokensFromLists[parentChainUsdcAddress]?.l2Address } if (childChainUsdcAddress) { updateErc20L2Balance([childChainUsdcAddress]) } }, [ - childChainProvider, parentChain.id, - parentChainProvider, + tokensFromLists, updateErc20L1Balance, updateErc20L2Balance ])