diff options
author | Chi Kei Chan <chikeichan@gmail.com> | 2017-10-20 03:35:39 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-20 03:35:39 +0800 |
commit | f1c097ab5c833d0e4bab639d65e5641211cb9753 (patch) | |
tree | 0e63ad5171608accdd2a0d669687a16cd8c17b95 /ui/app | |
parent | 332c7441b656ec82ebfba863e3feb4dbf365d67b (diff) | |
parent | c2880c4b8fe56f3b175d75b6ae8a84271dde3e28 (diff) | |
download | tangerine-wallet-browser-f1c097ab5c833d0e4bab639d65e5641211cb9753.tar tangerine-wallet-browser-f1c097ab5c833d0e4bab639d65e5641211cb9753.tar.gz tangerine-wallet-browser-f1c097ab5c833d0e4bab639d65e5641211cb9753.tar.bz2 tangerine-wallet-browser-f1c097ab5c833d0e4bab639d65e5641211cb9753.tar.lz tangerine-wallet-browser-f1c097ab5c833d0e4bab639d65e5641211cb9753.tar.xz tangerine-wallet-browser-f1c097ab5c833d0e4bab639d65e5641211cb9753.tar.zst tangerine-wallet-browser-f1c097ab5c833d0e4bab639d65e5641211cb9753.zip |
Merge branch 'NewUI-flat' into MM-128-get-currentCurrency-from-state
Diffstat (limited to 'ui/app')
-rw-r--r-- | ui/app/components/pending-tx/confirm-send-token.js | 51 | ||||
-rw-r--r-- | ui/app/conversion-util.js | 8 | ||||
-rw-r--r-- | ui/app/selectors.js | 11 |
3 files changed, 48 insertions, 22 deletions
diff --git a/ui/app/components/pending-tx/confirm-send-token.js b/ui/app/components/pending-tx/confirm-send-token.js index 155242f56..42b676954 100644 --- a/ui/app/components/pending-tx/confirm-send-token.js +++ b/ui/app/components/pending-tx/confirm-send-token.js @@ -11,12 +11,22 @@ const Identicon = require('../identicon') const ethUtil = require('ethereumjs-util') const BN = ethUtil.BN const hexToBn = require('../../../../app/scripts/lib/hex-to-bn') -const { conversionUtil } = require('../../conversion-util') +const { + conversionUtil, + multiplyCurrencies, + addCurrencies, +} = require('../../conversion-util') const MIN_GAS_PRICE_GWEI_BN = new BN(1) const GWEI_FACTOR = new BN(1e9) const MIN_GAS_PRICE_BN = MIN_GAS_PRICE_GWEI_BN.mul(GWEI_FACTOR) +const { + getSelectedTokenExchangeRate, + getTokenExchangeRate, + getSelectedAddress, +} = require('../../selectors') + module.exports = connect(mapStateToProps, mapDispatchToProps)(ConfirmSendToken) function mapStateToProps (state, ownProps) { @@ -28,10 +38,8 @@ function mapStateToProps (state, ownProps) { identities, } = state.metamask const accounts = state.metamask.accounts - const selectedAddress = state.metamask.selectedAddress || Object.keys(accounts)[0] - const tokenExchangeRates = state.metamask.tokenExchangeRates - const pair = `${symbol.toLowerCase()}_eth` - const { rate: tokenExchangeRate = 0 } = tokenExchangeRates[pair] || {} + const selectedAddress = getSelectedAddress(state) + const tokenExchangeRate = getTokenExchangeRate(state, symbol) return { conversionRate, @@ -86,15 +94,12 @@ ConfirmSendToken.prototype.getGasFee = function () { const txParams = txMeta.txParams || {} const { decimals } = token - // Gas const gas = txParams.gas - const gasBn = hexToBn(gas) - - // Gas Price const gasPrice = txParams.gasPrice || MIN_GAS_PRICE_BN.toString(16) - const gasPriceBn = hexToBn(gasPrice) - const txFeeBn = gasBn.mul(gasPriceBn) - + const gasTotal = multiplyCurrencies(gas, gasPrice, { + multiplicandBase: 16, + multiplierBase: 16, + }) const FIAT = conversionUtil(txFeeBn, { fromNumericBase: 'BN', @@ -105,7 +110,7 @@ ConfirmSendToken.prototype.getGasFee = function () { numberOfDecimals: 2, conversionRate, }) - const ETH = conversionUtil(txFeeBn, { + const ETH = conversionUtil(gasTotal, { fromNumericBase: 'BN', toNumericBase: 'dec', fromDenomination: 'WEI', @@ -114,12 +119,22 @@ ConfirmSendToken.prototype.getGasFee = function () { numberOfDecimals: 6, conversionRate, }) + const tokenGas = multiplyCurrencies(gas, gasPrice, { + toNumericBase: 'dec', + multiplicandBase: 16, + multiplierBase: 16, + toCurrency: 'BAT', + conversionRate: tokenExchangeRate, + invertConversionRate: true, + fromDenomination: 'WEI', + numberOfDecimals: decimals || 4, + }) return { fiat: +Number(FIAT).toFixed(2), eth: ETH, token: tokenExchangeRate - ? +(ETH * tokenExchangeRate).toFixed(decimals) + ? tokenGas : null, } } @@ -130,14 +145,14 @@ ConfirmSendToken.prototype.getData = function () { const { value } = params[0] || {} const txMeta = this.gatherTxMeta() const txParams = txMeta.txParams || {} - + return { from: { address: txParams.from, name: identities[txParams.from].name, }, to: { - address: txParams.to, + address: value, name: identities[value] ? identities[value].name : 'New Recipient', }, memo: txParams.memo || '', @@ -196,6 +211,8 @@ ConfirmSendToken.prototype.renderTotalPlusGas = function () { const { fiat: fiatAmount, token: tokenAmount } = this.getAmount() const { fiat: fiatGas, token: tokenGas } = this.getGasFee() + const tokenTotal = addCurrencies(tokenAmount, tokenGas || '0') + return fiatAmount && fiatGas ? ( h('section.flex-row.flex-center.confirm-screen-total-box ', [ @@ -273,7 +290,7 @@ ConfirmSendToken.prototype.render = function () { h( Identicon, { - address: txParams.to, + address: toAddress, diameter: 60, }, ), diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index 50f903d9f..2f3fb1678 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -147,16 +147,16 @@ const addCurrencies = (a, b, options = {}) => { const multiplyCurrencies = (a, b, options = {}) => { const { - toNumericBase, - numberOfDecimals, multiplicandBase, multiplierBase, + ...conversionOptions, } = options + const value = (new BigNumber(a, multiplicandBase)).times(b, multiplierBase); + return converter({ value, - toNumericBase, - numberOfDecimals, + ...conversionOptions, }) } diff --git a/ui/app/selectors.js b/ui/app/selectors.js index 1cfbc3975..66b7c00e4 100644 --- a/ui/app/selectors.js +++ b/ui/app/selectors.js @@ -6,6 +6,7 @@ const selectors = { getSelectedAccount, getSelectedToken, getSelectedTokenExchangeRate, + getTokenExchangeRate, conversionRateSelector, transactionsSelector, accountsWithSendEtherInfoSelector, @@ -58,7 +59,15 @@ function getSelectedTokenExchangeRate (state) { return tokenExchangeRate } -function conversionRateSelector (state) { +function getTokenExchangeRate (state, tokenSymbol) { + const pair = `${tokenSymbol.toLowerCase()}_eth` + const tokenExchangeRates = state.metamask.tokenExchangeRates + const { rate: tokenExchangeRate = 0 } = tokenExchangeRates[pair] || {} + + return tokenExchangeRate +} + +function conversionRateSelector (state) { return state.metamask.conversionRate } |