From 99acde4fb83bd9df5fe28825006558b1c0c4acbc Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Thu, 25 Oct 2018 14:57:35 +0200 Subject: [PATCH] Remove changes from CurrencyDisplay component --- .../currency-display.container.js | 9 ++++----- .../tests/currency-display.component.test.js | 2 -- .../tests/currency-display.container.test.js | 17 ----------------- .../components/transaction-breakdown/index.js | 2 +- .../transaction-breakdown.component.js | 7 ++++--- .../transaction-breakdown.container.js | 11 +++++++++++ 6 files changed, 20 insertions(+), 28 deletions(-) create mode 100644 ui/app/components/transaction-breakdown/transaction-breakdown.container.js diff --git a/ui/app/components/currency-display/currency-display.container.js b/ui/app/components/currency-display/currency-display.container.js index 60e1487cc49f..1b3fe74dabdd 100644 --- a/ui/app/components/currency-display/currency-display.container.js +++ b/ui/app/components/currency-display/currency-display.container.js @@ -3,17 +3,16 @@ import CurrencyDisplay from './currency-display.component' import { getValueFromWeiHex, formatCurrency } from '../../helpers/confirm-transaction/util' const mapStateToProps = state => { - const { metamask: { nativeCurrency, currentCurrency, conversionRate } } = state + const { metamask: { currentCurrency, conversionRate } } = state return { currentCurrency, conversionRate, - nativeCurrency, } } const mergeProps = (stateProps, dispatchProps, ownProps) => { - const { nativeCurrency, currentCurrency, conversionRate, ...restStateProps } = stateProps + const { currentCurrency, conversionRate, ...restStateProps } = stateProps const { value, numberOfDecimals = 2, @@ -23,9 +22,9 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => { ...restOwnProps } = ownProps - const toCurrency = currency === 'ETH' ? nativeCurrency || currency : currency || currentCurrency + const toCurrency = currency || currentCurrency const convertedValue = getValueFromWeiHex({ - value, nativeCurrency, toCurrency, conversionRate, numberOfDecimals, toDenomination: denomination, + value, toCurrency, conversionRate, numberOfDecimals, toDenomination: denomination, }) const displayValue = formatCurrency(convertedValue, toCurrency) const suffix = hideLabel ? undefined : toCurrency.toUpperCase() diff --git a/ui/app/components/currency-display/tests/currency-display.component.test.js b/ui/app/components/currency-display/tests/currency-display.component.test.js index 56825829c7f1..d9ef052f1bf2 100644 --- a/ui/app/components/currency-display/tests/currency-display.component.test.js +++ b/ui/app/components/currency-display/tests/currency-display.component.test.js @@ -6,7 +6,6 @@ import CurrencyDisplay from '../currency-display.component' describe('CurrencyDisplay Component', () => { it('should render text with a className', () => { const wrapper = shallow() @@ -17,7 +16,6 @@ describe('CurrencyDisplay Component', () => { it('should render text with a prefix', () => { const wrapper = shallow( { metamask: { conversionRate: 280.45, currentCurrency: 'usd', - nativeCurrency: 'ETH', }, } assert.deepEqual(mapStateToProps(mockState), { conversionRate: 280.45, currentCurrency: 'usd', - nativeCurrency: 'ETH', }) }) }) @@ -37,7 +35,6 @@ describe('CurrencyDisplay container', () => { const mockStateProps = { conversionRate: 280.45, currentCurrency: 'usd', - nativeCurrency: 'ETH', } const tests = [ @@ -46,48 +43,40 @@ describe('CurrencyDisplay container', () => { value: '0x2386f26fc10000', numberOfDecimals: 2, currency: 'usd', - nativeCurrency: 'ETH', }, result: { displayValue: '$2.80', suffix: 'USD', - nativeCurrency: 'ETH', }, }, { props: { value: '0x2386f26fc10000', - nativeCurrency: 'ETH', }, result: { displayValue: '$2.80', suffix: 'USD', - nativeCurrency: 'ETH', }, }, { props: { value: '0x1193461d01595930', currency: 'ETH', - nativeCurrency: 'ETH', numberOfDecimals: 3, }, result: { displayValue: '1.266', suffix: 'ETH', - nativeCurrency: 'ETH', }, }, { props: { value: '0x1193461d01595930', currency: 'ETH', - nativeCurrency: 'ETH', numberOfDecimals: 3, hideLabel: true, }, result: { - nativeCurrency: 'ETH', displayValue: '1.266', suffix: undefined, }, @@ -96,12 +85,10 @@ describe('CurrencyDisplay container', () => { props: { value: '0x3b9aca00', currency: 'ETH', - nativeCurrency: 'ETH', denomination: 'GWEI', hideLabel: true, }, result: { - nativeCurrency: 'ETH', displayValue: '1', suffix: undefined, }, @@ -110,12 +97,10 @@ describe('CurrencyDisplay container', () => { props: { value: '0x3b9aca00', currency: 'ETH', - nativeCurrency: 'ETH', denomination: 'WEI', hideLabel: true, }, result: { - nativeCurrency: 'ETH', displayValue: '1000000000', suffix: undefined, }, @@ -124,12 +109,10 @@ describe('CurrencyDisplay container', () => { props: { value: '0x3b9aca00', currency: 'ETH', - nativeCurrency: 'ETH', numberOfDecimals: 100, hideLabel: true, }, result: { - nativeCurrency: 'ETH', displayValue: '1e-9', suffix: undefined, }, diff --git a/ui/app/components/transaction-breakdown/index.js b/ui/app/components/transaction-breakdown/index.js index c887f504f192..4a5b526639c6 100644 --- a/ui/app/components/transaction-breakdown/index.js +++ b/ui/app/components/transaction-breakdown/index.js @@ -1 +1 @@ -export { default } from './transaction-breakdown.component' +export { default } from './transaction-breakdown.container' diff --git a/ui/app/components/transaction-breakdown/transaction-breakdown.component.js b/ui/app/components/transaction-breakdown/transaction-breakdown.component.js index 77bedcad734f..3a76478737d3 100644 --- a/ui/app/components/transaction-breakdown/transaction-breakdown.component.js +++ b/ui/app/components/transaction-breakdown/transaction-breakdown.component.js @@ -6,7 +6,7 @@ import Card from '../card' import CurrencyDisplay from '../currency-display' import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display' import HexToDecimal from '../hex-to-decimal' -import { ETH, GWEI, PRIMARY, SECONDARY } from '../../constants/common' +import { GWEI, PRIMARY, SECONDARY } from '../../constants/common' import { getHexGasTotal } from '../../helpers/confirm-transaction/util' import { sumHexes } from '../../helpers/transactions.util' @@ -18,6 +18,7 @@ export default class TransactionBreakdown extends PureComponent { static propTypes = { transaction: PropTypes.object, className: PropTypes.string, + nativeCurrency: PropTypes.string.isRequired, } static defaultProps = { @@ -26,7 +27,7 @@ export default class TransactionBreakdown extends PureComponent { render () { const { t } = this.context - const { transaction, className } = this.props + const { transaction, className, nativeCurrency } = this.props const { txParams: { gas, gasPrice, value } = {}, txReceipt: { gasUsed } = {} } = transaction const gasLimit = typeof gasUsed === 'string' ? gasUsed : gas @@ -72,7 +73,7 @@ export default class TransactionBreakdown extends PureComponent { { + return { + nativeCurrency: getNativeCurrency(state), + } +} + +export default connect(mapStateToProps)(TransactionBreakdown)