diff --git a/packages/arb-token-bridge-ui/src/components/TransferPanel/TokenButton.tsx b/packages/arb-token-bridge-ui/src/components/TransferPanel/TokenButton.tsx index c090e311a3..eaa43c8007 100644 --- a/packages/arb-token-bridge-ui/src/components/TransferPanel/TokenButton.tsx +++ b/packages/arb-token-bridge-ui/src/components/TransferPanel/TokenButton.tsx @@ -57,7 +57,7 @@ export function TokenButton({ {({ open }) => ( <> )} */} - - {tokenSymbol} - + {tokenSymbol} {!disabled && ( + + {/* In deposit mode, when user selected USDC on mainnet, + the UI shows the Arb One balance of both USDC.e and native USDC */} + {showUsdcSpecificInfo && isDepositMode && ( + + )} + + ) + } + + if (nativeCurrency.isCustom) { + return ( + + ) + } + + return ( + + ) +} + +export function DestinationNetworkBox({ + customFeeTokenBalances, + showUsdcSpecificInfo +}: { + customFeeTokenBalances: Balances + showUsdcSpecificInfo: boolean +}) { + const { address: walletAddress } = useAccount() + const [networks] = useNetworks() const { destinationAddress } = useDestinationAddressStore() const destinationAddressOrWalletAddress = destinationAddress || walletAddress const [ @@ -58,7 +136,6 @@ export function DestinationNetworkBox({ return ( <> @@ -70,87 +147,10 @@ export function DestinationNetworkBox({ {destinationAddressOrWalletAddress && utils.isAddress(destinationAddressOrWalletAddress) && ( - <> - - {/* In deposit mode, when user selected USDC on mainnet, - the UI shows the Arb One balance of both USDC.e and native USDC */} - {isDepositMode && showUsdcSpecificInfo && ( - - )} - {nativeCurrency.isCustom ? ( - <> - - {!isDepositMode && ( - - )} - - ) : ( - - )} - + )} diff --git a/packages/arb-token-bridge-ui/src/components/TransferPanel/TransferPanelMain/SourceNetworkBox.tsx b/packages/arb-token-bridge-ui/src/components/TransferPanel/TransferPanelMain/SourceNetworkBox.tsx index cf0ba5a22a..b41ba30d1c 100644 --- a/packages/arb-token-bridge-ui/src/components/TransferPanel/TransferPanelMain/SourceNetworkBox.tsx +++ b/packages/arb-token-bridge-ui/src/components/TransferPanel/TransferPanelMain/SourceNetworkBox.tsx @@ -1,27 +1,17 @@ import { ChangeEventHandler, useCallback, useEffect, useMemo } from 'react' +import { utils } from 'ethers' import { getNetworkName } from '../../../util/networks' import { NetworkButton, NetworkSelectionContainer } from '../../common/NetworkSelectionContainer' -import { - BalancesContainer, - ETHBalance, - NetworkContainer, - NetworkListboxPlusBalancesContainer -} from '../TransferPanelMain' -import { TokenBalance } from './TokenBalance' -import { NetworkType } from './utils' +import { NetworkContainer } from '../TransferPanelMain' import { useAppState } from '../../../state' import { useNetworks } from '../../../hooks/useNetworks' import { useNativeCurrency } from '../../../hooks/useNativeCurrency' import { useNetworksRelationship } from '../../../hooks/useNetworksRelationship' -import { - Balances, - useSelectedTokenBalances -} from '../../../hooks/TransferPanel/useSelectedTokenBalances' -import { useBalances } from '../../../hooks/useBalances' +import { Balances } from '../../../hooks/TransferPanel/useSelectedTokenBalances' import { ETH_BALANCE_ARTICLE_LINK, USDC_LEARN_MORE_LINK @@ -39,6 +29,7 @@ import { useDialog } from '../../common/Dialog' import { useTransferReadiness } from '../useTransferReadiness' import { useIsBatchTransferSupported } from '../../../hooks/TransferPanel/useIsBatchTransferSupported' import { useSelectedTokenDecimals } from '../../../hooks/TransferPanel/useSelectedTokenDecimals' +import { useBalanceOnSourceChain } from '../../../hooks/useBalanceOnSourceChain' export function SourceNetworkBox({ customFeeTokenBalances, @@ -53,8 +44,6 @@ export function SourceNetworkBox({ const { app: { selectedToken } } = useAppState() - const { ethParentBalance, ethChildBalance } = useBalances() - const selectedTokenBalances = useSelectedTokenBalances() const nativeCurrency = useNativeCurrency({ provider: childChainProvider }) const [{ amount, amount2 }] = useArbQueryParams() const { setAmount, setAmount2 } = useSetInputAmount() @@ -66,6 +55,7 @@ export function SourceNetworkBox({ const isBatchTransferSupported = useIsBatchTransferSupported() const decimals = useSelectedTokenDecimals() const { errorMessages } = useTransferReadiness() + const ethBalanceSourceChain = useBalanceOnSourceChain(null) const isMaxAmount = amount === AmountQueryParamEnum.MAX const isMaxAmount2 = amount2 === AmountQueryParamEnum.MAX @@ -109,69 +99,21 @@ export function SourceNetworkBox({ const tokenButtonOptionsAmount2 = useMemo( () => ({ symbol: nativeCurrency.symbol, - disabled: true + disabled: true, + balance: ethBalanceSourceChain + ? Number(utils.formatEther(ethBalanceSourceChain)) + : undefined }), - [nativeCurrency.symbol] + [ethBalanceSourceChain, nativeCurrency.symbol] ) return ( <> - - - - - {nativeCurrency.isCustom ? ( - <> - - {/* Only show ETH balance on parent chain */} - {isDepositMode && ( - - )} - - ) : ( - - )} - - +
{isBatchTransferSupported && ( @@ -190,10 +133,11 @@ export function SourceNetworkBox({ errorMessage={errorMessages?.inputAmount2} value={amount2} onChange={handleAmount2Change} - tokenButtonOptions={tokenButtonOptionsAmount2} + options={tokenButtonOptionsAmount2} maxAmount={maxAmount2} isMaxAmount={isMaxAmount2} decimals={nativeCurrency.decimals} + customFeeTokenBalances={customFeeTokenBalances} /> )} diff --git a/packages/arb-token-bridge-ui/src/components/TransferPanel/TransferPanelMainInput.tsx b/packages/arb-token-bridge-ui/src/components/TransferPanel/TransferPanelMainInput.tsx index ad3efc5e98..c10a404096 100644 --- a/packages/arb-token-bridge-ui/src/components/TransferPanel/TransferPanelMainInput.tsx +++ b/packages/arb-token-bridge-ui/src/components/TransferPanel/TransferPanelMainInput.tsx @@ -10,29 +10,44 @@ import { useMemo } from 'react' import { TokenButton, TokenButtonOptions } from './TokenButton' import { useNetworks } from '../../hooks/useNetworks' import { useNetworksRelationship } from '../../hooks/useNetworksRelationship' -import { useSelectedTokenBalances } from '../../hooks/TransferPanel/useSelectedTokenBalances' +import { + Balances, + useSelectedTokenBalances +} from '../../hooks/TransferPanel/useSelectedTokenBalances' import { useAppState } from '../../state' import { useBalances } from '../../hooks/useBalances' import { TransferReadinessRichErrorMessage } from './useTransferReadinessUtils' import { ExternalLink } from '../common/ExternalLink' import { useTransferDisabledDialogStore } from './TransferDisabledDialog' +import { formatAmount } from '../../util/NumberUtils' +import { useNativeCurrency } from '../../hooks/useNativeCurrency' +import { Loader } from '../common/atoms/Loader' import { sanitizeAmountQueryParam } from '../../hooks/useArbQueryParams' import { truncateExtraDecimals } from '../../util/NumberUtils' -function MaxButton(props: React.ButtonHTMLAttributes) { - const { className = '', ...rest } = props - +function MaxButton({ + customFeeTokenBalances, + className = '', + ...rest +}: React.ButtonHTMLAttributes & { + customFeeTokenBalances: Balances +}) { const { app: { selectedToken } } = useAppState() const [networks] = useNetworks() - const { isDepositMode } = useNetworksRelationship(networks) + const { isDepositMode, childChainProvider } = + useNetworksRelationship(networks) const { ethParentBalance, ethChildBalance } = useBalances() const selectedTokenBalances = useSelectedTokenBalances() + const nativeCurrency = useNativeCurrency({ provider: childChainProvider }) const maxButtonVisible = useMemo(() => { const ethBalance = isDepositMode ? ethParentBalance : ethChildBalance + const customFeeTokenBalance = isDepositMode + ? customFeeTokenBalances.parentBalance + : customFeeTokenBalances.childBalance const tokenBalance = isDepositMode ? selectedTokenBalances.parentBalance : selectedTokenBalances.childBalance @@ -45,17 +60,23 @@ function MaxButton(props: React.ButtonHTMLAttributes) { return !tokenBalance.isZero() } + if (nativeCurrency.isCustom) { + return customFeeTokenBalance && !customFeeTokenBalance.isZero() + } + if (!ethBalance) { return false } return !ethBalance.isZero() }, [ + isDepositMode, ethParentBalance, ethChildBalance, + customFeeTokenBalances, selectedTokenBalances, selectedToken, - isDepositMode + nativeCurrency.isCustom ]) if (!maxButtonVisible) { @@ -66,7 +87,7 @@ function MaxButton(props: React.ButtonHTMLAttributes) {