From c156c85eaa064b971ce0202df0bb1681eb0e22dd Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 7 Nov 2017 21:47:14 -0330 Subject: Fix amount max for sending token. --- ui/app/components/send/currency-display.js | 30 +++++++++++++++++++++++------- ui/app/send-v2.js | 8 +++++--- 2 files changed, 28 insertions(+), 10 deletions(-) (limited to 'ui') diff --git a/ui/app/components/send/currency-display.js b/ui/app/components/send/currency-display.js index 8b72b3e6d..49df5b0b7 100644 --- a/ui/app/components/send/currency-display.js +++ b/ui/app/components/send/currency-display.js @@ -36,6 +36,28 @@ CurrencyDisplay.prototype.getAmount = function (value) { : toHexWei(value) } +CurrencyDisplay.prototype.getValueToRender = function () { + const { selectedToken, conversionRate, value } = this.props + + const { decimals, symbol } = selectedToken || {} + const multiplier = Math.pow(10, Number(decimals || 0)) + + return selectedToken + ? conversionUtil(value, { + fromNumericBase: 'hex', + toCurrency: symbol, + conversionRate: multiplier, + invertConversionRate: true, + }) + : conversionUtil(value, { + fromNumericBase: 'hex', + toNumericBase: 'dec', + fromDenomination: 'WEI', + numberOfDecimals: 6, + conversionRate, + }) +} + CurrencyDisplay.prototype.render = function () { const { className = 'currency-display', @@ -50,13 +72,7 @@ CurrencyDisplay.prototype.render = function () { handleChange, } = this.props - const valueToRender = conversionUtil(value, { - fromNumericBase: 'hex', - toNumericBase: 'dec', - fromDenomination: 'WEI', - numberOfDecimals: 6, - conversionRate, - }) + const valueToRender = this.getValueToRender() const convertedValue = conversionUtil(valueToRender, { fromNumericBase: 'dec', diff --git a/ui/app/send-v2.js b/ui/app/send-v2.js index 8c8b97a6d..ffc9accc5 100644 --- a/ui/app/send-v2.js +++ b/ui/app/send-v2.js @@ -328,9 +328,11 @@ SendTransactionScreen.prototype.setAmountToMax = function () { ) updateSendErrors({ amount: null }) - updateGasPrice(MIN_GAS_PRICE_HEX) - updateGasLimit(MIN_GAS_LIMIT_HEX) - updateGasTotal(MIN_GAS_TOTAL) + if (!selectedToken) { + updateGasPrice(MIN_GAS_PRICE_HEX) + updateGasLimit(MIN_GAS_LIMIT_HEX) + updateGasTotal(MIN_GAS_TOTAL) + } updateSendAmount(maxAmount) } -- cgit From d1977225a48f381f3a6bda4a54ce9e0e0914357e Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 7 Nov 2017 21:49:14 -0330 Subject: Calculate max amount for send ether based on minimum gas total. --- ui/app/components/send/currency-display.js | 8 -------- ui/app/send-v2.js | 3 +-- 2 files changed, 1 insertion(+), 10 deletions(-) (limited to 'ui') diff --git a/ui/app/components/send/currency-display.js b/ui/app/components/send/currency-display.js index 49df5b0b7..870fbb42a 100644 --- a/ui/app/components/send/currency-display.js +++ b/ui/app/components/send/currency-display.js @@ -11,11 +11,6 @@ function CurrencyDisplay () { Component.call(this) } -function isValidInput (text) { - const re = /^([1-9]\d*|0)(\.|\.\d*)?$/ - return re.test(text) -} - function toHexWei (value) { return conversionUtil(value, { fromNumericBase: 'dec', @@ -68,7 +63,6 @@ CurrencyDisplay.prototype.render = function () { convertedCurrency, readOnly = false, inError = false, - value, handleChange, } = this.props @@ -82,8 +76,6 @@ CurrencyDisplay.prototype.render = function () { conversionRate, }) - const inputSizeMultiplier = readOnly ? 1 : 1.2 - return h('div', { className, style: { diff --git a/ui/app/send-v2.js b/ui/app/send-v2.js index ffc9accc5..0cef47b27 100644 --- a/ui/app/send-v2.js +++ b/ui/app/send-v2.js @@ -307,7 +307,6 @@ SendTransactionScreen.prototype.handleAmountChange = function (value) { SendTransactionScreen.prototype.setAmountToMax = function () { const { from: { balance }, - gasTotal, updateSendAmount, updateSendErrors, updateGasPrice, @@ -323,7 +322,7 @@ SendTransactionScreen.prototype.setAmountToMax = function () { ? multiplyCurrencies(tokenBalance, multiplier, {toNumericBase: 'hex'}) : subtractCurrencies( ethUtil.addHexPrefix(balance), - ethUtil.addHexPrefix(gasTotal), + ethUtil.addHexPrefix(MIN_GAS_TOTAL), { toNumericBase: 'hex' } ) -- cgit