From 0adca6e67a870c48327226b3e7ee154e0450f718 Mon Sep 17 00:00:00 2001 From: Salim Toubal Date: Wed, 28 Feb 2024 23:38:36 +0100 Subject: [PATCH] fix: fix linea testnet case --- .../useIsOriginalNativeTokenSymbol.test.ts | 42 +++++++++++++++++++ .../hooks/useIsOriginalNativeTokenSymbol.ts | 4 +- app/constants/network.js | 2 +- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/app/components/UI/Ramp/hooks/useIsOriginalNativeTokenSymbol.test.ts b/app/components/UI/Ramp/hooks/useIsOriginalNativeTokenSymbol.test.ts index dfbfffcc5ddb..85f9c63d1429 100644 --- a/app/components/UI/Ramp/hooks/useIsOriginalNativeTokenSymbol.test.ts +++ b/app/components/UI/Ramp/hooks/useIsOriginalNativeTokenSymbol.test.ts @@ -257,4 +257,46 @@ describe('useNativeTokenFiatAmount', () => { expect(result.result.current).toBe(true); expect(spyFetch).not.toHaveBeenCalled(); }); + + it('should return the correct value for LineaGoerli testnet', async () => { + mockSelectorState({ + engine: { + backgroundState: { + ...initialBackgroundState, + PreferencesController: { + useSafeChainsListValidation: true, + }, + }, + }, + }); + + // Mock the safeChainsList response with a different native symbol + const safeChainsList = [ + { + chainId: 1, + nativeCurrency: { + symbol: 'BTC', + }, + }, + ]; + + // Mock the fetchWithCache function to return the safeChainsList + const spyFetch = jest.spyOn(axios, 'get').mockImplementation(() => + Promise.resolve({ + data: safeChainsList, + }), + ); + + let result: any; + + await act(async () => { + result = renderHook(() => + useIsOriginalNativeTokenSymbol('0xe704', 'LineaETH', 'linea'), + ); + }); + // expect this to pass because the chainId is in the CURRENCY_SYMBOL_BY_CHAIN_ID + expect(result.result.current).toBe(true); + // expect that the chainlist API was not called + expect(spyFetch).not.toHaveBeenCalled(); + }); }); diff --git a/app/components/UI/Ramp/hooks/useIsOriginalNativeTokenSymbol.ts b/app/components/UI/Ramp/hooks/useIsOriginalNativeTokenSymbol.ts index 6045ab6101f0..b012b3fa46a7 100644 --- a/app/components/UI/Ramp/hooks/useIsOriginalNativeTokenSymbol.ts +++ b/app/components/UI/Ramp/hooks/useIsOriginalNativeTokenSymbol.ts @@ -3,7 +3,6 @@ import { useSelector } from 'react-redux'; import { CURRENCY_SYMBOL_BY_CHAIN_ID } from '../../../../../app/constants/network'; import { selectUseSafeChainsListValidation } from '../../../../../app/selectors/preferencesController'; import axios from 'axios'; -import { toHexadecimal } from '../../../../../app/util/number'; const CHAIN_ID_NETWORK_URL = 'https://chainid.network/chains.json'; @@ -34,8 +33,7 @@ function useIsOriginalNativeTokenSymbol( } // check first on the CURRENCY_SYMBOL_BY_CHAIN_ID - const mappedCurrencySymbol = - CURRENCY_SYMBOL_BY_CHAIN_ID[toHexadecimal(networkId)]; + const mappedCurrencySymbol = CURRENCY_SYMBOL_BY_CHAIN_ID[networkId]; if (mappedCurrencySymbol) { setIsOriginalNativeSymbol(mappedCurrencySymbol === ticker); diff --git a/app/constants/network.js b/app/constants/network.js index c34d29cabb2c..609d4a691206 100644 --- a/app/constants/network.js +++ b/app/constants/network.js @@ -53,7 +53,7 @@ export const CHAINLIST_CURRENCY_SYMBOLS_MAP = { CELO: 'CELO', HARMONY: 'ONE', SEPOLIA: 'SepoliaETH', - LINEA_GOERLI: 'ETH', + LINEA_GOERLI: 'LineaETH', GOERLI: 'GoerliETH', LINEA_MAINNET: 'ETH', ZKSYNC_ERA: 'ETH',