From 67bdfe87e31e695f8c4beab1659a3a4b764ccf24 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 30 Oct 2017 15:18:50 -0230 Subject: Token balance in send state; validating sufficient tokens, validation updates on 'from' switching. --- ui/app/send-v2.js | 131 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 108 insertions(+), 23 deletions(-) (limited to 'ui/app/send-v2.js') diff --git a/ui/app/send-v2.js b/ui/app/send-v2.js index 6ce3e1b70..8ad2b912c 100644 --- a/ui/app/send-v2.js +++ b/ui/app/send-v2.js @@ -10,14 +10,19 @@ const MemoTextArea = require('./components/send/memo-textarea') const GasFeeDisplay = require('./components/send/gas-fee-display-v2') const { MIN_GAS_TOTAL } = require('./components/send/send-constants') +const abi = require('human-standard-token-abi') const { multiplyCurrencies, conversionGreaterThan, } = require('./conversion-util') +const { + calcTokenAmount, +} = require('./token-util') const { isBalanceSufficient, -} = require('./components/send/send-utils.js') + isTokenBalanceSufficient, +} = require('./components/send/send-utils') const { isValidAddress } = require('./util') module.exports = SendTransactionScreen @@ -40,6 +45,37 @@ function SendTransactionScreen () { this.validateAmount = this.validateAmount.bind(this) } +const getParamsForGasEstimate = function (selectedAddress, symbol, data) { + const estimatedGasParams = { + from: selectedAddress, + gas: '746a528800', + } + + if (symbol) { + Object.assign(estimatedGasParams, { value: '0x0' }) + } + + if (data) { + Object.assign(estimatedGasParams, { data }) + } + + return estimatedGasParams +} + +SendTransactionScreen.prototype.updateSendTokenBalance = function (usersToken) { + if (!usersToken) return + + const { + selectedToken = {}, + updateSendTokenBalance, + } = this.props + const { decimals } = selectedToken || {} + + const tokenBalance = calcTokenAmount(usersToken.balance.toString(), decimals) + + updateSendTokenBalance(tokenBalance) +} + SendTransactionScreen.prototype.componentWillMount = function () { const { updateTokenExchangeRate, @@ -49,32 +85,25 @@ SendTransactionScreen.prototype.componentWillMount = function () { selectedAddress, data, updateGasTotal, + updateSendTokenBalance, + from, + tokenContract, } = this.props - const { symbol } = selectedToken || {} - - const estimateGasParams = { - from: selectedAddress, - gas: '746a528800', - } + const { symbol, decimals } = selectedToken || {} if (symbol) { updateTokenExchangeRate(symbol) - Object.assign(estimateGasParams, { value: '0x0' }) } - if (data) { - Object.assign(estimateGasParams, { data }) - } + const estimateGasParams = getParamsForGasEstimate(selectedAddress, symbol, data) Promise .all([ getGasPrice(), - estimateGas({ - from: selectedAddress, - gas: '746a528800', - }), + estimateGas(estimateGasParams), + tokenContract && tokenContract.balanceOf(from.address) ]) - .then(([gasPrice, gas]) => { + .then(([gasPrice, gas, usersToken]) => { const newGasTotal = multiplyCurrencies(gas, gasPrice, { toNumericBase: 'hex', @@ -82,9 +111,36 @@ SendTransactionScreen.prototype.componentWillMount = function () { multiplierBase: 16, }) updateGasTotal(newGasTotal) + this.updateSendTokenBalance(usersToken) }) } +SendTransactionScreen.prototype.componentDidUpdate = function (prevProps) { + const { + from: { balance }, + gasTotal, + tokenBalance, + amount, + selectedToken, + } = this.props + const { + from: { balance: prevBalance }, + gasTotal: prevGasTotal, + tokenBalance: prevTokenBalance, + } = prevProps + + const notFirstRender = [prevBalance, prevGasTotal].every(n => n !== null) + + const balanceHasChanged = balance !== prevBalance + const gasTotalHasChange = gasTotal !== prevGasTotal + const tokenBalanceHasChanged = selectedToken && tokenBalance !== prevTokenBalance + const amountValidationChange = balanceHasChanged || gasTotalHasChange || tokenBalanceHasChanged + + if (notFirstRender && amountValidationChange) { + this.validateAmount(amount) + } +} + SendTransactionScreen.prototype.renderHeaderIcon = function () { const { selectedToken } = this.props @@ -144,12 +200,31 @@ SendTransactionScreen.prototype.renderErrorMessage = function (errorType) { : null } +SendTransactionScreen.prototype.handleFromChange = async function (newFrom) { + const { + from, + updateSendFrom, + updateSendTokenBalance, + tokenContract, + selectedToken, + } = this.props + const { decimals } = selectedToken || {} + + if (tokenContract) { + const usersToken = await tokenContract.balanceOf(newFrom.address) + this.updateSendTokenBalance(usersToken) + } + updateSendFrom(newFrom) +} + SendTransactionScreen.prototype.renderFromRow = function () { const { from, fromAccounts, conversionRate, updateSendFrom, + updateSendTokenBalance, + tokenContract, } = this.props const { fromDropdownOpen } = this.state @@ -163,7 +238,7 @@ SendTransactionScreen.prototype.renderFromRow = function () { dropdownOpen: fromDropdownOpen, accounts: fromAccounts, selectedAccount: from, - onSelect: updateSendFrom, + onSelect: newFrom => this.handleFromChange(newFrom), openDropdown: () => this.setState({ fromDropdownOpen: true }), closeDropdown: () => this.setState({ fromDropdownOpen: false }), conversionRate, @@ -239,21 +314,31 @@ SendTransactionScreen.prototype.validateAmount = function (value) { primaryCurrency, selectedToken, gasTotal, + tokenBalance, } = this.props + const { decimals } = selectedToken || {} const amount = value let amountError = null const sufficientBalance = isBalanceSufficient({ - amount, + amount: selectedToken ? '0x0' : amount, gasTotal, balance, primaryCurrency, - selectedToken, amountConversionRate, conversionRate, }) + let sufficientTokens + if (selectedToken) { + sufficientTokens = isTokenBalanceSufficient({ + tokenBalance, + amount, + decimals, + }) + } + const amountLessThanZero = conversionGreaterThan( { value: 0, fromNumericBase: 'dec' }, { value: amount, fromNumericBase: 'hex' }, @@ -261,6 +346,8 @@ SendTransactionScreen.prototype.validateAmount = function (value) { if (!sufficientBalance) { amountError = 'Insufficient funds.' + } else if (selectedToken && !sufficientTokens) { + amountError = 'Insufficient tokens.' } else if (amountLessThanZero) { amountError = 'Can not send negative amounts of ETH.' } @@ -275,10 +362,9 @@ SendTransactionScreen.prototype.renderAmountRow = function () { convertedCurrency, amountConversionRate, errors, + amount, } = this.props - const { amount } = this.state - return h('div.send-v2__form-row', [ h('div.send-v2__form-label', [ @@ -335,8 +421,7 @@ SendTransactionScreen.prototype.renderGasRow = function () { } SendTransactionScreen.prototype.renderMemoRow = function () { - const { updateSendMemo } = this.props - const { memo } = this.state + const { updateSendMemo, memo } = this.props return h('div.send-v2__form-row', [ -- cgit v1.2.3 From 319779ab081f70343b5ef77531450878292a90d6 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 26 Oct 2017 14:13:12 -0230 Subject: Adds max amount feature for send-ether --- ui/app/send-v2.js | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'ui/app/send-v2.js') diff --git a/ui/app/send-v2.js b/ui/app/send-v2.js index 8ad2b912c..412aa417c 100644 --- a/ui/app/send-v2.js +++ b/ui/app/send-v2.js @@ -2,6 +2,8 @@ const { inherits } = require('util') const PersistentForm = require('../lib/persistent-form') const h = require('react-hyperscript') +const ethUtil = require('ethereumjs-util') + const Identicon = require('./components/identicon') const FromDropdown = require('./components/send/from-dropdown') const ToAutoComplete = require('./components/send/to-autocomplete') @@ -9,12 +11,17 @@ const CurrencyDisplay = require('./components/send/currency-display') const MemoTextArea = require('./components/send/memo-textarea') const GasFeeDisplay = require('./components/send/gas-fee-display-v2') -const { MIN_GAS_TOTAL } = require('./components/send/send-constants') +const { + MIN_GAS_TOTAL, + MIN_GAS_PRICE_HEX, + MIN_GAS_LIMIT_HEX, +} = require('./components/send/send-constants') const abi = require('human-standard-token-abi') const { multiplyCurrencies, conversionGreaterThan, + subtractCurrencies, } = require('./conversion-util') const { calcTokenAmount, @@ -305,6 +312,30 @@ SendTransactionScreen.prototype.handleAmountChange = function (value) { updateSendAmount(amount) } +SendTransactionScreen.prototype.setAmountToMax = function () { + const { + from: { balance }, + gasTotal, + updateSendAmount, + updateSendErrors, + updateGasPrice, + updateGasLimit, + updateGasTotal, + } = this.props + + const maxAmount = subtractCurrencies( + ethUtil.addHexPrefix(balance), + ethUtil.addHexPrefix(MIN_GAS_TOTAL), + { toNumericBase: 'hex' } + ) + + updateSendErrors({ amount: null }) + updateGasPrice(MIN_GAS_PRICE_HEX) + updateGasLimit(MIN_GAS_LIMIT_HEX) + updateGasTotal(MIN_GAS_TOTAL) + updateSendAmount(maxAmount) +} + SendTransactionScreen.prototype.validateAmount = function (value) { const { from: { balance }, @@ -370,6 +401,12 @@ SendTransactionScreen.prototype.renderAmountRow = function () { h('div.send-v2__form-label', [ 'Amount:', this.renderErrorMessage('amount'), + !errors.amount && h('div.send-v2__amount-max', { + onClick: (event) => { + event.preventDefault() + this.setAmountToMax() + }, + }, [ 'Max' ]), ]), h('div.send-v2__form-field', [ -- cgit v1.2.3 From c420249fb9115f7dc871acfd8c5cf832ebf5e890 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 30 Oct 2017 15:37:30 -0230 Subject: Adds max amount feature for send token --- ui/app/send-v2.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'ui/app/send-v2.js') 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) } -- cgit v1.2.3 From e5391cf9fdc7dfc25318caaed5dd56270946ddf8 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 30 Oct 2017 19:34:21 -0230 Subject: Allow sending 0 eth or tokens --- ui/app/send-v2.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ui/app/send-v2.js') diff --git a/ui/app/send-v2.js b/ui/app/send-v2.js index 6f3b48be6..951af3d2c 100644 --- a/ui/app/send-v2.js +++ b/ui/app/send-v2.js @@ -422,7 +422,7 @@ SendTransactionScreen.prototype.renderAmountRow = function () { primaryCurrency, convertedCurrency, selectedToken, - value: amount, + value: amount || '0x0', conversionRate: amountConversionRate, handleChange: this.handleAmountChange, validate: this.validateAmount, @@ -512,7 +512,7 @@ SendTransactionScreen.prototype.renderFooter = function () { errors: { amount: amountError, to: toError }, } = this.props - const noErrors = amountError === null && toError === null + const noErrors = !amountError && toError === null const errorClass = noErrors ? '' : '__disabled' return h('div.send-v2__footer', [ @@ -566,7 +566,7 @@ SendTransactionScreen.prototype.onSubmit = function (event) { errors: { amount: amountError, to: toError }, } = this.props - const noErrors = amountError === null && toError === null + const noErrors = !amountError && toError === null if (!noErrors) { return -- cgit v1.2.3 From 8c6e1232e417f5a2974b5aa1cc479dac4925df63 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 6 Nov 2017 16:14:46 -0330 Subject: Lint fixes. --- ui/app/send-v2.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'ui/app/send-v2.js') diff --git a/ui/app/send-v2.js b/ui/app/send-v2.js index 951af3d2c..bb4c592e8 100644 --- a/ui/app/send-v2.js +++ b/ui/app/send-v2.js @@ -16,7 +16,6 @@ const { MIN_GAS_PRICE_HEX, MIN_GAS_LIMIT_HEX, } = require('./components/send/send-constants') -const abi = require('human-standard-token-abi') const { multiplyCurrencies, @@ -92,11 +91,10 @@ SendTransactionScreen.prototype.componentWillMount = function () { selectedAddress, data, updateGasTotal, - updateSendTokenBalance, from, tokenContract, } = this.props - const { symbol, decimals } = selectedToken || {} + const { symbol } = selectedToken || {} if (symbol) { updateTokenExchangeRate(symbol) @@ -209,13 +207,9 @@ SendTransactionScreen.prototype.renderErrorMessage = function (errorType) { SendTransactionScreen.prototype.handleFromChange = async function (newFrom) { const { - from, updateSendFrom, - updateSendTokenBalance, tokenContract, - selectedToken, } = this.props - const { decimals } = selectedToken || {} if (tokenContract) { const usersToken = await tokenContract.balanceOf(newFrom.address) @@ -229,9 +223,6 @@ SendTransactionScreen.prototype.renderFromRow = function () { from, fromAccounts, conversionRate, - updateSendFrom, - updateSendTokenBalance, - tokenContract, } = this.props const { fromDropdownOpen } = this.state -- cgit v1.2.3 From c57d504794b6020d42dcdabe08a13ed412450fc1 Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 7 Nov 2017 20:06:26 -0330 Subject: Add currency-input component to correct send amount behaviour and move currency display value state to parent component. --- ui/app/send-v2.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'ui/app/send-v2.js') diff --git a/ui/app/send-v2.js b/ui/app/send-v2.js index bb4c592e8..8c8b97a6d 100644 --- a/ui/app/send-v2.js +++ b/ui/app/send-v2.js @@ -300,6 +300,7 @@ SendTransactionScreen.prototype.handleAmountChange = function (value) { const amount = value const { updateSendAmount } = this.props + this.validateAmount(amount) updateSendAmount(amount) } @@ -330,7 +331,6 @@ SendTransactionScreen.prototype.setAmountToMax = function () { updateGasPrice(MIN_GAS_PRICE_HEX) updateGasLimit(MIN_GAS_LIMIT_HEX) updateGasTotal(MIN_GAS_TOTAL) - updateSendAmount(maxAmount) } @@ -393,9 +393,8 @@ SendTransactionScreen.prototype.renderAmountRow = function () { errors, amount, } = this.props - return h('div.send-v2__form-row', [ - + h('div.send-v2__form-label', [ 'Amount:', this.renderErrorMessage('amount'), @@ -416,7 +415,6 @@ SendTransactionScreen.prototype.renderAmountRow = function () { value: amount || '0x0', conversionRate: amountConversionRate, handleChange: this.handleAmountChange, - validate: this.validateAmount, }), ]), -- cgit v1.2.3 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/send-v2.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'ui/app/send-v2.js') 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 v1.2.3 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/send-v2.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'ui/app/send-v2.js') 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 v1.2.3 From 5120cfdff3047e4bf88cec544895cc713d063cdd Mon Sep 17 00:00:00 2001 From: Thomas Huang Date: Thu, 9 Nov 2017 14:23:10 -0800 Subject: Linting --- ui/app/send-v2.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ui/app/send-v2.js') diff --git a/ui/app/send-v2.js b/ui/app/send-v2.js index 0cef47b27..690af7e5c 100644 --- a/ui/app/send-v2.js +++ b/ui/app/send-v2.js @@ -106,7 +106,7 @@ SendTransactionScreen.prototype.componentWillMount = function () { .all([ getGasPrice(), estimateGas(estimateGasParams), - tokenContract && tokenContract.balanceOf(from.address) + tokenContract && tokenContract.balanceOf(from.address), ]) .then(([gasPrice, gas, usersToken]) => { @@ -352,7 +352,7 @@ SendTransactionScreen.prototype.validateAmount = function (value) { let amountError = null const sufficientBalance = isBalanceSufficient({ - amount: selectedToken ? '0x0' : amount, + amount: selectedToken ? '0x0' : amount, gasTotal, balance, primaryCurrency, @@ -395,7 +395,7 @@ SendTransactionScreen.prototype.renderAmountRow = function () { amount, } = this.props return h('div.send-v2__form-row', [ - + h('div.send-v2__form-label', [ 'Amount:', this.renderErrorMessage('amount'), -- cgit v1.2.3 From 34ca7290c593d6fb27faa98a660c8c0bca7e1457 Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 8 Nov 2017 13:14:48 -0330 Subject: Allow editing of send ether. --- ui/app/send-v2.js | 54 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 17 deletions(-) (limited to 'ui/app/send-v2.js') diff --git a/ui/app/send-v2.js b/ui/app/send-v2.js index 690af7e5c..b7e904ea8 100644 --- a/ui/app/send-v2.js +++ b/ui/app/send-v2.js @@ -93,6 +93,9 @@ SendTransactionScreen.prototype.componentWillMount = function () { updateGasTotal, from, tokenContract, + editingTransactionId, + gasPrice, + gasLimit, } = this.props const { symbol } = selectedToken || {} @@ -102,22 +105,32 @@ SendTransactionScreen.prototype.componentWillMount = function () { const estimateGasParams = getParamsForGasEstimate(selectedAddress, symbol, data) - Promise - .all([ - getGasPrice(), - estimateGas(estimateGasParams), - tokenContract && tokenContract.balanceOf(from.address), - ]) - .then(([gasPrice, gas, usersToken]) => { - - const newGasTotal = multiplyCurrencies(gas, gasPrice, { - toNumericBase: 'hex', - multiplicandBase: 16, - multiplierBase: 16, + let newGasTotal + if (!editingTransactionId) { + Promise + .all([ + getGasPrice(), + estimateGas(estimateGasParams), + tokenContract && tokenContract.balanceOf(from.address) + ]) + .then(([gasPrice, gas, usersToken]) => { + + const newGasTotal = multiplyCurrencies(gas, gasPrice, { + toNumericBase: 'hex', + multiplicandBase: 16, + multiplierBase: 16, + }) + updateGasTotal(newGasTotal) + this.updateSendTokenBalance(usersToken) }) - updateGasTotal(newGasTotal) - this.updateSendTokenBalance(usersToken) + } else { + newGasTotal = multiplyCurrencies(gasLimit, gasPrice, { + toNumericBase: 'hex', + multiplicandBase: 16, + multiplierBase: 16, }) + updateGasTotal(newGasTotal) + } } SendTransactionScreen.prototype.componentDidUpdate = function (prevProps) { @@ -394,6 +407,7 @@ SendTransactionScreen.prototype.renderAmountRow = function () { errors, amount, } = this.props + return h('div.send-v2__form-row', [ h('div.send-v2__form-label', [ @@ -551,9 +565,12 @@ SendTransactionScreen.prototype.onSubmit = function (event) { gasPrice, signTokenTx, signTx, + updateAndApproveTx, selectedToken, - clearSend, + toAccounts, + editingTransactionId, errors: { amount: amountError, to: toError }, + backToConfirmScreen, } = this.props const noErrors = !amountError && toError === null @@ -564,6 +581,11 @@ SendTransactionScreen.prototype.onSubmit = function (event) { this.addToAddressBookIfNew(to) + if (editingTransactionId) { + backToConfirmScreen(editingTransactionId) + return + } + const txParams = { from, value: '0', @@ -576,8 +598,6 @@ SendTransactionScreen.prototype.onSubmit = function (event) { txParams.to = to } - clearSend() - selectedToken ? signTokenTx(selectedToken.address, to, amount, txParams) : signTx(txParams) -- cgit v1.2.3 From 0a91671ff69957596abbcffb7d20c89f144d7a69 Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 8 Nov 2017 15:48:27 -0330 Subject: Fix lint errors. --- ui/app/send-v2.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'ui/app/send-v2.js') diff --git a/ui/app/send-v2.js b/ui/app/send-v2.js index b7e904ea8..0d745c66e 100644 --- a/ui/app/send-v2.js +++ b/ui/app/send-v2.js @@ -111,7 +111,7 @@ SendTransactionScreen.prototype.componentWillMount = function () { .all([ getGasPrice(), estimateGas(estimateGasParams), - tokenContract && tokenContract.balanceOf(from.address) + tokenContract && tokenContract.balanceOf(from.address), ]) .then(([gasPrice, gas, usersToken]) => { @@ -565,9 +565,7 @@ SendTransactionScreen.prototype.onSubmit = function (event) { gasPrice, signTokenTx, signTx, - updateAndApproveTx, selectedToken, - toAccounts, editingTransactionId, errors: { amount: amountError, to: toError }, backToConfirmScreen, -- cgit v1.2.3 From 4671f28476165fec43785ae23352c1e9a0776abc Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 9 Nov 2017 11:44:32 -0330 Subject: Allow editing of token transactions. --- ui/app/send-v2.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'ui/app/send-v2.js') diff --git a/ui/app/send-v2.js b/ui/app/send-v2.js index 0d745c66e..788ae87b4 100644 --- a/ui/app/send-v2.js +++ b/ui/app/send-v2.js @@ -76,7 +76,6 @@ SendTransactionScreen.prototype.updateSendTokenBalance = function (usersToken) { updateSendTokenBalance, } = this.props const { decimals } = selectedToken || {} - const tokenBalance = calcTokenAmount(usersToken.balance.toString(), decimals) updateSendTokenBalance(tokenBalance) @@ -105,13 +104,14 @@ SendTransactionScreen.prototype.componentWillMount = function () { const estimateGasParams = getParamsForGasEstimate(selectedAddress, symbol, data) + const tokenBalancePromise = tokenContract && tokenContract.balanceOf(from.address) let newGasTotal if (!editingTransactionId) { Promise .all([ getGasPrice(), estimateGas(estimateGasParams), - tokenContract && tokenContract.balanceOf(from.address), + tokenBalancePromise, ]) .then(([gasPrice, gas, usersToken]) => { @@ -130,6 +130,8 @@ SendTransactionScreen.prototype.componentWillMount = function () { multiplierBase: 16, }) updateGasTotal(newGasTotal) + tokenBalancePromise && tokenBalancePromise.then( + usersToken => this.updateSendTokenBalance(usersToken)) } } @@ -363,7 +365,6 @@ SendTransactionScreen.prototype.validateAmount = function (value) { const amount = value let amountError = null - const sufficientBalance = isBalanceSufficient({ amount: selectedToken ? '0x0' : amount, gasTotal, -- cgit v1.2.3