From 636abe3b7b2d04c7f6e9ef5fbf88dd7c213c9bf2 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 10 Feb 2022 19:35:34 -0800 Subject: [PATCH] fix: respond to updated amounts immediately (#3289) --- src/lib/components/Swap/Toolbar/index.tsx | 7 +++---- src/lib/hooks/swap/useSwapInfo.tsx | 8 +++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/lib/components/Swap/Toolbar/index.tsx b/src/lib/components/Swap/Toolbar/index.tsx index 76f8b3c8cd..1774d32724 100644 --- a/src/lib/components/Swap/Toolbar/index.tsx +++ b/src/lib/components/Swap/Toolbar/index.tsx @@ -40,10 +40,6 @@ export default function Toolbar({ disabled }: { disabled?: boolean }) { return } - if (balance && trade?.inputAmount.greaterThan(balance)) { - return - } - if (inputCurrency && outputCurrency && isAmountPopulated) { if (!trade || routeIsLoading) { return @@ -51,6 +47,9 @@ export default function Toolbar({ disabled }: { disabled?: boolean }) { if (!routeFound) { return } + if (balance && trade?.inputAmount.greaterThan(balance)) { + return + } if (trade.inputAmount && trade.outputAmount) { return } diff --git a/src/lib/hooks/swap/useSwapInfo.tsx b/src/lib/hooks/swap/useSwapInfo.tsx index 6ae4e9f544..ec8e35da2c 100644 --- a/src/lib/hooks/swap/useSwapInfo.tsx +++ b/src/lib/hooks/swap/useSwapInfo.tsx @@ -57,6 +57,8 @@ function useComputeSwapInfo(): SwapInfo { () => tryParseCurrencyAmount(amount, (isExactIn ? inputCurrency : outputCurrency) ?? undefined), [inputCurrency, isExactIn, outputCurrency, amount] ) + const parsedAmountIn = isExactIn ? parsedAmount : undefined + const parsedAmountOut = isExactIn ? undefined : parsedAmount //@TODO(ianlapham): this would eventually be replaced with routing api logic. const trade = useBestTrade( @@ -83,10 +85,10 @@ function useComputeSwapInfo(): SwapInfo { const currencyAmounts = useMemo( () => ({ - [Field.INPUT]: trade.trade?.inputAmount, - [Field.OUTPUT]: trade.trade?.outputAmount, + [Field.INPUT]: parsedAmountIn || trade.trade?.inputAmount, + [Field.OUTPUT]: parsedAmountOut || trade.trade?.outputAmount, }), - [trade.trade?.inputAmount, trade.trade?.outputAmount] + [parsedAmountIn, parsedAmountOut, trade.trade?.inputAmount, trade.trade?.outputAmount] ) const allowedSlippage = useAllowedSlippage(trade.trade)