From ed09bcb85a40ceeee3a684a1106609fd81362d9e Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Thu, 26 Jan 2023 20:47:53 -0330 Subject: [PATCH 1/6] Use network provider state, instead of CurrencyRateController state, select 'nativeCurrency' --- ui/ducks/metamask/metamask.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/ducks/metamask/metamask.js b/ui/ducks/metamask/metamask.js index 878da2a9ff12..c098b1adc259 100644 --- a/ui/ducks/metamask/metamask.js +++ b/ui/ducks/metamask/metamask.js @@ -307,7 +307,7 @@ export function getConversionRate(state) { } export function getNativeCurrency(state) { - return state.metamask.nativeCurrency; + return state.metamask.provider.ticker; } export function getSendHexDataFeatureFlagState(state) { From cddca598a3145669b67fbe0e5ad96ab2ea250756 Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Fri, 27 Jan 2023 06:59:12 -0330 Subject: [PATCH 2/6] Fix unit tests --- test/data/mock-state.json | 3 ++- .../transaction-activity-log.container.test.js | 4 ++++ .../confirm-transaction.duck.test.js | 3 +++ ui/ducks/metamask/metamask.test.js | 1 + ui/pages/send/gas-display/gas-display.js | 3 ++- .../__snapshots__/send-content.component.test.js.snap | 10 +++------- 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/test/data/mock-state.json b/test/data/mock-state.json index b53e97a8a78e..2fcf1bb07bc0 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 cb6dbeab0deb..58c3674f10e0 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 2f5e1ff4c3fd..4fc239d3170b 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.test.js b/ui/ducks/metamask/metamask.test.js index 8b39e355b213..eac1d5bc8582 100644 --- a/ui/ducks/metamask/metamask.test.js +++ b/ui/ducks/metamask/metamask.test.js @@ -44,6 +44,7 @@ describe('MetaMask Reducers', () => { provider: { type: 'testnet', chainId: '0x5', + ticker: 'ETH', }, accounts: { '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825': { diff --git a/ui/pages/send/gas-display/gas-display.js b/ui/pages/send/gas-display/gas-display.js index 9f0398e474b4..313779e332f0 100644 --- a/ui/pages/send/gas-display/gas-display.js +++ b/ui/pages/send/gas-display/gas-display.js @@ -60,9 +60,10 @@ export default function GasDisplay({ gasError }) { const useCurrencyRateCheck = useSelector(getUseCurrencyRateCheck); const { showFiatInTestnets, useNativeCurrencyAsPrimaryCurrency } = useSelector(getPreferences); - const { nativeCurrency, provider, unapprovedTxs } = useSelector( + 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 db87fae1ea6e..031652ec624b 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 -
+ />
From 8d80a463f27366989e26eca74a8998f92f7a94a3 Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Fri, 27 Jan 2023 07:41:45 -0330 Subject: [PATCH 3/6] Lint fix --- ui/ducks/confirm-transaction/confirm-transaction.duck.test.js | 2 +- ui/pages/send/gas-display/gas-display.js | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/ui/ducks/confirm-transaction/confirm-transaction.duck.test.js b/ui/ducks/confirm-transaction/confirm-transaction.duck.test.js index 4fc239d3170b..4d31dca274f0 100644 --- a/ui/ducks/confirm-transaction/confirm-transaction.duck.test.js +++ b/ui/ducks/confirm-transaction/confirm-transaction.duck.test.js @@ -291,7 +291,7 @@ describe('Confirm Transaction Duck', () => { conversionRate: 468.58, currentCurrency: 'usd', provider: { - ticker: 'ETH' + ticker: 'ETH', }, }, confirmTransaction: { diff --git a/ui/pages/send/gas-display/gas-display.js b/ui/pages/send/gas-display/gas-display.js index 313779e332f0..a968d4dc3cc4 100644 --- a/ui/pages/send/gas-display/gas-display.js +++ b/ui/pages/send/gas-display/gas-display.js @@ -60,9 +60,7 @@ export default function GasDisplay({ gasError }) { const useCurrencyRateCheck = useSelector(getUseCurrencyRateCheck); const { showFiatInTestnets, useNativeCurrencyAsPrimaryCurrency } = useSelector(getPreferences); - const { 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]; From 49b65ad530e3b384577034039264a7d5819472a7 Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Fri, 27 Jan 2023 11:54:31 -0330 Subject: [PATCH 4/6] Only use the network provider ticket for the native currency when useCurrencyRateCheck is false --- ui/ducks/metamask/metamask.js | 6 +++++- ui/ducks/metamask/metamask.test.js | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ui/ducks/metamask/metamask.js b/ui/ducks/metamask/metamask.js index c098b1adc259..bd31a1517574 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.provider.ticker; + 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 eac1d5bc8582..50cc6bdcae6a 100644 --- a/ui/ducks/metamask/metamask.test.js +++ b/ui/ducks/metamask/metamask.test.js @@ -40,11 +40,12 @@ describe('MetaMask Reducers', () => { currentBlockGasLimit: '0x4c1878', conversionRate: 1200.88200327, nativeCurrency: 'ETH', + useCurrencyRateCheck: true, network: '5', provider: { type: 'testnet', chainId: '0x5', - ticker: 'ETH', + ticker: 'TestETH', }, accounts: { '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825': { @@ -309,9 +310,18 @@ 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({ + useCurrencyRateCheck: false, + ...mockState, + }), + ).toStrictEqual('TestETH'); + }); }); describe('getSendHexDataFeatureFlagState()', () => { From f8c41201ad9c6a8430814eed6ce4b1979c42ca0e Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Fri, 27 Jan 2023 12:07:57 -0330 Subject: [PATCH 5/6] Fix unit test --- ui/ducks/metamask/metamask.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/ducks/metamask/metamask.test.js b/ui/ducks/metamask/metamask.test.js index 50cc6bdcae6a..956a012541f4 100644 --- a/ui/ducks/metamask/metamask.test.js +++ b/ui/ducks/metamask/metamask.test.js @@ -317,8 +317,8 @@ describe('MetaMask Reducers', () => { it('should return the ticker symbol of the selected network when useCurrencyRateCheck is false', () => { expect( getNativeCurrency({ - useCurrencyRateCheck: false, ...mockState, + useCurrencyRateCheck: false, }), ).toStrictEqual('TestETH'); }); From c07ef736655a6012c24ed817ff113499dea2a9f0 Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Fri, 27 Jan 2023 12:33:26 -0330 Subject: [PATCH 6/6] Fix tests for real --- ui/ducks/metamask/metamask.test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ui/ducks/metamask/metamask.test.js b/ui/ducks/metamask/metamask.test.js index 956a012541f4..510ba2215956 100644 --- a/ui/ducks/metamask/metamask.test.js +++ b/ui/ducks/metamask/metamask.test.js @@ -318,7 +318,10 @@ describe('MetaMask Reducers', () => { expect( getNativeCurrency({ ...mockState, - useCurrencyRateCheck: false, + metamask: { + ...mockState.metamask, + useCurrencyRateCheck: false, + }, }), ).toStrictEqual('TestETH'); });