Skip to content

Commit

Permalink
fix: fix linea testnet case
Browse files Browse the repository at this point in the history
  • Loading branch information
salimtb committed Feb 28, 2024
1 parent bf5977c commit 0adca6e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion app/constants/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 0adca6e

Please sign in to comment.