Ensure all of a token is swapped when clicking max in swaps (#9507)

feature/default_network_editable
Dan J Miller 4 years ago committed by GitHub
parent cdfa2e66fd
commit a939853989
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      ui/app/pages/swaps/build-quote/build-quote.js

@ -95,9 +95,12 @@ export default function BuildQuote ({
symbol: fromTokenSymbol, symbol: fromTokenSymbol,
string: fromTokenString, string: fromTokenString,
decimals: fromTokenDecimals, decimals: fromTokenDecimals,
balance: rawFromTokenBalance,
} = selectedFromToken || {} } = selectedFromToken || {}
const prevFromTokenString = usePrevious(fromTokenString) const fromTokenBalance = rawFromTokenBalance && calcTokenAmount(rawFromTokenBalance, fromTokenDecimals).toString(10)
const prevFromTokenBalance = usePrevious(fromTokenBalance)
const swapFromTokenFiatValue = useTokenFiatAmount( const swapFromTokenFiatValue = useTokenFiatAmount(
fromTokenAddress, fromTokenAddress,
@ -158,10 +161,10 @@ export default function BuildQuote ({
}, [dispatch, fromToken, ethBalance]) }, [dispatch, fromToken, ethBalance])
useEffect(() => { useEffect(() => {
if (prevFromTokenString !== fromTokenString) { if (prevFromTokenBalance !== fromTokenBalance) {
onInputChange(inputValue, fromTokenString) onInputChange(inputValue, fromTokenBalance)
} }
}, [onInputChange, prevFromTokenString, inputValue, fromTokenString]) }, [onInputChange, prevFromTokenBalance, inputValue, fromTokenBalance])
useEffect(() => { useEffect(() => {
dispatch(resetSwapsPostFetchState()) dispatch(resetSwapsPostFetchState())
@ -176,7 +179,7 @@ export default function BuildQuote ({
className="build-quote__max-button" className="build-quote__max-button"
onClick={() => { onClick={() => {
dispatch(setMaxMode(true)) dispatch(setMaxMode(true))
onInputChange(fromTokenString || '0', fromTokenString) onInputChange(fromTokenBalance || '0', fromTokenBalance)
}} }}
>{t('max')} >{t('max')}
</div> </div>
@ -186,7 +189,7 @@ export default function BuildQuote ({
itemsToSearch={tokensToSearch} itemsToSearch={tokensToSearch}
onInputChange={(value) => { onInputChange={(value) => {
dispatch(setMaxMode(false)) dispatch(setMaxMode(false))
onInputChange(value, fromTokenString, fromTokenDecimals) onInputChange(value, fromTokenBalance)
}} }}
inputValue={inputValue} inputValue={inputValue}
leftValue={inputValue && swapFromFiatValue} leftValue={inputValue && swapFromFiatValue}

Loading…
Cancel
Save