From ff33ccdf328e4deb0ce85de69d5d9022bb37757f Mon Sep 17 00:00:00 2001 From: Bartek Date: Tue, 21 Jan 2025 17:29:05 +0100 Subject: [PATCH] merge --- .../src/hooks/CCTP/useUpdateUsdcBalances.ts | 127 ------------------ 1 file changed, 127 deletions(-) delete mode 100644 packages/arb-token-bridge-ui/src/hooks/CCTP/useUpdateUsdcBalances.ts diff --git a/packages/arb-token-bridge-ui/src/hooks/CCTP/useUpdateUsdcBalances.ts b/packages/arb-token-bridge-ui/src/hooks/CCTP/useUpdateUsdcBalances.ts deleted file mode 100644 index dde96b1a69..0000000000 --- a/packages/arb-token-bridge-ui/src/hooks/CCTP/useUpdateUsdcBalances.ts +++ /dev/null @@ -1,127 +0,0 @@ -import { useCallback } from 'react' -import { Address } from 'wagmi' -import useSWRImmutable from 'swr/immutable' - -import { CommonAddress } from '../../util/CommonAddressUtils' -import { getL2ERC20Address } from '../../util/TokenUtils' -import { useNetworks } from '../useNetworks' -import { useNetworksRelationship } from '../useNetworksRelationship' -import { isNetwork } from '../../util/networks' -import { useBalances } from '../useBalances' -import { getProviderForChainId } from '@/token-bridge-sdk/utils' - -export async function getChildUsdcAddress({ - parentChainId, - childChainId -}: { - parentChainId: number - childChainId: number -}) { - const { - isEthereumMainnet: isParentEthereumMainnet, - isSepolia: isParentSepolia - } = isNetwork(parentChainId) - - if (isParentEthereumMainnet) { - return CommonAddress.ArbitrumOne.USDC - } - - if (isParentSepolia) { - return CommonAddress.ArbitrumSepolia.USDC - } - - const parentUsdcAddress = getParentUsdcAddress(parentChainId) - const parentProvider = getProviderForChainId(parentChainId) - const childProvider = getProviderForChainId(childChainId) - - if (!parentUsdcAddress) { - return - } - - return getL2ERC20Address({ - erc20L1Address: parentUsdcAddress, - l1Provider: parentProvider, - l2Provider: childProvider - }) -} - -export function getParentUsdcAddress(parentChainId: number) { - const { - isEthereumMainnet: isParentEthereumMainnet, - isSepolia: isParentSepolia, - isArbitrumOne: isParentArbitrumOne, - isArbitrumSepolia: isParentArbitrumSepolia - } = isNetwork(parentChainId) - - if (isParentEthereumMainnet) { - return CommonAddress.Ethereum.USDC - } - - if (isParentSepolia) { - return CommonAddress.Sepolia.USDC - } - - if (isParentArbitrumOne) { - return CommonAddress.ArbitrumOne.USDC - } - - if (isParentArbitrumSepolia) { - return CommonAddress.ArbitrumSepolia.USDC - } -} - -export function useUpdateUsdcBalances({ - walletAddress -}: { - walletAddress: Address | undefined -}) { - const [networks] = useNetworks() - const { parentChain, childChain } = useNetworksRelationship(networks) - - const { - updateErc20ParentBalances: updateErc20ParentBalance, - updateErc20ChildBalances: updateErc20ChildBalance - } = useBalances({ - parentWalletAddress: walletAddress, - childWalletAddress: walletAddress - }) - - // we don't have native USDC addresses for Orbit chains, we need to fetch it - const { data: childUsdcAddress, isLoading } = useSWRImmutable( - [parentChain.id, childChain.id, 'getChildUsdcAddress'], - ([parentChainId, childChainId]) => - getChildUsdcAddress({ - parentChainId, - childChainId - }) - ) - - const updateUsdcBalances = useCallback(() => { - const parentUsdcAddress = getParentUsdcAddress(parentChain.id) - - // USDC is not native for the selected networks, do nothing - if (!parentUsdcAddress) { - return - } - - if (isLoading) { - return - } - - updateErc20ParentBalance([parentUsdcAddress.toLowerCase()]) - - if (childUsdcAddress) { - updateErc20ChildBalance([childUsdcAddress.toLowerCase()]) - } - }, [ - isLoading, - childUsdcAddress, - parentChain.id, - updateErc20ChildBalance, - updateErc20ParentBalance - ]) - - return { - updateUsdcBalances - } -}