diff --git a/libs/oeth/swap/src/views/SwapView.tsx b/libs/oeth/swap/src/views/SwapView.tsx index e9d9d54f4..5bdab87f2 100644 --- a/libs/oeth/swap/src/views/SwapView.tsx +++ b/libs/oeth/swap/src/views/SwapView.tsx @@ -22,7 +22,7 @@ import { } from '@origin/shared/providers'; import { composeContexts, isNilOrEmpty } from '@origin/shared/utils'; import { useIntl } from 'react-intl'; -import { useAccount, useBalance } from 'wagmi'; +import { mainnet, useAccount, useBalance, useNetwork } from 'wagmi'; import { ApyHeader } from '../components/ApyHeader'; import { SwapRoute } from '../components/SwapRoute'; @@ -74,6 +74,7 @@ function SwapViewWrapped() { const intl = useIntl(); const { value: slippage, set: setSlippage } = useSlippage(); const { address, isConnected } = useAccount(); + const { chain } = useNetwork(); const [tokenSource, setTokenSource] = useState(null); const [ { @@ -194,6 +195,10 @@ function SwapViewWrapped() { onTokenClick={() => { setTokenSource('tokenIn'); }} + isNativeCurrency={ + tokenIn.symbol === + (chain?.nativeCurrency.symbol ?? mainnet.nativeCurrency.symbol) + } tokenPriceUsd={prices?.[tokenIn.symbol]} isPriceLoading={isPriceLoading} isConnected={isConnected} @@ -239,6 +244,10 @@ function SwapViewWrapped() { onTokenClick={() => { setTokenSource('tokenOut'); }} + isNativeCurrency={ + tokenOut.symbol === + (chain?.nativeCurrency.symbol ?? mainnet.nativeCurrency.symbol) + } tokenPriceUsd={prices?.[tokenOut.symbol]} isPriceLoading={isSwapRoutesLoading || isPriceLoading} isConnected={isConnected} diff --git a/libs/shared/components/src/Inputs/TokenInput.tsx b/libs/shared/components/src/Inputs/TokenInput.tsx index f3ebe587a..efb9466b6 100644 --- a/libs/shared/components/src/Inputs/TokenInput.tsx +++ b/libs/shared/components/src/Inputs/TokenInput.tsx @@ -32,6 +32,7 @@ export type TokenInputProps = { disableMaxButton?: boolean; token: Token; onTokenClick?: () => void; + isNativeCurrency?: boolean; isTokenClickDisabled?: boolean; tokenPriceUsd?: number; isPriceLoading?: boolean; @@ -58,6 +59,7 @@ export const TokenInput = forwardRef( disableMaxButton, token, onTokenClick, + isNativeCurrency = false, isTokenClickDisabled, tokenPriceUsd = 0, isPriceLoading, @@ -70,17 +72,16 @@ export const TokenInput = forwardRef( const intl = useIntl(); const handleMaxClick = () => { - const max = - token.symbol === 'ETH' - ? balance - parseEther(MIN_ETH_FOR_GAS) - : balance; + const max = isNativeCurrency + ? balance - parseEther(MIN_ETH_FOR_GAS) + : balance; onAmountChange(max); }; const amountUsd = +formatUnits(amount, decimals) * tokenPriceUsd; const maxVisible = !hideMaxButton && - (token.symbol === 'ETH' ? balance > parseEther(MIN_ETH_FOR_GAS) : true); + (isNativeCurrency ? balance > parseEther(MIN_ETH_FOR_GAS) : true); const maxDisabled = disableMaxButton || !isConnected || isBalanceLoading; return (