-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into union-getTransferMode
- Loading branch information
Showing
9 changed files
with
230 additions
and
103 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...ges/arb-token-bridge-ui/src/components/TransactionHistory/TransactionHistorySearchBar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ages/arb-token-bridge-ui/src/components/TransferPanel/hooks/useDestinationAddressError.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/arb-token-bridge-ui/src/components/common/AddCustomChain.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 0 additions & 88 deletions
88
packages/arb-token-bridge-ui/src/hooks/CCTP/useUpdateUSDCBalances.ts
This file was deleted.
Oops, something went wrong.
127 changes: 127 additions & 0 deletions
127
packages/arb-token-bridge-ui/src/hooks/CCTP/useUpdateUsdcBalances.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
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 | ||
} | ||
} |
Oops, something went wrong.