diff options
Adds USD to token list.
Diffstat (limited to 'ui/app/components/token-cell.js')
-rw-r--r-- | ui/app/components/token-cell.js | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/ui/app/components/token-cell.js b/ui/app/components/token-cell.js index a6fe8fc61..dc1c7f46f 100644 --- a/ui/app/components/token-cell.js +++ b/ui/app/components/token-cell.js @@ -6,18 +6,22 @@ const Identicon = require('./identicon') const prefixForNetwork = require('../../lib/etherscan-prefix-for-network') const selectors = require('../selectors') const actions = require('../actions') +const { conversionUtil } = require('../conversion-util') function mapStateToProps (state) { return { network: state.metamask.network, selectedTokenAddress: state.metamask.selectedTokenAddress, userAddress: selectors.getSelectedAddress(state), + tokenExchangeRates: state.metamask.tokenExchangeRates, + ethToUSDRate: state.metamask.conversionRate, } } function mapDispatchToProps (dispatch) { return { setSelectedToken: address => dispatch(actions.setSelectedToken(address)), + updateTokenExchangeRate: token => dispatch(actions.updateTokenExchangeRate(token)), } } @@ -28,6 +32,15 @@ function TokenCell () { Component.call(this) } +TokenCell.prototype.componentWillMount = function () { + const { + updateTokenExchangeRate, + symbol, + } = this.props + + updateTokenExchangeRate(symbol) +} + TokenCell.prototype.render = function () { const props = this.props const { @@ -37,8 +50,29 @@ TokenCell.prototype.render = function () { network, setSelectedToken, selectedTokenAddress, + tokenExchangeRates, + ethToUSDRate, // userAddress, } = props + + const pair = `${symbol.toLowerCase()}_eth`; + + let currentTokenToEthRate; + let currentTokenInUSD; + let formattedUSD = '' + + if (tokenExchangeRates[pair]) { + currentTokenToEthRate = tokenExchangeRates[pair].rate; + currentTokenInUSD = conversionUtil(string, { + fromNumericBase: 'dec', + fromCurrency: symbol, + toCurrency: 'USD', + numberOfDecimals: 2, + conversionRate: currentTokenToEthRate, + ethToUSDRate, + }) + formattedUSD = `$${currentTokenInUSD} USD`; + } return ( h('div.token-list-item', { @@ -58,9 +92,9 @@ TokenCell.prototype.render = function () { h('h.token-list-item__balance-wrapper', null, [ h('h3.token-list-item__token-balance', `${string || 0} ${symbol}`), - // h('div.token-list-item__fiat-amount', { - // style: {}, - // }, '210 FPO'), + h('div.token-list-item__fiat-amount', { + style: {}, + }, formattedUSD), ]), /* |