1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

fixed currency-display (#5619)

* call getValueFromWeiHex() with fromCurrency=nativeCurrency
This commit is contained in:
HackyMiner 2018-10-30 20:15:38 +09:00 committed by Whymarrh Whitby
parent 73eeeda215
commit ac079365e6
2 changed files with 22 additions and 3 deletions

View File

@ -3,16 +3,17 @@ import CurrencyDisplay from './currency-display.component'
import { getValueFromWeiHex, formatCurrency } from '../../helpers/confirm-transaction/util' import { getValueFromWeiHex, formatCurrency } from '../../helpers/confirm-transaction/util'
const mapStateToProps = state => { const mapStateToProps = state => {
const { metamask: { currentCurrency, conversionRate } } = state const { metamask: { nativeCurrency, currentCurrency, conversionRate } } = state
return { return {
currentCurrency, currentCurrency,
conversionRate, conversionRate,
nativeCurrency,
} }
} }
const mergeProps = (stateProps, dispatchProps, ownProps) => { const mergeProps = (stateProps, dispatchProps, ownProps) => {
const { currentCurrency, conversionRate, ...restStateProps } = stateProps const { nativeCurrency, currentCurrency, conversionRate, ...restStateProps } = stateProps
const { const {
value, value,
numberOfDecimals = 2, numberOfDecimals = 2,
@ -24,7 +25,7 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => {
const toCurrency = currency || currentCurrency const toCurrency = currency || currentCurrency
const convertedValue = getValueFromWeiHex({ const convertedValue = getValueFromWeiHex({
value, toCurrency, conversionRate, numberOfDecimals, toDenomination: denomination, value, fromCurrency: nativeCurrency, toCurrency, conversionRate, numberOfDecimals, toDenomination: denomination,
}) })
const displayValue = formatCurrency(convertedValue, toCurrency) const displayValue = formatCurrency(convertedValue, toCurrency)
const suffix = hideLabel ? undefined : toCurrency.toUpperCase() const suffix = hideLabel ? undefined : toCurrency.toUpperCase()

View File

@ -20,12 +20,14 @@ describe('CurrencyDisplay container', () => {
metamask: { metamask: {
conversionRate: 280.45, conversionRate: 280.45,
currentCurrency: 'usd', currentCurrency: 'usd',
nativeCurrency: 'ETH',
}, },
} }
assert.deepEqual(mapStateToProps(mockState), { assert.deepEqual(mapStateToProps(mockState), {
conversionRate: 280.45, conversionRate: 280.45,
currentCurrency: 'usd', currentCurrency: 'usd',
nativeCurrency: 'ETH',
}) })
}) })
}) })
@ -35,6 +37,7 @@ describe('CurrencyDisplay container', () => {
const mockStateProps = { const mockStateProps = {
conversionRate: 280.45, conversionRate: 280.45,
currentCurrency: 'usd', currentCurrency: 'usd',
nativeCurrency: 'ETH',
} }
const tests = [ const tests = [
@ -43,40 +46,49 @@ describe('CurrencyDisplay container', () => {
value: '0x2386f26fc10000', value: '0x2386f26fc10000',
numberOfDecimals: 2, numberOfDecimals: 2,
currency: 'usd', currency: 'usd',
nativeCurrency: 'ETH',
}, },
result: { result: {
displayValue: '$2.80', displayValue: '$2.80',
suffix: 'USD', suffix: 'USD',
nativeCurrency: 'ETH',
}, },
}, },
{ {
props: { props: {
value: '0x2386f26fc10000', value: '0x2386f26fc10000',
currency: 'usd',
nativeCurrency: 'ETH',
}, },
result: { result: {
displayValue: '$2.80', displayValue: '$2.80',
suffix: 'USD', suffix: 'USD',
nativeCurrency: 'ETH',
}, },
}, },
{ {
props: { props: {
value: '0x1193461d01595930', value: '0x1193461d01595930',
currency: 'ETH', currency: 'ETH',
nativeCurrency: 'ETH',
numberOfDecimals: 3, numberOfDecimals: 3,
}, },
result: { result: {
displayValue: '1.266', displayValue: '1.266',
suffix: 'ETH', suffix: 'ETH',
nativeCurrency: 'ETH',
}, },
}, },
{ {
props: { props: {
value: '0x1193461d01595930', value: '0x1193461d01595930',
currency: 'ETH', currency: 'ETH',
nativeCurrency: 'ETH',
numberOfDecimals: 3, numberOfDecimals: 3,
hideLabel: true, hideLabel: true,
}, },
result: { result: {
nativeCurrency: 'ETH',
displayValue: '1.266', displayValue: '1.266',
suffix: undefined, suffix: undefined,
}, },
@ -85,10 +97,12 @@ describe('CurrencyDisplay container', () => {
props: { props: {
value: '0x3b9aca00', value: '0x3b9aca00',
currency: 'ETH', currency: 'ETH',
nativeCurrency: 'ETH',
denomination: 'GWEI', denomination: 'GWEI',
hideLabel: true, hideLabel: true,
}, },
result: { result: {
nativeCurrency: 'ETH',
displayValue: '1', displayValue: '1',
suffix: undefined, suffix: undefined,
}, },
@ -97,10 +111,12 @@ describe('CurrencyDisplay container', () => {
props: { props: {
value: '0x3b9aca00', value: '0x3b9aca00',
currency: 'ETH', currency: 'ETH',
nativeCurrency: 'ETH',
denomination: 'WEI', denomination: 'WEI',
hideLabel: true, hideLabel: true,
}, },
result: { result: {
nativeCurrency: 'ETH',
displayValue: '1000000000', displayValue: '1000000000',
suffix: undefined, suffix: undefined,
}, },
@ -109,10 +125,12 @@ describe('CurrencyDisplay container', () => {
props: { props: {
value: '0x3b9aca00', value: '0x3b9aca00',
currency: 'ETH', currency: 'ETH',
nativeCurrency: 'ETH',
numberOfDecimals: 100, numberOfDecimals: 100,
hideLabel: true, hideLabel: true,
}, },
result: { result: {
nativeCurrency: 'ETH',
displayValue: '1e-9', displayValue: '1e-9',
suffix: undefined, suffix: undefined,
}, },