Skip to content

Commit

Permalink
update usdc balances hook
Browse files Browse the repository at this point in the history
  • Loading branch information
brtkx committed Jun 11, 2024
1 parent 2b736ff commit 8f6862d
Showing 1 changed file with 5 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -27,6 +27,8 @@ export function useUpdateUSDCBalances({
walletAddress
})

const tokensFromLists = useTokensFromLists()

const updateUSDCBalances = useCallback(async () => {
const { isEthereumMainnet, isSepolia, isArbitrumOne, isArbitrumSepolia } =
isNetwork(parentChain.id)
Expand Down Expand Up @@ -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
])
Expand Down

0 comments on commit 8f6862d

Please sign in to comment.