1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 16:18:07 +01:00

Merge pull request #2399 from danjm/MM-128-get-currentCurrency-from-state

[NewUI] Get currentCurrency from state, allows other fiats
This commit is contained in:
Chi Kei Chan 2017-10-19 12:35:49 -07:00 committed by GitHub
commit d3f923efef
14 changed files with 90 additions and 67 deletions

View File

@ -76,6 +76,7 @@ function mapStateToProps (state) {
lastUnreadNotice: state.metamask.lastUnreadNotice, lastUnreadNotice: state.metamask.lastUnreadNotice,
lostAccounts: state.metamask.lostAccounts, lostAccounts: state.metamask.lostAccounts,
frequentRpcList: state.metamask.frequentRpcList || [], frequentRpcList: state.metamask.frequentRpcList || [],
currentCurrency: state.metamask.currentCurrency,
// state needed to get account dropdown temporarily rendering from app bar // state needed to get account dropdown temporarily rendering from app bar
identities, identities,
@ -96,7 +97,9 @@ function mapDispatchToProps (dispatch, ownProps) {
} }
App.prototype.componentWillMount = function () { App.prototype.componentWillMount = function () {
if (!this.props.currentCurrency) {
this.props.setCurrentCurrencyToUSD() this.props.setCurrentCurrencyToUSD()
}
} }
App.prototype.render = function () { App.prototype.render = function () {

View File

@ -21,10 +21,12 @@ function mapStateToProps (state) {
const { const {
conversionRate, conversionRate,
identities, identities,
currentCurrency,
} = state.metamask } = state.metamask
const accounts = state.metamask.accounts const accounts = state.metamask.accounts
const selectedAddress = state.metamask.selectedAddress || Object.keys(accounts)[0] const selectedAddress = state.metamask.selectedAddress || Object.keys(accounts)[0]
return { return {
currentCurrency,
conversionRate, conversionRate,
identities, identities,
selectedAddress, selectedAddress,
@ -124,15 +126,15 @@ ConfirmDeployContract.prototype.getData = function () {
} }
ConfirmDeployContract.prototype.getAmount = function () { ConfirmDeployContract.prototype.getAmount = function () {
const { conversionRate } = this.props const { conversionRate, currentCurrency } = this.props
const txMeta = this.gatherTxMeta() const txMeta = this.gatherTxMeta()
const txParams = txMeta.txParams || {} const txParams = txMeta.txParams || {}
const USD = conversionUtil(txParams.value, { const FIAT = conversionUtil(txParams.value, {
fromNumericBase: 'hex', fromNumericBase: 'hex',
toNumericBase: 'dec', toNumericBase: 'dec',
fromCurrency: 'ETH', fromCurrency: 'ETH',
toCurrency: 'USD', toCurrency: currentCurrency,
numberOfDecimals: 2, numberOfDecimals: 2,
fromDenomination: 'WEI', fromDenomination: 'WEI',
conversionRate, conversionRate,
@ -148,14 +150,14 @@ ConfirmDeployContract.prototype.getAmount = function () {
}) })
return { return {
fiat: Number(USD), fiat: Number(FIAT),
token: Number(ETH), token: Number(ETH),
} }
} }
ConfirmDeployContract.prototype.getGasFee = function () { ConfirmDeployContract.prototype.getGasFee = function () {
const { conversionRate } = this.props const { conversionRate, currentCurrency } = this.props
const txMeta = this.gatherTxMeta() const txMeta = this.gatherTxMeta()
const txParams = txMeta.txParams || {} const txParams = txMeta.txParams || {}
@ -169,12 +171,12 @@ ConfirmDeployContract.prototype.getGasFee = function () {
const txFeeBn = gasBn.mul(gasPriceBn) const txFeeBn = gasBn.mul(gasPriceBn)
const USD = conversionUtil(txFeeBn, { const FIAT = conversionUtil(txFeeBn, {
fromNumericBase: 'BN', fromNumericBase: 'BN',
toNumericBase: 'dec', toNumericBase: 'dec',
fromDenomination: 'WEI', fromDenomination: 'WEI',
fromCurrency: 'ETH', fromCurrency: 'ETH',
toCurrency: 'USD', toCurrency: currentCurrency,
numberOfDecimals: 2, numberOfDecimals: 2,
conversionRate, conversionRate,
}) })
@ -189,7 +191,7 @@ ConfirmDeployContract.prototype.getGasFee = function () {
}) })
return { return {
fiat: Number(USD), fiat: Number(FIAT),
eth: Number(ETH), eth: Number(ETH),
} }
} }
@ -200,7 +202,7 @@ ConfirmDeployContract.prototype.renderGasFee = function () {
h('section.flex-row.flex-center.confirm-screen-row', [ h('section.flex-row.flex-center.confirm-screen-row', [
h('span.confirm-screen-label.confirm-screen-section-column', [ 'Gas Fee' ]), h('span.confirm-screen-label.confirm-screen-section-column', [ 'Gas Fee' ]),
h('div.confirm-screen-section-column', [ h('div.confirm-screen-section-column', [
h('div.confirm-screen-row-info', `$${fiatGas} USD`), h('div.confirm-screen-row-info', `${fiatGas} FIAT`),
h( h(
'div.confirm-screen-row-detail', 'div.confirm-screen-row-detail',
@ -212,6 +214,7 @@ ConfirmDeployContract.prototype.renderGasFee = function () {
} }
ConfirmDeployContract.prototype.renderHeroAmount = function () { ConfirmDeployContract.prototype.renderHeroAmount = function () {
const { currentCurrency } = this.props
const { fiat: fiatAmount } = this.getAmount() const { fiat: fiatAmount } = this.getAmount()
const txMeta = this.gatherTxMeta() const txMeta = this.gatherTxMeta()
const txParams = txMeta.txParams || {} const txParams = txMeta.txParams || {}
@ -219,8 +222,8 @@ ConfirmDeployContract.prototype.renderHeroAmount = function () {
return ( return (
h('div.confirm-send-token__hero-amount-wrapper', [ h('div.confirm-send-token__hero-amount-wrapper', [
h('h3.flex-center.confirm-screen-send-amount', `$${fiatAmount}`), h('h3.flex-center.confirm-screen-send-amount', `${fiatAmount}`),
h('h3.flex-center.confirm-screen-send-amount-currency', 'USD'), h('h3.flex-center.confirm-screen-send-amount-currency', currentCurrency.toUpperCase()),
h('div.flex-center.confirm-memo-wrapper', [ h('div.flex-center.confirm-memo-wrapper', [
h('h3.confirm-screen-send-memo', memo), h('h3.confirm-screen-send-memo', memo),
]), ]),
@ -229,6 +232,7 @@ ConfirmDeployContract.prototype.renderHeroAmount = function () {
} }
ConfirmDeployContract.prototype.renderTotalPlusGas = function () { ConfirmDeployContract.prototype.renderTotalPlusGas = function () {
const { currentCurrency } = this.props
const { fiat: fiatAmount, token: tokenAmount } = this.getAmount() const { fiat: fiatAmount, token: tokenAmount } = this.getAmount()
const { fiat: fiatGas, eth: ethGas } = this.getGasFee() const { fiat: fiatGas, eth: ethGas } = this.getGasFee()
@ -240,7 +244,7 @@ ConfirmDeployContract.prototype.renderTotalPlusGas = function () {
]), ]),
h('div.confirm-screen-section-column', [ h('div.confirm-screen-section-column', [
h('div.confirm-screen-row-info', `$${fiatAmount + fiatGas} USD`), h('div.confirm-screen-row-info', `${fiatAmount + fiatGas} ${currentCurrency.toUpperCase()}`),
h('div.confirm-screen-row-detail', `${tokenAmount + ethGas} ETH`), h('div.confirm-screen-row-detail', `${tokenAmount + ethGas} ETH`),
]), ]),
]) ])

View File

@ -20,6 +20,7 @@ function mapStateToProps (state) {
const { const {
conversionRate, conversionRate,
identities, identities,
currentCurrency,
} = state.metamask } = state.metamask
const accounts = state.metamask.accounts const accounts = state.metamask.accounts
const selectedAddress = state.metamask.selectedAddress || Object.keys(accounts)[0] const selectedAddress = state.metamask.selectedAddress || Object.keys(accounts)[0]
@ -27,6 +28,7 @@ function mapStateToProps (state) {
conversionRate, conversionRate,
identities, identities,
selectedAddress, selectedAddress,
currentCurrency,
} }
} }
@ -45,15 +47,15 @@ function ConfirmSendEther () {
} }
ConfirmSendEther.prototype.getAmount = function () { ConfirmSendEther.prototype.getAmount = function () {
const { conversionRate } = this.props const { conversionRate, currentCurrency } = this.props
const txMeta = this.gatherTxMeta() const txMeta = this.gatherTxMeta()
const txParams = txMeta.txParams || {} const txParams = txMeta.txParams || {}
console.log(txParams) console.log(`conversionRate, currentCurrency`, conversionRate, currentCurrency);
const USD = conversionUtil(txParams.value, { const FIAT = conversionUtil(txParams.value, {
fromNumericBase: 'hex', fromNumericBase: 'hex',
toNumericBase: 'dec', toNumericBase: 'dec',
fromCurrency: 'ETH', fromCurrency: 'ETH',
toCurrency: 'USD', toCurrency: currentCurrency,
numberOfDecimals: 2, numberOfDecimals: 2,
fromDenomination: 'WEI', fromDenomination: 'WEI',
conversionRate, conversionRate,
@ -69,14 +71,14 @@ ConfirmSendEther.prototype.getAmount = function () {
}) })
return { return {
USD, FIAT,
ETH, ETH,
} }
} }
ConfirmSendEther.prototype.getGasFee = function () { ConfirmSendEther.prototype.getGasFee = function () {
const { conversionRate } = this.props const { conversionRate, currentCurrency } = this.props
const txMeta = this.gatherTxMeta() const txMeta = this.gatherTxMeta()
const txParams = txMeta.txParams || {} const txParams = txMeta.txParams || {}
@ -96,12 +98,12 @@ ConfirmSendEther.prototype.getGasFee = function () {
const txFeeBn = gasBn.mul(gasPriceBn) const txFeeBn = gasBn.mul(gasPriceBn)
const USD = conversionUtil(txFeeBn, { const FIAT = conversionUtil(txFeeBn, {
fromNumericBase: 'BN', fromNumericBase: 'BN',
toNumericBase: 'dec', toNumericBase: 'dec',
fromDenomination: 'WEI', fromDenomination: 'WEI',
fromCurrency: 'ETH', fromCurrency: 'ETH',
toCurrency: 'USD', toCurrency: currentCurrency,
numberOfDecimals: 2, numberOfDecimals: 2,
conversionRate, conversionRate,
}) })
@ -116,7 +118,7 @@ ConfirmSendEther.prototype.getGasFee = function () {
}) })
return { return {
USD, FIAT,
ETH, ETH,
} }
} }
@ -125,10 +127,10 @@ ConfirmSendEther.prototype.getData = function () {
const { identities } = this.props const { identities } = this.props
const txMeta = this.gatherTxMeta() const txMeta = this.gatherTxMeta()
const txParams = txMeta.txParams || {} const txParams = txMeta.txParams || {}
const { USD: gasFeeInUSD, ETH: gasFeeInETH } = this.getGasFee() const { FIAT: gasFeeInFIAT, ETH: gasFeeInETH } = this.getGasFee()
const { USD: amountInUSD, ETH: amountInETH } = this.getAmount() const { FIAT: amountInFIAT, ETH: amountInETH } = this.getAmount()
const totalInUSD = addCurrencies(gasFeeInUSD, amountInUSD, { const totalInFIAT = addCurrencies(gasFeeInFIAT, amountInFIAT, {
toNumericBase: 'dec', toNumericBase: 'dec',
numberOfDecimals: 2, numberOfDecimals: 2,
}) })
@ -147,17 +149,17 @@ ConfirmSendEther.prototype.getData = function () {
name: identities[txParams.to] ? identities[txParams.to].name : 'New Recipient', name: identities[txParams.to] ? identities[txParams.to].name : 'New Recipient',
}, },
memo: txParams.memo || '', memo: txParams.memo || '',
gasFeeInUSD, gasFeeInFIAT,
gasFeeInETH, gasFeeInETH,
amountInUSD, amountInFIAT,
amountInETH, amountInETH,
totalInUSD, totalInFIAT,
totalInETH, totalInETH,
} }
} }
ConfirmSendEther.prototype.render = function () { ConfirmSendEther.prototype.render = function () {
const { backToAccountDetail, selectedAddress } = this.props const { backToAccountDetail, selectedAddress, currentCurrency } = this.props
const txMeta = this.gatherTxMeta() const txMeta = this.gatherTxMeta()
const txParams = txMeta.txParams || {} const txParams = txMeta.txParams || {}
@ -171,10 +173,10 @@ ConfirmSendEther.prototype.render = function () {
name: toName, name: toName,
}, },
memo, memo,
gasFeeInUSD, gasFeeInFIAT,
gasFeeInETH, gasFeeInETH,
amountInUSD, amountInFIAT,
totalInUSD, totalInFIAT,
totalInETH, totalInETH,
} = this.getData() } = this.getData()
@ -239,8 +241,8 @@ ConfirmSendEther.prototype.render = function () {
// `You're sending to Recipient ...${toAddress.slice(toAddress.length - 4)}`, // `You're sending to Recipient ...${toAddress.slice(toAddress.length - 4)}`,
// ]), // ]),
h('h3.flex-center.confirm-screen-send-amount', [`$${amountInUSD}`]), h('h3.flex-center.confirm-screen-send-amount', [`$${amountInFIAT}`]),
h('h3.flex-center.confirm-screen-send-amount-currency', [ 'USD' ]), h('h3.flex-center.confirm-screen-send-amount-currency', [ currentCurrency.toUpperCase() ]),
h('div.flex-center.confirm-memo-wrapper', [ h('div.flex-center.confirm-memo-wrapper', [
h('h3.confirm-screen-send-memo', [ memo ? `"${memo}"` : '' ]), h('h3.confirm-screen-send-memo', [ memo ? `"${memo}"` : '' ]),
]), ]),
@ -265,7 +267,7 @@ ConfirmSendEther.prototype.render = function () {
h('section.flex-row.flex-center.confirm-screen-row', [ h('section.flex-row.flex-center.confirm-screen-row', [
h('span.confirm-screen-label.confirm-screen-section-column', [ 'Gas Fee' ]), h('span.confirm-screen-label.confirm-screen-section-column', [ 'Gas Fee' ]),
h('div.confirm-screen-section-column', [ h('div.confirm-screen-section-column', [
h('div.confirm-screen-row-info', `$${gasFeeInUSD} USD`), h('div.confirm-screen-row-info', `${gasFeeInFIAT} ${currentCurrency.toUpperCase()}`),
h('div.confirm-screen-row-detail', `${gasFeeInETH} ETH`), h('div.confirm-screen-row-detail', `${gasFeeInETH} ETH`),
]), ]),
@ -279,7 +281,7 @@ ConfirmSendEther.prototype.render = function () {
]), ]),
h('div.confirm-screen-section-column', [ h('div.confirm-screen-section-column', [
h('div.confirm-screen-row-info', `$${totalInUSD} USD`), h('div.confirm-screen-row-info', `${totalInFIAT} ${currentCurrency.toUpperCase()}`),
h('div.confirm-screen-row-detail', `${totalInETH} ETH`), h('div.confirm-screen-row-detail', `${totalInETH} ETH`),
]), ]),
]), ]),

View File

@ -89,7 +89,7 @@ ConfirmSendToken.prototype.getAmount = function () {
} }
ConfirmSendToken.prototype.getGasFee = function () { ConfirmSendToken.prototype.getGasFee = function () {
const { conversionRate, tokenExchangeRate, token } = this.props const { conversionRate, tokenExchangeRate, token, currentCurrency } = this.props
const txMeta = this.gatherTxMeta() const txMeta = this.gatherTxMeta()
const txParams = txMeta.txParams || {} const txParams = txMeta.txParams || {}
const { decimals } = token const { decimals } = token
@ -101,12 +101,12 @@ ConfirmSendToken.prototype.getGasFee = function () {
multiplierBase: 16, multiplierBase: 16,
}) })
const USD = conversionUtil(gasTotal, { const FIAT = conversionUtil(txFeeBn, {
fromNumericBase: 'BN', fromNumericBase: 'BN',
toNumericBase: 'dec', toNumericBase: 'dec',
fromDenomination: 'WEI', fromDenomination: 'WEI',
fromCurrency: 'ETH', fromCurrency: 'ETH',
toCurrency: 'USD', toCurrency: currentCurrency,
numberOfDecimals: 2, numberOfDecimals: 2,
conversionRate, conversionRate,
}) })
@ -131,7 +131,7 @@ ConfirmSendToken.prototype.getGasFee = function () {
}) })
return { return {
fiat: +Number(USD).toFixed(2), fiat: +Number(FIAT).toFixed(2),
eth: ETH, eth: ETH,
token: tokenExchangeRate token: tokenExchangeRate
? tokenGas ? tokenGas
@ -160,7 +160,7 @@ ConfirmSendToken.prototype.getData = function () {
} }
ConfirmSendToken.prototype.renderHeroAmount = function () { ConfirmSendToken.prototype.renderHeroAmount = function () {
const { token: { symbol } } = this.props const { token: { symbol }, currentCurrency } = this.props
const { fiat: fiatAmount, token: tokenAmount } = this.getAmount() const { fiat: fiatAmount, token: tokenAmount } = this.getAmount()
const txMeta = this.gatherTxMeta() const txMeta = this.gatherTxMeta()
const txParams = txMeta.txParams || {} const txParams = txMeta.txParams || {}
@ -169,8 +169,8 @@ ConfirmSendToken.prototype.renderHeroAmount = function () {
return fiatAmount return fiatAmount
? ( ? (
h('div.confirm-send-token__hero-amount-wrapper', [ h('div.confirm-send-token__hero-amount-wrapper', [
h('h3.flex-center.confirm-screen-send-amount', `$${fiatAmount}`), h('h3.flex-center.confirm-screen-send-amount', `${fiatAmount}`),
h('h3.flex-center.confirm-screen-send-amount-currency', 'USD'), h('h3.flex-center.confirm-screen-send-amount-currency', currentCurrency),
h('div.flex-center.confirm-memo-wrapper', [ h('div.flex-center.confirm-memo-wrapper', [
h('h3.confirm-screen-send-memo', [ memo ? `"${memo}"` : '' ]), h('h3.confirm-screen-send-memo', [ memo ? `"${memo}"` : '' ]),
]), ]),
@ -188,14 +188,14 @@ ConfirmSendToken.prototype.renderHeroAmount = function () {
} }
ConfirmSendToken.prototype.renderGasFee = function () { ConfirmSendToken.prototype.renderGasFee = function () {
const { token: { symbol } } = this.props const { token: { symbol }, currentCurrency } = this.props
const { fiat: fiatGas, token: tokenGas, eth: ethGas } = this.getGasFee() const { fiat: fiatGas, token: tokenGas, eth: ethGas } = this.getGasFee()
return ( return (
h('section.flex-row.flex-center.confirm-screen-row', [ h('section.flex-row.flex-center.confirm-screen-row', [
h('span.confirm-screen-label.confirm-screen-section-column', [ 'Gas Fee' ]), h('span.confirm-screen-label.confirm-screen-section-column', [ 'Gas Fee' ]),
h('div.confirm-screen-section-column', [ h('div.confirm-screen-section-column', [
h('div.confirm-screen-row-info', `$${fiatGas} USD`), h('div.confirm-screen-row-info', `${fiatGas} ${currentCurrency}`),
h( h(
'div.confirm-screen-row-detail', 'div.confirm-screen-row-detail',
@ -207,7 +207,7 @@ ConfirmSendToken.prototype.renderGasFee = function () {
} }
ConfirmSendToken.prototype.renderTotalPlusGas = function () { ConfirmSendToken.prototype.renderTotalPlusGas = function () {
const { token: { symbol } } = this.props const { token: { symbol }, currentCurrency } = this.props
const { fiat: fiatAmount, token: tokenAmount } = this.getAmount() const { fiat: fiatAmount, token: tokenAmount } = this.getAmount()
const { fiat: fiatGas, token: tokenGas } = this.getGasFee() const { fiat: fiatGas, token: tokenGas } = this.getGasFee()
@ -222,8 +222,8 @@ ConfirmSendToken.prototype.renderTotalPlusGas = function () {
]), ]),
h('div.confirm-screen-section-column', [ h('div.confirm-screen-section-column', [
h('div.confirm-screen-row-info', `$${fiatAmount + fiatGas} USD`), h('div.confirm-screen-row-info', `${fiatAmount + fiatGas} ${currentCurrency}`),
h('div.confirm-screen-row-detail', `${tokenTotal} ${symbol}`), h('div.confirm-screen-row-detail', `${tokenAmount + tokenGas} ${symbol}`),
]), ]),
]) ])
) )
@ -236,7 +236,7 @@ ConfirmSendToken.prototype.renderTotalPlusGas = function () {
h('div.confirm-screen-section-column', [ h('div.confirm-screen-section-column', [
h('div.confirm-screen-row-info', `${tokenAmount} ${symbol}`), h('div.confirm-screen-row-info', `${tokenAmount} ${symbol}`),
h('div.confirm-screen-row-detail', `+ ${fiatGas} USD Gas`), h('div.confirm-screen-row-detail', `+ ${fiatGas} ${currentCurrency} Gas`),
]), ]),
]) ])
) )

View File

@ -36,7 +36,6 @@ function mapStateToProps (state) {
function mapDispatchToProps (dispatch) { function mapDispatchToProps (dispatch) {
return { return {
setCurrentCurrencyToUSD: () => dispatch(actions.setCurrentCurrency('usd')),
backToAccountDetail: address => dispatch(actions.backToAccountDetail(address)), backToAccountDetail: address => dispatch(actions.backToAccountDetail(address)),
cancelTransaction: ({ id }) => dispatch(actions.cancelTx({ id })), cancelTransaction: ({ id }) => dispatch(actions.cancelTx({ id })),
} }
@ -58,8 +57,6 @@ PendingTx.prototype.componentWillMount = async function () {
const txMeta = this.gatherTxMeta() const txMeta = this.gatherTxMeta()
const txParams = txMeta.txParams || {} const txParams = txMeta.txParams || {}
this.props.setCurrentCurrencyToUSD()
if (!txParams.to) { if (!txParams.to) {
return this.setState({ return this.setState({
transactionType: TX_TYPES.DEPLOY_CONTRACT, transactionType: TX_TYPES.DEPLOY_CONTRACT,

View File

@ -4,7 +4,7 @@ const inherits = require('util').inherits
const connect = require('react-redux').connect const connect = require('react-redux').connect
const Identicon = require('../identicon') const Identicon = require('../identicon')
const CurrencyDisplay = require('./currency-display') const CurrencyDisplay = require('./currency-display')
const { conversionRateSelector } = require('../../selectors') const { conversionRateSelector, getCurrentCurrency } = require('../../selectors')
inherits(AccountListItem, Component) inherits(AccountListItem, Component)
function AccountListItem () { function AccountListItem () {
@ -13,7 +13,8 @@ function AccountListItem () {
function mapStateToProps(state) { function mapStateToProps(state) {
return { return {
conversionRate: conversionRateSelector(state) conversionRate: conversionRateSelector(state),
currentCurrency: getCurrentCurrency(state),
} }
} }
@ -25,6 +26,7 @@ AccountListItem.prototype.render = function () {
handleClick, handleClick,
icon = null, icon = null,
conversionRate, conversionRate,
currentCurrency,
} = this.props } = this.props
const { name, address, balance } = account const { name, address, balance } = account
@ -52,10 +54,9 @@ AccountListItem.prototype.render = function () {
h(CurrencyDisplay, { h(CurrencyDisplay, {
primaryCurrency: 'ETH', primaryCurrency: 'ETH',
convertedCurrency: 'USD', convertedCurrency: currentCurrency,
value: balance, value: balance,
conversionRate, conversionRate,
convertedPrefix: '$',
readOnly: true, readOnly: true,
className: 'account-list-item__account-balances', className: 'account-list-item__account-balances',
primaryBalanceClassName: 'account-list-item__account-primary-balance', primaryBalanceClassName: 'account-list-item__account-primary-balance',

View File

@ -118,7 +118,7 @@ CurrencyDisplay.prototype.render = function () {
h('div', { h('div', {
className: convertedBalanceClassName, className: convertedBalanceClassName,
}, `${convertedPrefix}${convertedValue} ${convertedCurrency}`), }, `${convertedValue} ${convertedCurrency.toUpperCase()}`),
]) ])

View File

@ -15,6 +15,8 @@ GasFeeDisplay.prototype.render = function () {
conversionRate, conversionRate,
gasTotal, gasTotal,
onClick, onClick,
primaryCurrency = 'ETH',
convertedCurrency,
} = this.props } = this.props
return h('div.send-v2__gas-fee-display', [ return h('div.send-v2__gas-fee-display', [
@ -22,7 +24,7 @@ GasFeeDisplay.prototype.render = function () {
gasTotal gasTotal
? h(CurrencyDisplay, { ? h(CurrencyDisplay, {
primaryCurrency: 'ETH', primaryCurrency: 'ETH',
convertedCurrency: 'USD', convertedCurrency,
value: gasTotal, value: gasTotal,
conversionRate, conversionRate,
convertedPrefix: '$', convertedPrefix: '$',

View File

@ -16,6 +16,7 @@ const {
getGasLimit, getGasLimit,
getAddressBook, getAddressBook,
getSendFrom, getSendFrom,
getCurrentCurrency,
} = require('../../selectors') } = require('../../selectors')
module.exports = connect(mapStateToProps, mapDispatchToProps)(SendEther) module.exports = connect(mapStateToProps, mapDispatchToProps)(SendEther)
@ -30,7 +31,7 @@ function mapStateToProps (state) {
let data; let data;
let primaryCurrency; let primaryCurrency;
let tokenToUSDRate; let tokenToFiatRate;
if (selectedToken) { if (selectedToken) {
data = Array.prototype.map.call( data = Array.prototype.map.call(
abi.rawEncode(['address', 'uint256'], [selectedAddress, '0x0']), abi.rawEncode(['address', 'uint256'], [selectedAddress, '0x0']),
@ -39,7 +40,7 @@ function mapStateToProps (state) {
primaryCurrency = selectedToken.symbol primaryCurrency = selectedToken.symbol
tokenToUSDRate = multiplyCurrencies( tokenToFiatRate = multiplyCurrencies(
conversionRate, conversionRate,
selectedTokenExchangeRate, selectedTokenExchangeRate,
{ toNumericBase: 'dec' } { toNumericBase: 'dec' }
@ -54,8 +55,9 @@ function mapStateToProps (state) {
conversionRate, conversionRate,
selectedToken, selectedToken,
primaryCurrency, primaryCurrency,
convertedCurrency: getCurrentCurrency(state),
data, data,
amountConversionRate: selectedToken ? tokenToUSDRate : conversionRate, amountConversionRate: selectedToken ? tokenToFiatRate : conversionRate,
} }
} }

View File

@ -11,11 +11,14 @@ const Identicon = require('./identicon')
const { conversionUtil } = require('../conversion-util') const { conversionUtil } = require('../conversion-util')
const { getCurrentCurrency } = require('../selectors')
module.exports = connect(mapStateToProps)(TxListItem) module.exports = connect(mapStateToProps)(TxListItem)
function mapStateToProps (state) { function mapStateToProps (state) {
return { return {
tokens: state.metamask.tokens, tokens: state.metamask.tokens,
currentCurrency: getCurrentCurrency(state),
} }
} }
@ -49,17 +52,18 @@ TxListItem.prototype.getSendEtherTotal = function () {
transactionAmount, transactionAmount,
conversionRate, conversionRate,
address, address,
currentCurrency,
} = this.props } = this.props
if (!address) { if (!address) {
return {} return {}
} }
const totalInUSD = conversionUtil(transactionAmount, { const totalInFiat = conversionUtil(transactionAmount, {
fromNumericBase: 'hex', fromNumericBase: 'hex',
toNumericBase: 'dec', toNumericBase: 'dec',
fromCurrency: 'ETH', fromCurrency: 'ETH',
toCurrency: 'USD', toCurrency: currentCurrency,
fromDenomination: 'WEI', fromDenomination: 'WEI',
numberOfDecimals: 2, numberOfDecimals: 2,
conversionRate, conversionRate,
@ -76,7 +80,7 @@ TxListItem.prototype.getSendEtherTotal = function () {
return { return {
total: `${totalInETH} ETH`, total: `${totalInETH} ETH`,
fiatTotal: `$${totalInUSD} USD`, fiatTotal: `${totalInFiat} ${currentCurrency.toUpperCase()}`,
} }
} }

View File

@ -170,6 +170,7 @@ function currentConversionInformation (metamaskState, state) {
}, },
defaultValue: currentCurrency, defaultValue: currentCurrency,
}, infuraCurrencies.map((currency) => { }, infuraCurrencies.map((currency) => {
console.log(`currency`, currency);
return h('option', {key: currency.quote.code, value: currency.quote.code}, `${currency.quote.code.toUpperCase()} - ${currency.quote.name}`) return h('option', {key: currency.quote.code, value: currency.quote.code}, `${currency.quote.code.toUpperCase()} - ${currency.quote.name}`)
}) })
), ),

View File

@ -36,7 +36,7 @@ const BIG_NUMBER_GWEI_MULTIPLIER = new BigNumber('1000000000')
// Individual Setters // Individual Setters
const convert = R.invoker(1, 'times') const convert = R.invoker(1, 'times')
const round = R.invoker(2, 'toFormat')(R.__, BigNumber.ROUND_DOWN) const round = R.invoker(2, 'round')(R.__, BigNumber.ROUND_DOWN)
const invertConversionRate = conversionRate => () => new BigNumber(1.0).div(conversionRate) const invertConversionRate = conversionRate => () => new BigNumber(1.0).div(conversionRate)
// Setter Maps // Setter Maps

View File

@ -15,6 +15,7 @@ const selectors = {
getGasLimit, getGasLimit,
getAddressBook, getAddressBook,
getSendFrom, getSendFrom,
getCurrentCurrency,
} }
module.exports = selectors module.exports = selectors
@ -121,3 +122,7 @@ function getGasLimit (state) {
function getSendFrom (state) { function getSendFrom (state) {
return state.metamask.send.from return state.metamask.send.from
} }
function getCurrentCurrency (state) {
return state.metamask.currentCurrency
}

View File

@ -277,6 +277,7 @@ SendTransactionScreen.prototype.renderAmountRow = function () {
const { const {
selectedToken, selectedToken,
primaryCurrency = 'ETH', primaryCurrency = 'ETH',
convertedCurrency,
amountConversionRate, amountConversionRate,
errors, errors,
} = this.props } = this.props
@ -294,10 +295,9 @@ SendTransactionScreen.prototype.renderAmountRow = function () {
h(CurrencyDisplay, { h(CurrencyDisplay, {
inError: Boolean(errors.amount), inError: Boolean(errors.amount),
primaryCurrency, primaryCurrency,
convertedCurrency: 'USD', convertedCurrency,
value: amount, value: amount,
conversionRate: amountConversionRate, conversionRate: amountConversionRate,
convertedPrefix: '$',
handleChange: this.handleAmountChange, handleChange: this.handleAmountChange,
validate: this.validateAmount, validate: this.validateAmount,
}), }),
@ -309,6 +309,7 @@ SendTransactionScreen.prototype.renderAmountRow = function () {
SendTransactionScreen.prototype.renderGasRow = function () { SendTransactionScreen.prototype.renderGasRow = function () {
const { const {
conversionRate, conversionRate,
convertedCurrency,
showCustomizeGasModal, showCustomizeGasModal,
gasTotal = MIN_GAS_TOTAL, gasTotal = MIN_GAS_TOTAL,
} = this.props } = this.props
@ -322,6 +323,7 @@ SendTransactionScreen.prototype.renderGasRow = function () {
h(GasFeeDisplay, { h(GasFeeDisplay, {
gasTotal, gasTotal,
conversionRate, conversionRate,
convertedCurrency,
onClick: showCustomizeGasModal, onClick: showCustomizeGasModal,
}), }),