From 5b06bf795bd59e4011ce30d3e39132466b9cdb87 Mon Sep 17 00:00:00 2001 From: Erik Marks <25517051+rekmarks@users.noreply.github.com> Date: Mon, 4 May 2020 10:54:54 -0700 Subject: [PATCH] Delete amountConversionRate and selectors (#8503) --- app/scripts/background.js | 2 +- test/unit/ui/app/selectors.spec.js | 24 -------- .../ui/token-input/token-input.container.js | 7 ++- ui/app/ducks/metamask/metamask.js | 1 - .../send-amount-row.component.js | 7 --- .../send-amount-row.container.js | 2 - .../tests/send-amount-row-component.test.js | 3 - ui/app/pages/send/send.component.js | 7 --- ui/app/pages/send/send.container.js | 2 - ui/app/pages/send/send.selectors.js | 38 ------------ ui/app/pages/send/send.utils.js | 7 +-- .../pages/send/tests/send-component.test.js | 3 - .../send/tests/send-selectors-test-data.js | 8 --- .../pages/send/tests/send-selectors.test.js | 59 ------------------- ui/app/pages/send/tests/send-utils.test.js | 8 +-- ui/app/selectors/selectors.js | 5 -- ui/app/selectors/tests/selectors-test-data.js | 10 +--- 17 files changed, 12 insertions(+), 181 deletions(-) diff --git a/app/scripts/background.js b/app/scripts/background.js index 9016a3944..41f1809bb 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -103,7 +103,7 @@ initialize().catch(log.error) * @property {Array} frequentRpcList - A list of frequently used RPCs, including custom user-provided ones. * @property {Array} addressBook - A list of previously sent to addresses. * @property {address} selectedTokenAddress - Used to indicate if a token is globally selected. Should be deprecated in favor of UI-centric token selection. - * @property {Object} tokenExchangeRates - Info about current token prices. + * @property {Object} contractExchangeRates - Info about current token prices. * @property {Array} tokens - Tokens held by the current user, including their balances. * @property {Object} send - TODO: Document * @property {Object} coinOptions - TODO: Document diff --git a/test/unit/ui/app/selectors.spec.js b/test/unit/ui/app/selectors.spec.js index c60851dd8..fff3f89d4 100644 --- a/test/unit/ui/app/selectors.spec.js +++ b/test/unit/ui/app/selectors.spec.js @@ -46,30 +46,6 @@ describe('Selectors', function () { }) }) - - describe('#getTokenExchangeRate', function () { - let missingTokenRate - - beforeEach(function () { - missingTokenRate = { - metamask: { - 'contractExchangeRates': {}, - }, - } - }) - - it('returns 0 token exchange rate for a token not in state', function () { - const tokenRate = selectors.getTokenExchangeRate(missingTokenRate, '0xd8f6a2ffb0fc5952d16c9768b71cfd35b6399aa5') - assert.equal(tokenRate, 0) - }) - - it('returns token exchange rate for specified token in state', function () { - const tokenRate = selectors.getTokenExchangeRate(mockState, '0xd8f6a2ffb0fc5952d16c9768b71cfd35b6399aa5') - assert.equal(tokenRate, 0.00008189274407698049) - }) - - }) - it('returns conversionRate from state', function () { assert.equal(selectors.conversionRateSelector(mockState), 556.12) }) diff --git a/ui/app/components/ui/token-input/token-input.container.js b/ui/app/components/ui/token-input/token-input.container.js index 933766bac..047cb46d0 100644 --- a/ui/app/components/ui/token-input/token-input.container.js +++ b/ui/app/components/ui/token-input/token-input.container.js @@ -1,6 +1,11 @@ import { connect } from 'react-redux' import TokenInput from './token-input.component' -import { getIsMainnet, getSelectedToken, getSelectedTokenExchangeRate, preferencesSelector } from '../../../selectors' +import { + getIsMainnet, + getSelectedToken, + getSelectedTokenExchangeRate, + preferencesSelector, +} from '../../../selectors' const mapStateToProps = (state) => { const { metamask: { currentCurrency } } = state diff --git a/ui/app/ducks/metamask/metamask.js b/ui/app/ducks/metamask/metamask.js index c5130e96e..ab85e8fd5 100644 --- a/ui/app/ducks/metamask/metamask.js +++ b/ui/app/ducks/metamask/metamask.js @@ -12,7 +12,6 @@ export default function reduceMetamask (state = {}, action) { addressBook: [], selectedTokenAddress: null, contractExchangeRates: {}, - tokenExchangeRates: {}, tokens: [], pendingTokens: {}, customNonceValue: '', diff --git a/ui/app/pages/send/send-content/send-amount-row/send-amount-row.component.js b/ui/app/pages/send/send-content/send-amount-row/send-amount-row.component.js index 134ffbce1..d307fdffd 100644 --- a/ui/app/pages/send/send-content/send-amount-row/send-amount-row.component.js +++ b/ui/app/pages/send/send-content/send-amount-row/send-amount-row.component.js @@ -10,10 +10,6 @@ export default class SendAmountRow extends Component { static propTypes = { amount: PropTypes.string, - amountConversionRate: PropTypes.oneOfType([ - PropTypes.string, - PropTypes.number, - ]), balance: PropTypes.string, conversionRate: PropTypes.number, gasTotal: PropTypes.string, @@ -50,7 +46,6 @@ export default class SendAmountRow extends Component { validateAmount (amount) { const { - amountConversionRate, balance, conversionRate, gasTotal, @@ -63,7 +58,6 @@ export default class SendAmountRow extends Component { updateSendAmountError({ amount, - amountConversionRate, balance, conversionRate, gasTotal, @@ -74,7 +68,6 @@ export default class SendAmountRow extends Component { if (selectedToken) { updateGasFeeError({ - amountConversionRate, balance, conversionRate, gasTotal, diff --git a/ui/app/pages/send/send-content/send-amount-row/send-amount-row.container.js b/ui/app/pages/send/send-content/send-amount-row/send-amount-row.container.js index 3ecfd69bb..5c7e3cd58 100644 --- a/ui/app/pages/send/send-content/send-amount-row/send-amount-row.container.js +++ b/ui/app/pages/send/send-content/send-amount-row/send-amount-row.container.js @@ -1,6 +1,5 @@ import { connect } from 'react-redux' import { - getAmountConversionRate, getConversionRate, getGasTotal, getPrimaryCurrency, @@ -26,7 +25,6 @@ export default connect(mapStateToProps, mapDispatchToProps)(SendAmountRow) function mapStateToProps (state) { return { amount: getSendAmount(state), - amountConversionRate: getAmountConversionRate(state), balance: getSendFromBalance(state), conversionRate: getConversionRate(state), gasTotal: getGasTotal(state), diff --git a/ui/app/pages/send/send-content/send-amount-row/tests/send-amount-row-component.test.js b/ui/app/pages/send/send-content/send-amount-row/tests/send-amount-row-component.test.js index 65559205a..0af1f2bd7 100644 --- a/ui/app/pages/send/send-content/send-amount-row/tests/send-amount-row-component.test.js +++ b/ui/app/pages/send/send-content/send-amount-row/tests/send-amount-row-component.test.js @@ -19,7 +19,6 @@ describe('SendAmountRow Component', function () { assert.ok(updateSendAmountError.calledOnceWithExactly({ amount: 'someAmount', - amountConversionRate: 'mockAmountConversionRate', balance: 'mockBalance', conversionRate: 7, gasTotal: 'mockGasTotal', @@ -37,7 +36,6 @@ describe('SendAmountRow Component', function () { instance.validateAmount('someAmount') assert.ok(updateGasFeeError.calledOnceWithExactly({ - amountConversionRate: 'mockAmountConversionRate', balance: 'mockBalance', conversionRate: 7, gasTotal: 'mockGasTotal', @@ -148,7 +146,6 @@ function shallowRenderSendAmountRow () { const wrapper = shallow(( { - // it('should', () => { - // assert.deepEqual( - // autoAddToBetaUI(mockState), - - // ) - // }) - // }) - - describe('getAmountConversionRate()', function () { - it('should return the token conversion rate if a token is selected', function () { - assert.equal( - getAmountConversionRate(mockState), - 2401.76400654 - ) - }) - - it('should return the eth conversion rate if no token is selected', function () { - const editedMockState = { - metamask: Object.assign({}, mockState.metamask, { selectedTokenAddress: null }), - } - assert.equal( - getAmountConversionRate(editedMockState), - 1200.88200327 - ) - }) - }) - describe('getBlockGasLimit', function () { it('should return the current block gas limit', function () { assert.deepEqual( @@ -291,24 +259,6 @@ describe('send selectors', function () { }) }) - describe('getSelectedTokenExchangeRate()', function () { - it('should return the exchange rate for the selected token', function () { - assert.equal( - getSelectedTokenExchangeRate(mockState), - 2.0 - ) - }) - }) - - describe('getSelectedTokenToFiatRate()', function () { - it('should return rate for converting the selected token to fiat', function () { - assert.equal( - getSelectedTokenToFiatRate(mockState), - 2401.76400654 - ) - }) - }) - describe('getSendAmount()', function () { it('should return the send.amount', function () { assert.equal( @@ -480,15 +430,6 @@ describe('send selectors', function () { }) }) - describe('getTokenExchangeRate()', function () { - it('should return the passed tokens exchange rates', function () { - assert.equal( - getTokenExchangeRate(mockState, 'GHI'), - 31.01 - ) - }) - }) - describe('getUnapprovedTxs()', function () { it('should return the unapproved txs', function () { assert.deepEqual( diff --git a/ui/app/pages/send/tests/send-utils.test.js b/ui/app/pages/send/tests/send-utils.test.js index 77f8f0443..450b1bf39 100644 --- a/ui/app/pages/send/tests/send-utils.test.js +++ b/ui/app/pages/send/tests/send-utils.test.js @@ -140,7 +140,6 @@ describe('send utils', function () { const config = { 'should return insufficientFunds error if isBalanceSufficient returns false': { amount: 15, - amountConversionRate: 2, balance: 1, conversionRate: 3, gasTotal: 17, @@ -149,7 +148,6 @@ describe('send utils', function () { }, 'should not return insufficientFunds error if selectedToken is truthy': { amount: '0x0', - amountConversionRate: 2, balance: 1, conversionRate: 3, gasTotal: 17, @@ -161,7 +159,6 @@ describe('send utils', function () { }, 'should return insufficientTokens error if token is selected and isTokenBalanceSufficient returns false': { amount: '0x10', - amountConversionRate: 2, balance: 100, conversionRate: 3, decimals: 10, @@ -182,7 +179,6 @@ describe('send utils', function () { describe('getGasFeeErrorObject()', function () { const config = { 'should return insufficientFunds error if isBalanceSufficient returns false': { - amountConversionRate: 2, balance: 16, conversionRate: 3, gasTotal: 17, @@ -190,7 +186,6 @@ describe('send utils', function () { expectedResult: { gasFee: INSUFFICIENT_FUNDS_ERROR }, }, 'should return null error if isBalanceSufficient returns true': { - amountConversionRate: 2, balance: 16, conversionRate: 3, gasTotal: 15, @@ -223,7 +218,6 @@ describe('send utils', function () { stubs.conversionGTE.resetHistory() const result = isBalanceSufficient({ amount: 15, - amountConversionRate: 2, balance: 100, conversionRate: 3, gasTotal: 17, @@ -251,7 +245,7 @@ describe('send utils', function () { { value: 32, fromNumericBase: 'hex', - conversionRate: 2, + conversionRate: 3, fromCurrency: 'ABC', }, ] diff --git a/ui/app/selectors/selectors.js b/ui/app/selectors/selectors.js index 314f879da..946bb5aad 100644 --- a/ui/app/selectors/selectors.js +++ b/ui/app/selectors/selectors.js @@ -184,11 +184,6 @@ export function getAssetImages (state) { return assetImages } -export function getTokenExchangeRate (state, address) { - const contractExchangeRates = state.metamask.contractExchangeRates - return contractExchangeRates[address] || 0 -} - export function getAddressBook (state) { const network = state.metamask.network if (!state.metamask.addressBook[network]) { diff --git a/ui/app/selectors/tests/selectors-test-data.js b/ui/app/selectors/tests/selectors-test-data.js index b2b0282f0..53ce8e6bd 100644 --- a/ui/app/selectors/tests/selectors-test-data.js +++ b/ui/app/selectors/tests/selectors-test-data.js @@ -84,13 +84,9 @@ export default { 'symbol': 'GHI', }, ], - 'tokenExchangeRates': { - 'def_eth': { - rate: 2.0, - }, - 'ghi_eth': { - rate: 31.01, - }, + 'contractExchangeRates': { + '0x8d6b81208414189a58339873ab429b6c47ab92d3': 0.00039345803819379796, + '0xd8f6a2ffb0fc5952d16c9768b71cfd35b6399aa5': 0.00008189274407698049, }, 'transactions': {}, 'currentNetworkTxList': [