From 47c4508cfbe125fa067514718cb40a8f4aed5cc0 Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Thu, 25 Oct 2018 12:32:28 +0200 Subject: [PATCH] Rename fromCurrency to nativeCurrency in CurrencyController --- app/scripts/controllers/currency.js | 32 +++++++++-------- app/scripts/metamask-controller.js | 8 ++--- test/data/mock-state.json | 2 +- ui/app/components/balance-component.js | 8 ++--- .../currency-display.container.js | 10 +++--- .../tests/currency-display.component.test.js | 4 +-- .../tests/currency-display.container.test.js | 34 +++++++++---------- .../currency-input.container.js | 8 ++--- .../tests/currency-input.component.test.js | 24 ++++++------- .../tests/currency-input.container.test.js | 10 +++--- .../account-list-item.container.js | 4 +-- .../tests/account-list-item-component.test.js | 2 +- .../tests/account-list-item-container.test.js | 4 +-- ui/app/components/send/send.selectors.js | 6 ++-- .../send/tests/send-selectors-test-data.js | 1 + .../send/tests/send-selectors.test.js | 6 ++-- ...transaction-activity-log.container.test.js | 4 +-- .../transaction-activity-log.component.js | 12 +++---- .../transaction-activity-log.container.js | 4 +-- .../transaction-view-balance.container.js | 4 +-- ...erenced-currency-display.container.test.js | 20 +++++------ ...-preferenced-currency-display.component.js | 2 +- ...-preferenced-currency-display.container.js | 8 ++--- ui/app/ducks/confirm-transaction.duck.js | 14 ++++---- ui/app/selectors.js | 6 ++-- ui/app/selectors/confirm-transaction.js | 2 +- 26 files changed, 122 insertions(+), 117 deletions(-) diff --git a/app/scripts/controllers/currency.js b/app/scripts/controllers/currency.js index 661136296df6..1e866d2c93d7 100644 --- a/app/scripts/controllers/currency.js +++ b/app/scripts/controllers/currency.js @@ -21,14 +21,15 @@ class CurrencyController { * since midnight of January 1, 1970 * @property {number} conversionInterval The id of the interval created by the scheduleConversionInterval method. * Used to clear an existing interval on subsequent calls of that method. + * @property {string} nativeCurrency The ticker/symbol of the native chain currency * */ constructor (opts = {}) { const initState = extend({ - fromCurrency: 'ETH', currentCurrency: 'usd', conversionRate: 0, conversionDate: 'N/A', + nativeCurrency: 'ETH', }, opts.initState) this.store = new ObservableStore(initState) } @@ -38,23 +39,26 @@ class CurrencyController { // /** - * A getter for the fromCurrency property + * A getter for the nativeCurrency property * * @returns {string} A 2-4 character shorthand that describes the specific currency * */ - getFromCurrency () { - return this.store.getState().fromCurrency + getNativeCurrency () { + return this.store.getState().nativeCurrency } /** - * A setter for the fromCurrency property + * A setter for the nativeCurrency property * - * @param {string} fromCurrency The new currency to set as the fromCurrency in the store + * @param {string} nativeCurrency The new currency to set as the nativeCurrency in the store * */ - setFromCurrency (fromCurrency) { - this.store.updateState({ ticker: fromCurrency, fromCurrency }) + setNativeCurrency (nativeCurrency) { + this.store.updateState({ + nativeCurrency, + ticker: nativeCurrency, + }) } /** @@ -125,19 +129,19 @@ class CurrencyController { * */ async updateConversionRate () { - let currentCurrency, fromCurrency + let currentCurrency, nativeCurrency try { currentCurrency = this.getCurrentCurrency() - fromCurrency = this.getFromCurrency() + nativeCurrency = this.getNativeCurrency() let apiUrl - if (fromCurrency === 'ETH') { + if (nativeCurrency === 'ETH') { apiUrl = `https://api.infura.io/v1/ticker/eth${currentCurrency.toLowerCase()}` } else { - apiUrl = `https://min-api.cryptocompare.com/data/price?fsym=${fromCurrency.toUpperCase()}&tsyms=${currentCurrency.toUpperCase()}` + apiUrl = `https://min-api.cryptocompare.com/data/price?fsym=${nativeCurrency.toUpperCase()}&tsyms=${currentCurrency.toUpperCase()}` } const response = await fetch(apiUrl) const parsedResponse = await response.json() - if (fromCurrency === 'ETH') { + if (nativeCurrency === 'ETH') { this.setConversionRate(Number(parsedResponse.bid)) this.setConversionDate(Number(parsedResponse.timestamp)) } else { @@ -150,7 +154,7 @@ class CurrencyController { } } } catch (err) { - log.warn(`MetaMask - Failed to query currency conversion:`, fromCurrency, currentCurrency, err) + log.warn(`MetaMask - Failed to query currency conversion:`, nativeCurrency, currentCurrency, err) this.setConversionRate(0) this.setConversionDate('N/A') } diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index fc238e4e3e6a..3778dbdb6753 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -138,12 +138,12 @@ module.exports = class MetamaskController extends EventEmitter { this.accountTracker.stop() } }) - + // ensure accountTracker updates balances after network change this.networkController.on('networkDidChange', () => { this.accountTracker._updateAccounts() }) - + // key mgmt const additionalKeyrings = [TrezorKeyring, LedgerBridgeKeyring] this.keyringController = new KeyringController({ @@ -1416,11 +1416,11 @@ module.exports = class MetamaskController extends EventEmitter { setCurrentCurrency (currencyCode, cb) { const { ticker } = this.networkController.getNetworkConfig() try { - this.currencyController.setFromCurrency(ticker) + this.currencyController.setNativeCurrency(ticker) this.currencyController.setCurrentCurrency(currencyCode) this.currencyController.updateConversionRate() const data = { - fromCurrency: ticker || 'ETH', + nativeCurrency: ticker || 'ETH', conversionRate: this.currencyController.getConversionRate(), currentCurrency: this.currencyController.getCurrentCurrency(), conversionDate: this.currencyController.getConversionDate(), diff --git a/test/data/mock-state.json b/test/data/mock-state.json index 454c5f09ef77..8deff5531265 100644 --- a/test/data/mock-state.json +++ b/test/data/mock-state.json @@ -113,7 +113,7 @@ }, "ticker": "ETH", "currentCurrency": "usd", - "fromCurrency": "ETH", + "nativeCurrency": "ETH", "conversionRate": 556.12, "addressBook": [ { diff --git a/ui/app/components/balance-component.js b/ui/app/components/balance-component.js index 4945103fd640..cd03539618c1 100644 --- a/ui/app/components/balance-component.js +++ b/ui/app/components/balance-component.js @@ -6,7 +6,7 @@ const TokenBalance = require('./token-balance') const Identicon = require('./identicon') import UserPreferencedCurrencyDisplay from './user-preferenced-currency-display' import { PRIMARY, SECONDARY } from '../constants/common' -const { getFromCurrency, getAssetImages, conversionRateSelector, getCurrentCurrency} = require('../selectors') +const { getNativeCurrency, getAssetImages, conversionRateSelector, getCurrentCurrency} = require('../selectors') const { formatBalance } = require('../util') @@ -21,7 +21,7 @@ function mapStateToProps (state) { return { account, network, - fromCurrency: getFromCurrency(state), + nativeCurrency: getNativeCurrency(state), conversionRate: conversionRateSelector(state), currentCurrency: getCurrentCurrency(state), assetImages: getAssetImages(state), @@ -67,10 +67,10 @@ BalanceComponent.prototype.renderTokenBalance = function () { BalanceComponent.prototype.renderBalance = function () { const props = this.props - const { account, fromCurrency } = props + const { account, nativeCurrency } = props const balanceValue = account && account.balance const needsParse = 'needsParse' in props ? props.needsParse : true - const formattedBalance = balanceValue ? formatBalance(balanceValue, 6, needsParse, fromCurrency) : '...' + const formattedBalance = balanceValue ? formatBalance(balanceValue, 6, needsParse, nativeCurrency) : '...' const showFiat = 'showFiat' in props ? props.showFiat : true if (formattedBalance === 'None' || formattedBalance === '...') { diff --git a/ui/app/components/currency-display/currency-display.container.js b/ui/app/components/currency-display/currency-display.container.js index 3852985dbe93..60e1487cc49f 100644 --- a/ui/app/components/currency-display/currency-display.container.js +++ b/ui/app/components/currency-display/currency-display.container.js @@ -3,17 +3,17 @@ import CurrencyDisplay from './currency-display.component' import { getValueFromWeiHex, formatCurrency } from '../../helpers/confirm-transaction/util' const mapStateToProps = state => { - const { metamask: { fromCurrency, currentCurrency, conversionRate } } = state + const { metamask: { nativeCurrency, currentCurrency, conversionRate } } = state return { currentCurrency, conversionRate, - fromCurrency, + nativeCurrency, } } const mergeProps = (stateProps, dispatchProps, ownProps) => { - const { fromCurrency, currentCurrency, conversionRate, ...restStateProps } = stateProps + const { nativeCurrency, currentCurrency, conversionRate, ...restStateProps } = stateProps const { value, numberOfDecimals = 2, @@ -23,9 +23,9 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => { ...restOwnProps } = ownProps - const toCurrency = currency === 'ETH' ? fromCurrency || currency : currency || currentCurrency + const toCurrency = currency === 'ETH' ? nativeCurrency || currency : currency || currentCurrency const convertedValue = getValueFromWeiHex({ - value, fromCurrency, toCurrency, conversionRate, numberOfDecimals, toDenomination: denomination, + value, nativeCurrency, 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 2fbc6bd08d1f..56825829c7f1 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,7 @@ import CurrencyDisplay from '../currency-display.component' describe('CurrencyDisplay Component', () => { it('should render text with a className', () => { const wrapper = shallow() @@ -17,7 +17,7 @@ describe('CurrencyDisplay Component', () => { it('should render text with a prefix', () => { const wrapper = shallow( { metamask: { conversionRate: 280.45, currentCurrency: 'usd', - fromCurrency: 'ETH', + nativeCurrency: 'ETH', }, } assert.deepEqual(mapStateToProps(mockState), { conversionRate: 280.45, currentCurrency: 'usd', - fromCurrency: 'ETH', + nativeCurrency: 'ETH', }) }) }) @@ -37,7 +37,7 @@ describe('CurrencyDisplay container', () => { const mockStateProps = { conversionRate: 280.45, currentCurrency: 'usd', - fromCurrency: 'ETH', + nativeCurrency: 'ETH', } const tests = [ @@ -46,48 +46,48 @@ describe('CurrencyDisplay container', () => { value: '0x2386f26fc10000', numberOfDecimals: 2, currency: 'usd', - fromCurrency: 'ETH', + nativeCurrency: 'ETH', }, result: { displayValue: '$2.80', suffix: 'USD', - fromCurrency: 'ETH', + nativeCurrency: 'ETH', }, }, { props: { value: '0x2386f26fc10000', - fromCurrency: 'ETH', + nativeCurrency: 'ETH', }, result: { displayValue: '$2.80', suffix: 'USD', - fromCurrency: 'ETH', + nativeCurrency: 'ETH', }, }, { props: { value: '0x1193461d01595930', currency: 'ETH', - fromCurrency: 'ETH', + nativeCurrency: 'ETH', numberOfDecimals: 3, }, result: { displayValue: '1.266', suffix: 'ETH', - fromCurrency: 'ETH', + nativeCurrency: 'ETH', }, }, { props: { value: '0x1193461d01595930', currency: 'ETH', - fromCurrency: 'ETH', + nativeCurrency: 'ETH', numberOfDecimals: 3, hideLabel: true, }, result: { - fromCurrency: 'ETH', + nativeCurrency: 'ETH', displayValue: '1.266', suffix: undefined, }, @@ -96,12 +96,12 @@ describe('CurrencyDisplay container', () => { props: { value: '0x3b9aca00', currency: 'ETH', - fromCurrency: 'ETH', + nativeCurrency: 'ETH', denomination: 'GWEI', hideLabel: true, }, result: { - fromCurrency: 'ETH', + nativeCurrency: 'ETH', displayValue: '1', suffix: undefined, }, @@ -110,12 +110,12 @@ describe('CurrencyDisplay container', () => { props: { value: '0x3b9aca00', currency: 'ETH', - fromCurrency: 'ETH', + nativeCurrency: 'ETH', denomination: 'WEI', hideLabel: true, }, result: { - fromCurrency: 'ETH', + nativeCurrency: 'ETH', displayValue: '1000000000', suffix: undefined, }, @@ -124,12 +124,12 @@ describe('CurrencyDisplay container', () => { props: { value: '0x3b9aca00', currency: 'ETH', - fromCurrency: 'ETH', + nativeCurrency: 'ETH', numberOfDecimals: 100, hideLabel: true, }, result: { - fromCurrency: 'ETH', + nativeCurrency: 'ETH', displayValue: '1e-9', suffix: undefined, }, diff --git a/ui/app/components/currency-input/currency-input.container.js b/ui/app/components/currency-input/currency-input.container.js index ad88b30c4c74..1d1ed7b41597 100644 --- a/ui/app/components/currency-input/currency-input.container.js +++ b/ui/app/components/currency-input/currency-input.container.js @@ -3,19 +3,19 @@ import CurrencyInput from './currency-input.component' import { ETH } from '../../constants/common' const mapStateToProps = state => { - const { metamask: { fromCurrency, currentCurrency, conversionRate } } = state + const { metamask: { nativeCurrency, currentCurrency, conversionRate } } = state return { - fromCurrency, + nativeCurrency, currentCurrency, conversionRate, } } const mergeProps = (stateProps, dispatchProps, ownProps) => { - const { fromCurrency, currentCurrency } = stateProps + const { nativeCurrency, currentCurrency } = stateProps const { useFiat } = ownProps - const suffix = useFiat ? currentCurrency.toUpperCase() : fromCurrency || ETH + const suffix = useFiat ? currentCurrency.toUpperCase() : nativeCurrency || ETH return { ...stateProps, diff --git a/ui/app/components/currency-input/tests/currency-input.component.test.js b/ui/app/components/currency-input/tests/currency-input.component.test.js index d774801df5a3..a33889f94a31 100644 --- a/ui/app/components/currency-input/tests/currency-input.component.test.js +++ b/ui/app/components/currency-input/tests/currency-input.component.test.js @@ -22,7 +22,7 @@ describe('CurrencyInput Component', () => { it('should render properly with a suffix', () => { const mockStore = { metamask: { - fromCurrency: 'ETH', + nativeCurrency: 'ETH', currentCurrency: 'usd', conversionRate: 231.06, }, @@ -33,7 +33,7 @@ describe('CurrencyInput Component', () => { ) @@ -47,7 +47,7 @@ describe('CurrencyInput Component', () => { it('should render properly with an ETH value', () => { const mockStore = { metamask: { - fromCurrency: 'ETH', + nativeCurrency: 'ETH', currentCurrency: 'usd', conversionRate: 231.06, }, @@ -59,7 +59,7 @@ describe('CurrencyInput Component', () => { @@ -79,7 +79,7 @@ describe('CurrencyInput Component', () => { it('should render properly with a fiat value', () => { const mockStore = { metamask: { - fromCurrency: 'ETH', + nativeCurrency: 'ETH', currentCurrency: 'usd', conversionRate: 231.06, }, @@ -92,7 +92,7 @@ describe('CurrencyInput Component', () => { value="f602f2234d0ea" suffix="USD" useFiat - fromCurrency="ETH" + nativeCurrency="ETH" currentCurrency="usd" conversionRate={231.06} /> @@ -122,7 +122,7 @@ describe('CurrencyInput Component', () => { it('should call onChange and onBlur on input changes with the hex value for ETH', () => { const mockStore = { metamask: { - fromCurrency: 'ETH', + nativeCurrency: 'ETH', currentCurrency: 'usd', conversionRate: 231.06, }, @@ -134,7 +134,7 @@ describe('CurrencyInput Component', () => { onChange={handleChangeSpy} onBlur={handleBlurSpy} suffix="ETH" - fromCurrency="ETH" + nativeCurrency="ETH" currentCurrency="usd" conversionRate={231.06} /> @@ -168,7 +168,7 @@ describe('CurrencyInput Component', () => { it('should call onChange and onBlur on input changes with the hex value for fiat', () => { const mockStore = { metamask: { - fromCurrency: 'ETH', + nativeCurrency: 'ETH', currentCurrency: 'usd', conversionRate: 231.06, }, @@ -180,7 +180,7 @@ describe('CurrencyInput Component', () => { onChange={handleChangeSpy} onBlur={handleBlurSpy} suffix="USD" - fromCurrency="ETH" + nativeCurrency="ETH" currentCurrency="usd" conversionRate={231.06} useFiat @@ -215,7 +215,7 @@ describe('CurrencyInput Component', () => { it('should change the state and pass in a new decimalValue when props.value changes', () => { const mockStore = { metamask: { - fromCurrency: 'ETH', + nativeCurrency: 'ETH', currentCurrency: 'usd', conversionRate: 231.06, }, @@ -227,7 +227,7 @@ describe('CurrencyInput Component', () => { onChange={handleChangeSpy} onBlur={handleBlurSpy} suffix="USD" - fromCurrency="ETH" + nativeCurrency="ETH" currentCurrency="usd" conversionRate={231.06} useFiat diff --git a/ui/app/components/currency-input/tests/currency-input.container.test.js b/ui/app/components/currency-input/tests/currency-input.container.test.js index 902c18571c62..5d72958e6549 100644 --- a/ui/app/components/currency-input/tests/currency-input.container.test.js +++ b/ui/app/components/currency-input/tests/currency-input.container.test.js @@ -20,14 +20,14 @@ describe('CurrencyInput container', () => { metamask: { conversionRate: 280.45, currentCurrency: 'usd', - fromCurrency: 'ETH', + nativeCurrency: 'ETH', }, } assert.deepEqual(mapStateToProps(mockState), { conversionRate: 280.45, currentCurrency: 'usd', - fromCurrency: 'ETH', + nativeCurrency: 'ETH', }) }) }) @@ -37,14 +37,14 @@ describe('CurrencyInput container', () => { const mockStateProps = { conversionRate: 280.45, currentCurrency: 'usd', - fromCurrency: 'ETH', + nativeCurrency: 'ETH', } const mockDispatchProps = {} assert.deepEqual(mergeProps(mockStateProps, mockDispatchProps, { useFiat: true }), { conversionRate: 280.45, currentCurrency: 'usd', - fromCurrency: 'ETH', + nativeCurrency: 'ETH', useFiat: true, suffix: 'USD', }) @@ -52,7 +52,7 @@ describe('CurrencyInput container', () => { assert.deepEqual(mergeProps(mockStateProps, mockDispatchProps, {}), { conversionRate: 280.45, currentCurrency: 'usd', - fromCurrency: 'ETH', + nativeCurrency: 'ETH', suffix: 'ETH', }) }) diff --git a/ui/app/components/send/account-list-item/account-list-item.container.js b/ui/app/components/send/account-list-item/account-list-item.container.js index 9e59e3ee04e4..f8e73d923305 100644 --- a/ui/app/components/send/account-list-item/account-list-item.container.js +++ b/ui/app/components/send/account-list-item/account-list-item.container.js @@ -2,7 +2,7 @@ import { connect } from 'react-redux' import { getConversionRate, getCurrentCurrency, - getFromCurrency, + getNativeCurrency, } from '../send.selectors.js' import AccountListItem from './account-list-item.component' @@ -12,6 +12,6 @@ function mapStateToProps (state) { return { conversionRate: getConversionRate(state), currentCurrency: getCurrentCurrency(state), - fromCurrency: getFromCurrency(state), + nativeCurrency: getNativeCurrency(state), } } diff --git a/ui/app/components/send/account-list-item/tests/account-list-item-component.test.js b/ui/app/components/send/account-list-item/tests/account-list-item-component.test.js index 018894b61b62..6ffc0b1c6795 100644 --- a/ui/app/components/send/account-list-item/tests/account-list-item-component.test.js +++ b/ui/app/components/send/account-list-item/tests/account-list-item-component.test.js @@ -28,7 +28,7 @@ describe('AccountListItem Component', function () { className={'mockClassName'} conversionRate={4} currentCurrency={'mockCurrentyCurrency'} - fromCurrency={'ETH'} + nativeCurrency={'ETH'} displayAddress={false} displayBalance={false} handleClick={propsMethodSpies.handleClick} diff --git a/ui/app/components/send/account-list-item/tests/account-list-item-container.test.js b/ui/app/components/send/account-list-item/tests/account-list-item-container.test.js index 0b4051e91a21..7c2f5fcb258d 100644 --- a/ui/app/components/send/account-list-item/tests/account-list-item-container.test.js +++ b/ui/app/components/send/account-list-item/tests/account-list-item-container.test.js @@ -13,7 +13,7 @@ proxyquire('../account-list-item.container.js', { '../send.selectors.js': { getConversionRate: (s) => `mockConversionRate:${s}`, getCurrentCurrency: (s) => `mockCurrentCurrency:${s}`, - getFromCurrency: (s) => `mockFromCurrency:${s}`, + getNativeCurrency: (s) => `mockNativeCurrency:${s}`, }, }) @@ -25,7 +25,7 @@ describe('account-list-item container', () => { assert.deepEqual(mapStateToProps('mockState'), { conversionRate: 'mockConversionRate:mockState', currentCurrency: 'mockCurrentCurrency:mockState', - fromCurrency: 'mockFromCurrency:mockState', + nativeCurrency: 'mockNativeCurrency:mockState', }) }) diff --git a/ui/app/components/send/send.selectors.js b/ui/app/components/send/send.selectors.js index 1cff9eaf8ccf..eb22a08b7337 100644 --- a/ui/app/components/send/send.selectors.js +++ b/ui/app/components/send/send.selectors.js @@ -19,7 +19,7 @@ const selectors = { getCurrentNetwork, getCurrentViewContext, getForceGasMin, - getFromCurrency, + getNativeCurrency, getGasLimit, getGasPrice, getGasPriceFromRecentBlocks, @@ -112,8 +112,8 @@ function getCurrentCurrency (state) { return state.metamask.currentCurrency } -function getFromCurrency (state) { - return state.metamask.fromCurrency || 'ETH' +function getNativeCurrency (state) { + return state.metamask.nativeCurrency } function getCurrentNetwork (state) { diff --git a/ui/app/components/send/tests/send-selectors-test-data.js b/ui/app/components/send/tests/send-selectors-test-data.js index 8b939dadbf00..30a2666cf1c3 100644 --- a/ui/app/components/send/tests/send-selectors-test-data.js +++ b/ui/app/components/send/tests/send-selectors-test-data.js @@ -26,6 +26,7 @@ module.exports = { 'currentCurrency': 'USD', 'conversionRate': 1200.88200327, 'conversionDate': 1489013762, + 'nativeCurrency': 'ETH', 'noActiveNotices': true, 'frequentRpcList': [], 'network': '3', diff --git a/ui/app/components/send/tests/send-selectors.test.js b/ui/app/components/send/tests/send-selectors.test.js index 6a5ef2f531fa..e7e901f0d431 100644 --- a/ui/app/components/send/tests/send-selectors.test.js +++ b/ui/app/components/send/tests/send-selectors.test.js @@ -12,7 +12,7 @@ const { getCurrentCurrency, getCurrentNetwork, getCurrentViewContext, - getFromCurrency, + getNativeCurrency, getForceGasMin, getGasLimit, getGasPrice, @@ -179,10 +179,10 @@ describe('send selectors', () => { }) }) - describe('getFromCurrency()', () => { + describe('getNativeCurrency()', () => { it('should return the ticker symbol of the selected network', () => { assert.equal( - getFromCurrency(mockState), + getNativeCurrency(mockState), 'ETH' ) }) diff --git a/ui/app/components/transaction-activity-log/tests/transaction-activity-log.container.test.js b/ui/app/components/transaction-activity-log/tests/transaction-activity-log.container.test.js index c81944732635..a7c35f51ecda 100644 --- a/ui/app/components/transaction-activity-log/tests/transaction-activity-log.container.test.js +++ b/ui/app/components/transaction-activity-log/tests/transaction-activity-log.container.test.js @@ -18,11 +18,11 @@ describe('TransactionActivityLog container', () => { const mockState = { metamask: { conversionRate: 280.45, - fromCurrency: 'ETH', + nativeCurrency: 'ETH', }, } - assert.deepEqual(mapStateToProps(mockState), { conversionRate: 280.45, fromCurrency: 'ETH' }) + assert.deepEqual(mapStateToProps(mockState), { conversionRate: 280.45, nativeCurrency: 'ETH' }) }) }) }) diff --git a/ui/app/components/transaction-activity-log/transaction-activity-log.component.js b/ui/app/components/transaction-activity-log/transaction-activity-log.component.js index 85c0e4d9c7e4..357ef626c767 100644 --- a/ui/app/components/transaction-activity-log/transaction-activity-log.component.js +++ b/ui/app/components/transaction-activity-log/transaction-activity-log.component.js @@ -15,7 +15,7 @@ export default class TransactionActivityLog extends PureComponent { transaction: PropTypes.object, className: PropTypes.string, conversionRate: PropTypes.number, - fromCurrency: PropTypes.string, + nativeCurrency: PropTypes.string, } state = { @@ -41,17 +41,17 @@ export default class TransactionActivityLog extends PureComponent { } renderActivity (activity, index) { - const { conversionRate, fromCurrency } = this.props + const { conversionRate, nativeCurrency } = this.props const { eventKey, value, timestamp } = activity const ethValue = index === 0 ? `${getValueFromWeiHex({ value, - fromCurrency, - toCurrency: fromCurrency, + nativeCurrency, + toCurrency: nativeCurrency, conversionRate, numberOfDecimals: 6, - })} ${fromCurrency}` - : getEthConversionFromWeiHex({ value, fromCurrency, toCurrency: fromCurrency, conversionRate }) + })} ${nativeCurrency}` + : getEthConversionFromWeiHex({ value, nativeCurrency, toCurrency: nativeCurrency, conversionRate }) const formattedTimestamp = formatDate(timestamp) const activityText = this.context.t(eventKey, [ethValue, formattedTimestamp]) diff --git a/ui/app/components/transaction-activity-log/transaction-activity-log.container.js b/ui/app/components/transaction-activity-log/transaction-activity-log.container.js index 83e354c7c460..622f77df1312 100644 --- a/ui/app/components/transaction-activity-log/transaction-activity-log.container.js +++ b/ui/app/components/transaction-activity-log/transaction-activity-log.container.js @@ -1,11 +1,11 @@ import { connect } from 'react-redux' import TransactionActivityLog from './transaction-activity-log.component' -import { conversionRateSelector, getFromCurrency } from '../../selectors' +import { conversionRateSelector, getNativeCurrency } from '../../selectors' const mapStateToProps = state => { return { conversionRate: conversionRateSelector(state), - fromCurrency: getFromCurrency(state), + nativeCurrency: getNativeCurrency(state), } } diff --git a/ui/app/components/transaction-view-balance/transaction-view-balance.container.js b/ui/app/components/transaction-view-balance/transaction-view-balance.container.js index 24b4ddd16f30..cb8078ec1dd0 100644 --- a/ui/app/components/transaction-view-balance/transaction-view-balance.container.js +++ b/ui/app/components/transaction-view-balance/transaction-view-balance.container.js @@ -2,7 +2,7 @@ import { connect } from 'react-redux' import { withRouter } from 'react-router-dom' import { compose } from 'recompose' import TransactionViewBalance from './transaction-view-balance.component' -import { getSelectedToken, getSelectedAddress, getFromCurrency, getSelectedTokenAssetImage } from '../../selectors' +import { getSelectedToken, getSelectedAddress, getNativeCurrency, getSelectedTokenAssetImage } from '../../selectors' import { showModal } from '../../actions' const mapStateToProps = state => { @@ -15,7 +15,7 @@ const mapStateToProps = state => { selectedToken: getSelectedToken(state), network, balance, - fromCurrency: getFromCurrency(state), + nativeCurrency: getNativeCurrency(state), assetImage: getSelectedTokenAssetImage(state), } } diff --git a/ui/app/components/user-preferenced-currency-display/tests/user-preferenced-currency-display.container.test.js b/ui/app/components/user-preferenced-currency-display/tests/user-preferenced-currency-display.container.test.js index 00a6079f4ca2..cf06a3613d92 100644 --- a/ui/app/components/user-preferenced-currency-display/tests/user-preferenced-currency-display.container.test.js +++ b/ui/app/components/user-preferenced-currency-display/tests/user-preferenced-currency-display.container.test.js @@ -18,7 +18,7 @@ describe('UserPreferencedCurrencyDisplay container', () => { it('should return the correct props', () => { const mockState = { metamask: { - fromCurrency: 'ETH', + nativeCurrency: 'ETH', preferences: { useETHAsPrimaryCurrency: true, }, @@ -26,7 +26,7 @@ describe('UserPreferencedCurrencyDisplay container', () => { } assert.deepEqual(mapStateToProps(mockState), { - fromCurrency: 'ETH', + nativeCurrency: 'ETH', useETHAsPrimaryCurrency: true, }) }) @@ -40,14 +40,14 @@ describe('UserPreferencedCurrencyDisplay container', () => { { stateProps: { useETHAsPrimaryCurrency: true, - fromCurrency: 'ETH', + nativeCurrency: 'ETH', }, ownProps: { type: 'PRIMARY', }, result: { currency: 'ETH', - fromCurrency: 'ETH', + nativeCurrency: 'ETH', numberOfDecimals: 6, prefix: undefined, }, @@ -55,14 +55,14 @@ describe('UserPreferencedCurrencyDisplay container', () => { { stateProps: { useETHAsPrimaryCurrency: false, - fromCurrency: 'ETH', + nativeCurrency: 'ETH', }, ownProps: { type: 'PRIMARY', }, result: { currency: undefined, - fromCurrency: 'ETH', + nativeCurrency: 'ETH', numberOfDecimals: 2, prefix: undefined, }, @@ -70,7 +70,7 @@ describe('UserPreferencedCurrencyDisplay container', () => { { stateProps: { useETHAsPrimaryCurrency: true, - fromCurrency: 'ETH', + nativeCurrency: 'ETH', }, ownProps: { type: 'SECONDARY', @@ -78,7 +78,7 @@ describe('UserPreferencedCurrencyDisplay container', () => { fiatPrefix: '-', }, result: { - fromCurrency: 'ETH', + nativeCurrency: 'ETH', currency: undefined, numberOfDecimals: 4, prefix: '-', @@ -87,7 +87,7 @@ describe('UserPreferencedCurrencyDisplay container', () => { { stateProps: { useETHAsPrimaryCurrency: false, - fromCurrency: 'ETH', + nativeCurrency: 'ETH', }, ownProps: { type: 'SECONDARY', @@ -98,7 +98,7 @@ describe('UserPreferencedCurrencyDisplay container', () => { }, result: { currency: 'ETH', - fromCurrency: 'ETH', + nativeCurrency: 'ETH', numberOfDecimals: 3, prefix: 'b', }, diff --git a/ui/app/components/user-preferenced-currency-display/user-preferenced-currency-display.component.js b/ui/app/components/user-preferenced-currency-display/user-preferenced-currency-display.component.js index be3dbe8f6716..f2a834ea7402 100644 --- a/ui/app/components/user-preferenced-currency-display/user-preferenced-currency-display.component.js +++ b/ui/app/components/user-preferenced-currency-display/user-preferenced-currency-display.component.js @@ -21,7 +21,7 @@ export default class UserPreferencedCurrencyDisplay extends PureComponent { fiatPrefix: PropTypes.string, // From container currency: PropTypes.string, - fromCurrency: PropTypes.string, + nativeCurrency: PropTypes.string, } renderEthLogo () { diff --git a/ui/app/components/user-preferenced-currency-display/user-preferenced-currency-display.container.js b/ui/app/components/user-preferenced-currency-display/user-preferenced-currency-display.container.js index d84aa19fbb1c..28329b3dfd76 100644 --- a/ui/app/components/user-preferenced-currency-display/user-preferenced-currency-display.container.js +++ b/ui/app/components/user-preferenced-currency-display/user-preferenced-currency-display.container.js @@ -8,12 +8,12 @@ const mapStateToProps = (state, ownProps) => { return { useETHAsPrimaryCurrency, - fromCurrency: state.metamask.fromCurrency, + nativeCurrency: state.metamask.nativeCurrency, } } const mergeProps = (stateProps, dispatchProps, ownProps) => { - const { useETHAsPrimaryCurrency, fromCurrency, ...restStateProps } = stateProps + const { useETHAsPrimaryCurrency, nativeCurrency, ...restStateProps } = stateProps const { type, numberOfDecimals: propsNumberOfDecimals, @@ -30,7 +30,7 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => { if (type === PRIMARY && useETHAsPrimaryCurrency || type === SECONDARY && !useETHAsPrimaryCurrency) { // Display ETH - currency = fromCurrency || ETH + currency = nativeCurrency || ETH numberOfDecimals = propsNumberOfDecimals || ethNumberOfDecimals || 6 prefix = propsPrefix || ethPrefix } else if (type === SECONDARY && useETHAsPrimaryCurrency || @@ -44,7 +44,7 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => { ...restStateProps, ...dispatchProps, ...restOwnProps, - fromCurrency, + nativeCurrency, currency, numberOfDecimals, prefix, diff --git a/ui/app/ducks/confirm-transaction.duck.js b/ui/app/ducks/confirm-transaction.duck.js index 8506f1765359..4d3a31c699e5 100644 --- a/ui/app/ducks/confirm-transaction.duck.js +++ b/ui/app/ducks/confirm-transaction.duck.js @@ -2,7 +2,7 @@ import { conversionRateSelector, currentCurrencySelector, unconfirmedTransactionsHashSelector, - getFromCurrency, + getNativeCurrency, } from '../selectors/confirm-transaction' import { @@ -293,17 +293,17 @@ export function updateTxDataAndCalculate (txData) { const state = getState() const currentCurrency = currentCurrencySelector(state) const conversionRate = conversionRateSelector(state) - const fromCurrency = getFromCurrency(state) + const nativeCurrency = getNativeCurrency(state) dispatch(updateTxData(txData)) const { txParams: { value = '0x0', gas: gasLimit = '0x0', gasPrice = '0x0' } = {} } = txData const fiatTransactionAmount = getValueFromWeiHex({ - value, fromCurrency, toCurrency: currentCurrency, conversionRate, numberOfDecimals: 2, + value, fromCurrency: nativeCurrency, toCurrency: currentCurrency, conversionRate, numberOfDecimals: 2, }) const ethTransactionAmount = getValueFromWeiHex({ - value, fromCurrency, toCurrency: fromCurrency, conversionRate, numberOfDecimals: 6, + value, fromCurrency: nativeCurrency, toCurrency: nativeCurrency, conversionRate, numberOfDecimals: 6, }) dispatch(updateTransactionAmounts({ @@ -316,15 +316,15 @@ export function updateTxDataAndCalculate (txData) { const fiatTransactionFee = getTransactionFee({ value: hexTransactionFee, - fromCurrency, + fromCurrency: nativeCurrency, toCurrency: currentCurrency, numberOfDecimals: 2, conversionRate, }) const ethTransactionFee = getTransactionFee({ value: hexTransactionFee, - fromCurrency, - toCurrency: fromCurrency, + fromCurrency: nativeCurrency, + toCurrency: nativeCurrency, numberOfDecimals: 6, conversionRate, }) diff --git a/ui/app/selectors.js b/ui/app/selectors.js index 88a247fbc6b5..7209f19d1f7f 100644 --- a/ui/app/selectors.js +++ b/ui/app/selectors.js @@ -26,7 +26,7 @@ const selectors = { getAddressBook, getSendFrom, getCurrentCurrency, - getFromCurrency, + getNativeCurrency, getSendAmount, getSelectedTokenToFiatRate, getSelectedTokenContract, @@ -144,8 +144,8 @@ function getCurrentCurrency (state) { return state.metamask.currentCurrency } -function getFromCurrency (state) { - return state.metamask.fromCurrency +function getNativeCurrency (state) { + return state.metamask.nativeCurrency } function getSelectedTokenToFiatRate (state) { diff --git a/ui/app/selectors/confirm-transaction.js b/ui/app/selectors/confirm-transaction.js index f7bd2c8f022d..90924c036dd0 100644 --- a/ui/app/selectors/confirm-transaction.js +++ b/ui/app/selectors/confirm-transaction.js @@ -93,7 +93,7 @@ export const unconfirmedTransactionsCountSelector = createSelector( export const currentCurrencySelector = state => state.metamask.currentCurrency export const conversionRateSelector = state => state.metamask.conversionRate -export const getFromCurrency = state => state.metamask.fromCurrency +export const getNativeCurrency = state => state.metamask.nativeCurrency const txDataSelector = state => state.confirmTransaction.txData const tokenDataSelector = state => state.confirmTransaction.tokenData