mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 18:00:18 +01:00
Ensure all of a token is swapped when clicking max in swaps (#9507)
This commit is contained in:
parent
cdfa2e66fd
commit
a939853989
@ -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')}
|
||||
</div>
|
||||
@ -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}
|
||||
|
Loading…
Reference in New Issue
Block a user