From 7a77c8251444a3a11f07cc76138273f0ffacac9c Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Fri, 27 Jan 2023 09:17:47 -0800 Subject: [PATCH] Use network provider state, instead of CurrencyRateController state, to select 'nativeCurrency' (#17450) * Use network provider state, instead of CurrencyRateController state, select 'nativeCurrency' * Fix unit tests * Lint fix * Only use the network provider ticket for the native currency when useCurrencyRateCheck is false * Fix unit test * Fix tests for real --- test/data/mock-state.json | 3 ++- .../transaction-activity-log.container.test.js | 4 ++++ .../confirm-transaction.duck.test.js | 3 +++ ui/ducks/metamask/metamask.js | 6 +++++- ui/ducks/metamask/metamask.test.js | 16 +++++++++++++++- ui/pages/send/gas-display/gas-display.js | 5 ++--- .../send-content.component.test.js.snap | 10 +++------- 7 files changed, 34 insertions(+), 13 deletions(-) diff --git a/test/data/mock-state.json b/test/data/mock-state.json index b53e97a8a..2fcf1bb07 100644 --- a/test/data/mock-state.json +++ b/test/data/mock-state.json @@ -74,7 +74,8 @@ "network": "5", "provider": { "type": "rpc", - "chainId": "0x5" + "chainId": "0x5", + "ticker": "ETH" }, "keyrings": [ { diff --git a/ui/components/app/transaction-activity-log/transaction-activity-log.container.test.js b/ui/components/app/transaction-activity-log/transaction-activity-log.container.test.js index cb6dbeab0..58c3674f1 100644 --- a/ui/components/app/transaction-activity-log/transaction-activity-log.container.test.js +++ b/ui/components/app/transaction-activity-log/transaction-activity-log.container.test.js @@ -18,6 +18,9 @@ describe('TransactionActivityLog container', () => { conversionRate: 280.45, nativeCurrency: 'ETH', frequentRpcListDetail: [], + provider: { + ticker: 'ETH', + }, }, }; @@ -43,6 +46,7 @@ describe('TransactionActivityLog container', () => { ], provider: { rpcUrl: 'https://customnetwork.com/', + ticker: 'ETH', }, }, }; diff --git a/ui/ducks/confirm-transaction/confirm-transaction.duck.test.js b/ui/ducks/confirm-transaction/confirm-transaction.duck.test.js index 2f5e1ff4c..4d31dca27 100644 --- a/ui/ducks/confirm-transaction/confirm-transaction.duck.test.js +++ b/ui/ducks/confirm-transaction/confirm-transaction.duck.test.js @@ -290,6 +290,9 @@ describe('Confirm Transaction Duck', () => { metamask: { conversionRate: 468.58, currentCurrency: 'usd', + provider: { + ticker: 'ETH', + }, }, confirmTransaction: { ethTransactionAmount: '1', diff --git a/ui/ducks/metamask/metamask.js b/ui/ducks/metamask/metamask.js index 878da2a9f..bd31a1517 100644 --- a/ui/ducks/metamask/metamask.js +++ b/ui/ducks/metamask/metamask.js @@ -10,6 +10,7 @@ import { accountsWithSendEtherInfoSelector, checkNetworkAndAccountSupports1559, getAddressBook, + getUseCurrencyRateCheck, } from '../../selectors'; import { updateTransactionGasFees } from '../../store/actions'; import { setCustomGasLimit, setCustomGasPrice } from '../gas/gas.duck'; @@ -307,7 +308,10 @@ export function getConversionRate(state) { } export function getNativeCurrency(state) { - return state.metamask.nativeCurrency; + const useCurrencyRateCheck = getUseCurrencyRateCheck(state); + return useCurrencyRateCheck + ? state.metamask.nativeCurrency + : state.metamask.provider.ticker; } export function getSendHexDataFeatureFlagState(state) { diff --git a/ui/ducks/metamask/metamask.test.js b/ui/ducks/metamask/metamask.test.js index 8b39e355b..510ba2215 100644 --- a/ui/ducks/metamask/metamask.test.js +++ b/ui/ducks/metamask/metamask.test.js @@ -40,10 +40,12 @@ describe('MetaMask Reducers', () => { currentBlockGasLimit: '0x4c1878', conversionRate: 1200.88200327, nativeCurrency: 'ETH', + useCurrencyRateCheck: true, network: '5', provider: { type: 'testnet', chainId: '0x5', + ticker: 'TestETH', }, accounts: { '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825': { @@ -308,9 +310,21 @@ describe('MetaMask Reducers', () => { }); describe('getNativeCurrency()', () => { - it('should return the ticker symbol of the selected network', () => { + it('should return nativeCurrency when useCurrencyRateCheck is true', () => { expect(getNativeCurrency(mockState)).toStrictEqual('ETH'); }); + + it('should return the ticker symbol of the selected network when useCurrencyRateCheck is false', () => { + expect( + getNativeCurrency({ + ...mockState, + metamask: { + ...mockState.metamask, + useCurrencyRateCheck: false, + }, + }), + ).toStrictEqual('TestETH'); + }); }); describe('getSendHexDataFeatureFlagState()', () => { diff --git a/ui/pages/send/gas-display/gas-display.js b/ui/pages/send/gas-display/gas-display.js index 9f0398e47..a968d4dc3 100644 --- a/ui/pages/send/gas-display/gas-display.js +++ b/ui/pages/send/gas-display/gas-display.js @@ -60,9 +60,8 @@ export default function GasDisplay({ gasError }) { const useCurrencyRateCheck = useSelector(getUseCurrencyRateCheck); const { showFiatInTestnets, useNativeCurrencyAsPrimaryCurrency } = useSelector(getPreferences); - const { nativeCurrency, provider, unapprovedTxs } = useSelector( - (state) => state.metamask, - ); + const { provider, unapprovedTxs } = useSelector((state) => state.metamask); + const nativeCurrency = provider.ticker; const { chainId } = provider; const networkName = NETWORK_TO_NAME_MAP[chainId]; const isInsufficientTokenError = diff --git a/ui/pages/send/send-content/__snapshots__/send-content.component.test.js.snap b/ui/pages/send/send-content/__snapshots__/send-content.component.test.js.snap index db87fae1e..031652ec6 100644 --- a/ui/pages/send/send-content/__snapshots__/send-content.component.test.js.snap +++ b/ui/pages/send/send-content/__snapshots__/send-content.component.test.js.snap @@ -31,10 +31,8 @@ exports[`SendContent Component render should match snapshot 1`] = `
-
@@ -43,9 +41,7 @@ exports[`SendContent Component render should match snapshot 1`] = ` >
- ETH -
+ />