diff options
Diffstat (limited to 'ui')
-rw-r--r-- | ui/app/actions.js | 3 | ||||
-rw-r--r-- | ui/app/components/send/send-v2-container.js | 1 | ||||
-rw-r--r-- | ui/app/css/itcss/components/modal.scss | 1 | ||||
-rw-r--r-- | ui/app/send-v2.js | 65 | ||||
-rw-r--r-- | ui/app/util.js | 5 |
5 files changed, 53 insertions, 22 deletions
diff --git a/ui/app/actions.js b/ui/app/actions.js index 192a73f76..25cb2c23f 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -1,5 +1,6 @@ const abi = require('human-standard-token-abi') const getBuyEthUrl = require('../../app/scripts/lib/buy-eth-url') +const { getTokenAddressFromTokenObject } = require('./util') const ethUtil = require('ethereumjs-util') var actions = { @@ -1094,10 +1095,12 @@ function removeToken (address) { function addTokens (tokens) { return dispatch => { if (Array.isArray(tokens)) { + dispatch(actions.setSelectedToken(getTokenAddressFromTokenObject(tokens[0]))) return Promise.all(tokens.map(({ address, symbol, decimals }) => ( dispatch(addToken(address, symbol, decimals)) ))) } else { + dispatch(actions.setSelectedToken(getTokenAddressFromTokenObject(tokens))) return Promise.all( Object .entries(tokens) diff --git a/ui/app/components/send/send-v2-container.js b/ui/app/components/send/send-v2-container.js index 2d2ed4546..1106902b7 100644 --- a/ui/app/components/send/send-v2-container.js +++ b/ui/app/components/send/send-v2-container.js @@ -51,6 +51,7 @@ function mapStateToProps (state) { amountConversionRate: selectedToken ? tokenToFiatRate : conversionRate, tokenContract: getSelectedTokenContract(state), unapprovedTxs: state.metamask.unapprovedTxs, + network: state.metamask.network, } } diff --git a/ui/app/css/itcss/components/modal.scss b/ui/app/css/itcss/components/modal.scss index 501351700..5bca4a07d 100644 --- a/ui/app/css/itcss/components/modal.scss +++ b/ui/app/css/itcss/components/modal.scss @@ -815,6 +815,7 @@ width: 100%; display: flex; justify-content: center; + align-items: center; padding: 30px; font-size: 22px; color: $nile-blue; diff --git a/ui/app/send-v2.js b/ui/app/send-v2.js index ca73fa5ea..d9187fd80 100644 --- a/ui/app/send-v2.js +++ b/ui/app/send-v2.js @@ -85,6 +85,20 @@ SendTransactionScreen.prototype.componentWillMount = function () { const { updateTokenExchangeRate, selectedToken = {}, + } = this.props + + const { symbol } = selectedToken || {} + + if (symbol) { + updateTokenExchangeRate(symbol) + } + + this.updateGas() +} + +SendTransactionScreen.prototype.updateGas = function () { + const { + selectedToken = {}, getGasPrice, estimateGas, selectedAddress, @@ -96,17 +110,16 @@ SendTransactionScreen.prototype.componentWillMount = function () { gasPrice, gasLimit, } = this.props - const { symbol } = selectedToken || {} - if (symbol) { - updateTokenExchangeRate(symbol) - } + const { symbol } = selectedToken || {} - const estimateGasParams = getParamsForGasEstimate(selectedAddress, symbol, data) + const tokenBalancePromise = tokenContract + ? tokenContract.balanceOf(from.address) + : Promise.resolve() - const tokenBalancePromise = tokenContract && tokenContract.balanceOf(from.address) - let newGasTotal if (!editingTransactionId) { + const estimateGasParams = getParamsForGasEstimate(selectedAddress, symbol, data) + Promise .all([ getGasPrice(), @@ -114,27 +127,26 @@ SendTransactionScreen.prototype.componentWillMount = function () { tokenBalancePromise, ]) .then(([gasPrice, gas, usersToken]) => { - - const newGasTotal = multiplyCurrencies(gas, gasPrice, { - toNumericBase: 'hex', - multiplicandBase: 16, - multiplierBase: 16, - }) + const newGasTotal = this.getGasTotal(gas, gasPrice) updateGasTotal(newGasTotal) this.updateSendTokenBalance(usersToken) }) } else { - newGasTotal = multiplyCurrencies(gasLimit, gasPrice, { - toNumericBase: 'hex', - multiplicandBase: 16, - multiplierBase: 16, - }) + const newGasTotal = this.getGasTotal(gasLimit, gasPrice) updateGasTotal(newGasTotal) - tokenBalancePromise && tokenBalancePromise.then( - usersToken => this.updateSendTokenBalance(usersToken)) + tokenBalancePromise + .then(usersToken => this.updateSendTokenBalance(usersToken)) } } +SendTransactionScreen.prototype.getGasTotal = function (gasLimit, gasPrice) { + return multiplyCurrencies(gasLimit, gasPrice, { + toNumericBase: 'hex', + multiplicandBase: 16, + multiplierBase: 16, + }) +} + SendTransactionScreen.prototype.componentDidUpdate = function (prevProps) { const { from: { balance }, @@ -142,11 +154,14 @@ SendTransactionScreen.prototype.componentDidUpdate = function (prevProps) { tokenBalance, amount, selectedToken, + network, } = this.props + const { from: { balance: prevBalance }, gasTotal: prevGasTotal, tokenBalance: prevTokenBalance, + network: prevNetwork, } = prevProps const notFirstRender = [prevBalance, prevGasTotal].every(n => n !== null) @@ -156,8 +171,14 @@ SendTransactionScreen.prototype.componentDidUpdate = function (prevProps) { const tokenBalanceHasChanged = selectedToken && tokenBalance !== prevTokenBalance const amountValidationChange = balanceHasChanged || gasTotalHasChange || tokenBalanceHasChanged - if (notFirstRender && amountValidationChange) { - this.validateAmount(amount) + if (notFirstRender) { + if (amountValidationChange) { + this.validateAmount(amount) + } + + if (network !== prevNetwork && network !== 'loading') { + this.updateGas() + } } } diff --git a/ui/app/util.js b/ui/app/util.js index 70c503550..800ccb218 100644 --- a/ui/app/util.js +++ b/ui/app/util.js @@ -56,6 +56,7 @@ module.exports = { exportAsFile: exportAsFile, isInvalidChecksumAddress, allNull, + getTokenAddressFromTokenObject, } function valuesFor (obj) { @@ -281,3 +282,7 @@ function exportAsFile (filename, data) { function allNull (obj) { return Object.entries(obj).every(([key, value]) => value === null) } + +function getTokenAddressFromTokenObject (token) { + return Object.values(token)[0].address.toLowerCase() +} |