From a939853989dbd42fb32a3be3500634ff56ea6d5d Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Wed, 7 Oct 2020 23:08:34 -0230 Subject: [PATCH] Ensure all of a token is swapped when clicking max in swaps (#9507) --- ui/app/pages/swaps/build-quote/build-quote.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/ui/app/pages/swaps/build-quote/build-quote.js b/ui/app/pages/swaps/build-quote/build-quote.js index daf7b4ec1..71520a88a 100644 --- a/ui/app/pages/swaps/build-quote/build-quote.js +++ b/ui/app/pages/swaps/build-quote/build-quote.js @@ -95,9 +95,12 @@ export default function BuildQuote ({ symbol: fromTokenSymbol, string: fromTokenString, decimals: fromTokenDecimals, + balance: rawFromTokenBalance, } = selectedFromToken || {} - const prevFromTokenString = usePrevious(fromTokenString) + const fromTokenBalance = rawFromTokenBalance && calcTokenAmount(rawFromTokenBalance, fromTokenDecimals).toString(10) + + const prevFromTokenBalance = usePrevious(fromTokenBalance) const swapFromTokenFiatValue = useTokenFiatAmount( fromTokenAddress, @@ -158,10 +161,10 @@ export default function BuildQuote ({ }, [dispatch, fromToken, ethBalance]) useEffect(() => { - if (prevFromTokenString !== fromTokenString) { - onInputChange(inputValue, fromTokenString) + if (prevFromTokenBalance !== fromTokenBalance) { + onInputChange(inputValue, fromTokenBalance) } - }, [onInputChange, prevFromTokenString, inputValue, fromTokenString]) + }, [onInputChange, prevFromTokenBalance, inputValue, fromTokenBalance]) useEffect(() => { dispatch(resetSwapsPostFetchState()) @@ -176,7 +179,7 @@ export default function BuildQuote ({ className="build-quote__max-button" onClick={() => { dispatch(setMaxMode(true)) - onInputChange(fromTokenString || '0', fromTokenString) + onInputChange(fromTokenBalance || '0', fromTokenBalance) }} >{t('max')} @@ -186,7 +189,7 @@ export default function BuildQuote ({ itemsToSearch={tokensToSearch} onInputChange={(value) => { dispatch(setMaxMode(false)) - onInputChange(value, fromTokenString, fromTokenDecimals) + onInputChange(value, fromTokenBalance) }} inputValue={inputValue} leftValue={inputValue && swapFromFiatValue}