From c420249fb9115f7dc871acfd8c5cf832ebf5e890 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 30 Oct 2017 15:37:30 -0230 Subject: [PATCH] Adds max amount feature for send token --- ui/app/send-v2.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/ui/app/send-v2.js b/ui/app/send-v2.js index 412aa417c..6f3b48be6 100644 --- a/ui/app/send-v2.js +++ b/ui/app/send-v2.js @@ -321,18 +321,25 @@ SendTransactionScreen.prototype.setAmountToMax = function () { updateGasPrice, updateGasLimit, updateGasTotal, + tokenBalance, + selectedToken, } = this.props + const { decimals } = selectedToken || {} + const multiplier = Math.pow(10, Number(decimals || 0)) - const maxAmount = subtractCurrencies( - ethUtil.addHexPrefix(balance), - ethUtil.addHexPrefix(MIN_GAS_TOTAL), - { toNumericBase: 'hex' } - ) + const maxAmount = selectedToken + ? multiplyCurrencies(tokenBalance, multiplier, {toNumericBase: 'hex'}) + : subtractCurrencies( + ethUtil.addHexPrefix(balance), + ethUtil.addHexPrefix(gasTotal), + { toNumericBase: 'hex' } + ) updateSendErrors({ amount: null }) updateGasPrice(MIN_GAS_PRICE_HEX) updateGasLimit(MIN_GAS_LIMIT_HEX) updateGasTotal(MIN_GAS_TOTAL) + updateSendAmount(maxAmount) }