diff options
author | Dan <danjm.com@gmail.com> | 2017-09-15 20:31:25 +0800 |
---|---|---|
committer | Chi Kei Chan <chikeichan@gmail.com> | 2017-09-16 07:16:41 +0800 |
commit | 095d327140fe4bb2b4a131a66e2774bdfeb8ce37 (patch) | |
tree | 559c3d59d438c25a0015cac707767d7b5779170e /ui/app/components | |
parent | ab77142c90a532a775636cf20a7e23191ff47f8f (diff) | |
download | tangerine-wallet-browser-095d327140fe4bb2b4a131a66e2774bdfeb8ce37.tar.gz tangerine-wallet-browser-095d327140fe4bb2b4a131a66e2774bdfeb8ce37.tar.zst tangerine-wallet-browser-095d327140fe4bb2b4a131a66e2774bdfeb8ce37.zip |
Adds USD to token list.
Diffstat (limited to 'ui/app/components')
-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), ]), /* |