From 2adc3e432d396beb0993515e444d8846518bee62 Mon Sep 17 00:00:00 2001 From: Victor Thomas <10986371+vthomas13@users.noreply.github.com> Date: Wed, 13 Dec 2023 17:31:34 -0500 Subject: [PATCH 1/5] Adding ChainID Currency Symbol Map (OP > ETH) --- shared/constants/network.ts | 19 ++++++++++++++++++- ui/hooks/useAccountTotalFiatBalance.test.js | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/shared/constants/network.ts b/shared/constants/network.ts index 8e7ad1a2354a..28e8fbb2ccd2 100644 --- a/shared/constants/network.ts +++ b/shared/constants/network.ts @@ -204,6 +204,7 @@ export const LOCALHOST_RPC_URL = 'http://localhost:8545'; export const CURRENCY_SYMBOLS = { ARBITRUM: 'ETH', AVALANCHE: 'AVAX', + BASE: 'ETH', BNB: 'BNB', BUSD: 'BUSD', CELO: 'CELO', @@ -212,17 +213,20 @@ export const CURRENCY_SYMBOLS = { ETH: 'ETH', FANTOM: 'FTM', HARMONY: 'ONE', + LINEA_MAINNET: 'ETH', + OPBNB: 'BNB', PALM: 'PALM', MATIC: 'MATIC', TEST_ETH: 'TESTETH', USDC: 'USDC', USDT: 'USDT', WETH: 'WETH', - OPTIMISM: 'OP', + OPTIMISM: 'ETH', CRONOS: 'CRO', GLIMMER: 'GLMR', MOONRIVER: 'MOVR', ONE: 'ONE', + ZKSYNC_ERA: 'ETH', } as const; export const ETH_TOKEN_IMAGE_URL = './images/eth_logo.png'; @@ -343,6 +347,19 @@ export const NETWORK_TO_NAME_MAP = { [CHAIN_IDS.LOCALHOST]: LOCALHOST_DISPLAY_NAME, } as const; +export const CHAIN_ID_TO_CURRENCY_SYMBOL_MAP = { + [CHAIN_IDS.AVALANCHE]: CURRENCY_SYMBOLS.AVALANCHE, + [CHAIN_IDS.BSC]: CURRENCY_SYMBOLS.BNB, + [CHAIN_IDS.BASE]: CURRENCY_SYMBOLS.BASE, + [CHAIN_IDS.ARBITRUM]: CURRENCY_SYMBOLS.ARBITRUM, + [CHAIN_IDS.LINEA_MAINNET]: CURRENCY_SYMBOLS.LINEA_MAINNET, + [CHAIN_IDS.MAINNET]: CURRENCY_SYMBOLS.ETH, + [CHAIN_IDS.OPBNB]: CURRENCY_SYMBOLS.OPBNB, + [CHAIN_IDS.OPTIMISM]: CURRENCY_SYMBOLS.OPTIMISM, + [CHAIN_IDS.POLYGON]: CURRENCY_SYMBOLS.MATIC, + [CHAIN_IDS.ZKSYNC_ERA]: CURRENCY_SYMBOLS.ZKSYNC_ERA, +} as const; + export const CHAIN_ID_TO_TYPE_MAP = { [CHAIN_IDS.MAINNET]: NETWORK_TYPES.MAINNET, [CHAIN_IDS.GOERLI]: NETWORK_TYPES.GOERLI, diff --git a/ui/hooks/useAccountTotalFiatBalance.test.js b/ui/hooks/useAccountTotalFiatBalance.test.js index 70dd78211f7b..791548395593 100644 --- a/ui/hooks/useAccountTotalFiatBalance.test.js +++ b/ui/hooks/useAccountTotalFiatBalance.test.js @@ -131,7 +131,7 @@ describe('useAccountTotalFiatBalance', () => { orderedTokenList: [ { fiatBalance: '1.85', - iconUrl: './images/eth_logo.png', + iconUrl: './images/optimism.svg', symbol: 'ETH', }, { From 676721c79f9ceabfde28d934a6b2a1d4002c1657 Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Fri, 15 Dec 2023 11:02:55 -0330 Subject: [PATCH 2/5] Add testnets to CHAIN_ID_TO_CURRENCY_SYMBOL_MAP --- shared/constants/network.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/shared/constants/network.ts b/shared/constants/network.ts index 28e8fbb2ccd2..75976d4cc470 100644 --- a/shared/constants/network.ts +++ b/shared/constants/network.ts @@ -358,6 +358,9 @@ export const CHAIN_ID_TO_CURRENCY_SYMBOL_MAP = { [CHAIN_IDS.OPTIMISM]: CURRENCY_SYMBOLS.OPTIMISM, [CHAIN_IDS.POLYGON]: CURRENCY_SYMBOLS.MATIC, [CHAIN_IDS.ZKSYNC_ERA]: CURRENCY_SYMBOLS.ZKSYNC_ERA, + [CHAIN_IDS.GOERLI]: EST_NETWORK_TICKER_MAP[NETWORK_TYPES.GOERLI], + [CHAIN_IDS.SEPOLIA]: TEST_NETWORK_TICKER_MAP[NETWORK_TYPES.SEPOLIA], + [CHAIN_IDS.LINEA_GOERLI]: TEST_NETWORK_TICKER_MAP[NETWORK_TYPES.LINEA_GOERLI], } as const; export const CHAIN_ID_TO_TYPE_MAP = { From 52bda686790139671135df69646fbcbb344dc605 Mon Sep 17 00:00:00 2001 From: Victor Thomas <10986371+vthomas13@users.noreply.github.com> Date: Fri, 15 Dec 2023 14:16:04 -0500 Subject: [PATCH 3/5] adding >99% networks, removing test change --- shared/constants/network.ts | 239 ++++++++++++++++++-- ui/hooks/useAccountTotalFiatBalance.test.js | 2 +- 2 files changed, 224 insertions(+), 17 deletions(-) diff --git a/shared/constants/network.ts b/shared/constants/network.ts index 75976d4cc470..d617764812b6 100644 --- a/shared/constants/network.ts +++ b/shared/constants/network.ts @@ -146,6 +146,60 @@ export const CHAIN_IDS = { ZKSYNC_ERA: '0x144', } as const; +const CHAINLIST_CHAIN_IDS_MAP = { + ...CHAIN_IDS, + SCROLL: '0x82750', + ZORA_MAINNET: '0x76adf1', + TAIKO_JOLNIR_L2_MAINNET: '0x28c5f', + POLYGON_ZKEVM: '0x44d', + FANTOM_OPERA: '0xfa', + CELO_MAINNET: '0xa4ec', + ARBITRUM_NOVA: '0xa4ba', + MANTLE: '0x1388', + CORE_BLOCKCHAIN_MAINNET: '0x45c', + MANTA_PACIFIC_MAINNET: '0xa9', + PULSECHAIN_MAINNET: '0x171', + FUSE_GOLD_MAINNET: '0x7a', + KAVA_EVM: '0x8ae', + DFK_CHAIN: '0xd2af', + HARMONY_MAINNET_SHARD_0: '0x63564c40', + PGN_PUBLIC_GOODS_NETWORK: '0x1a8', + LIGHTLINK_PHOENIX_MAINNET: '0x762', + NEAR_AURORA_MAINNET: '0x4e454152', + KROMA_MAINNET: '0xff', + NEBULA_MAINNET: '0x585eb4b1', + KLAYTN_MAINNET_CYPRESS: '0x2019', + ENDURANCE_SMART_CHAIN_MAINNET: '0x288', + CRONOS_MAINNET_BETA: '0x19', + FLARE_MAINNET: '0xe', + KCC_MAINNET: '0x141', + SHARDEUM_SPHINX_1X: '0x1f92', + ETHEREUM_CLASSIC_MAINNET: '0x3d', + HAQQ_NETWORK: '0x2be3', + SHARDEUM_LIBERTY_2X: '0x1f91', + BLACKFORT_EXCHANGE_NETWORK: '0x1387', + CONFLUX_ESPACE: '0x406', + FUSE_MAINNET: '0x7a', + CANTO: '0x1e14', + SHIB_MAINNET: '0x1b', + OKXCHAIN_MAINNET: '0x42', + ZKATANA: '0x133e40', + DEXALOT_SUBNET: '0x6984c', + ASTAR: '0x250', + EVMOS: '0x2329', + BAHAMUT_MAINNET: '0x142d', + SONGBIRD_CANARY_NETWORK: '0x13', + STEP_NETWORK: '0x4d2', + VELAS_EVM_MAINNET: '0x6a', + Q_MAINNET: '0x8a71', + TELOS_EVM_MAINNET: '0x28', + TENET: '0x617', + DOGECHAIN_MAINNET: '0x7d0', + OASYS_MAINNET: '0xf8', + HUOBI_ECO_CHAIN_MAINNET: '0x80', + ACALA_NETWORK: '0x313', +} as const; + /** * The largest possible chain ID we can handle. * Explanation: https://gist.github.com/rekmarks/a47bd5f2525936c4b8eee31a16345553 @@ -204,7 +258,6 @@ export const LOCALHOST_RPC_URL = 'http://localhost:8545'; export const CURRENCY_SYMBOLS = { ARBITRUM: 'ETH', AVALANCHE: 'AVAX', - BASE: 'ETH', BNB: 'BNB', BUSD: 'BUSD', CELO: 'CELO', @@ -213,8 +266,6 @@ export const CURRENCY_SYMBOLS = { ETH: 'ETH', FANTOM: 'FTM', HARMONY: 'ONE', - LINEA_MAINNET: 'ETH', - OPBNB: 'BNB', PALM: 'PALM', MATIC: 'MATIC', TEST_ETH: 'TESTETH', @@ -226,7 +277,65 @@ export const CURRENCY_SYMBOLS = { GLIMMER: 'GLMR', MOONRIVER: 'MOVR', ONE: 'ONE', +} as const; + +const CHAINLIST_CURRENCY_SYMBOLS_MAP = { + ...CURRENCY_SYMBOLS, + BASE: 'ETH', + LINEA_MAINNET: 'ETH', + OPBNB: 'BNB', ZKSYNC_ERA: 'ETH', + SCROLL: 'ETH', + ZORA_MAINNET: 'ETH', + TAIKO_JOLNIR_L2_MAINNET: 'ETH', + POLYGON_ZKEVM: 'ETH', + FANTOM_OPERA: 'FTM', + CELO_MAINNET: 'CELO', + ARBITRUM_NOVA: 'ETH', + MANTLE: 'MNT', + CORE_BLOCKCHAIN_MAINNET: 'CORE', + MANTA_PACIFIC_MAINNET: 'ETH', + PULSECHAIN_MAINNET: 'PLS', + MOONBEAM: 'GLMR', + FUSE_GOLD_MAINNET: 'FUSE', + KAVA_EVM: 'KAVA', + DFK_CHAIN: 'JEWEL', + HARMONY_MAINNET_SHARD_0: 'ONE', + PGN_PUBLIC_GOODS_NETWORK: 'ETH', + LIGHTLINK_PHOENIX_MAINNET: 'ETH', + NEAR_AURORA_MAINNET: 'ETH', + KROMA_MAINNET: 'ETH', + NEBULA_MAINNET: 'sFUEL', + KLAYTN_MAINNET_CYPRESS: 'KLAY', + ENDURANCE_SMART_CHAIN_MAINNET: 'ACE', + CRONOS_MAINNET_BETA: 'CRO', + FLARE_MAINNET: 'FLR', + KCC_MAINNET: 'KCS', + SHARDEUM_SPHINX_1X: 'SHM', + ETHEREUM_CLASSIC_MAINNET: 'ETC', + HAQQ_NETWORK: 'ISLM', + SHARDEUM_LIBERTY_2X: 'SHM', + BLACKFORT_EXCHANGE_NETWORK: 'BXN', + CONFLUX_ESPACE: 'CFX', + FUSE_MAINNET: 'FUSE', + CANTO: 'CANTO', + SHIB_MAINNET: 'SHIB', + OKXCHAIN_MAINNET: 'OKT', + ZKATANA: 'ETH', + DEXALOT_SUBNET: 'ALOT', + ASTAR: 'ASTR', + EVMOS: 'EVMOS', + BAHAMUT_MAINNET: 'FTN', + SONGBIRD_CANARY_NETWORK: 'SGB', + STEP_NETWORK: 'FITFI', + VELAS_EVM_MAINNET: 'VLX', + Q_MAINNET: 'Q', + TELOS_EVM_MAINNET: 'TLOS', + TENET: 'TENET', + DOGECHAIN_MAINNET: 'DOGE', + OASYS_MAINNET: 'OAS', + HUOBI_ECO_CHAIN_MAINNET: 'HT', + ACALA_NETWORK: 'ACA', } as const; export const ETH_TOKEN_IMAGE_URL = './images/eth_logo.png'; @@ -348,19 +457,117 @@ export const NETWORK_TO_NAME_MAP = { } as const; export const CHAIN_ID_TO_CURRENCY_SYMBOL_MAP = { - [CHAIN_IDS.AVALANCHE]: CURRENCY_SYMBOLS.AVALANCHE, - [CHAIN_IDS.BSC]: CURRENCY_SYMBOLS.BNB, - [CHAIN_IDS.BASE]: CURRENCY_SYMBOLS.BASE, - [CHAIN_IDS.ARBITRUM]: CURRENCY_SYMBOLS.ARBITRUM, - [CHAIN_IDS.LINEA_MAINNET]: CURRENCY_SYMBOLS.LINEA_MAINNET, - [CHAIN_IDS.MAINNET]: CURRENCY_SYMBOLS.ETH, - [CHAIN_IDS.OPBNB]: CURRENCY_SYMBOLS.OPBNB, - [CHAIN_IDS.OPTIMISM]: CURRENCY_SYMBOLS.OPTIMISM, - [CHAIN_IDS.POLYGON]: CURRENCY_SYMBOLS.MATIC, - [CHAIN_IDS.ZKSYNC_ERA]: CURRENCY_SYMBOLS.ZKSYNC_ERA, - [CHAIN_IDS.GOERLI]: EST_NETWORK_TICKER_MAP[NETWORK_TYPES.GOERLI], - [CHAIN_IDS.SEPOLIA]: TEST_NETWORK_TICKER_MAP[NETWORK_TYPES.SEPOLIA], - [CHAIN_IDS.LINEA_GOERLI]: TEST_NETWORK_TICKER_MAP[NETWORK_TYPES.LINEA_GOERLI], + [CHAINLIST_CHAIN_IDS_MAP.AVALANCHE]: CHAINLIST_CURRENCY_SYMBOLS_MAP.AVALANCHE, + [CHAINLIST_CHAIN_IDS_MAP.BSC]: CHAINLIST_CURRENCY_SYMBOLS_MAP.BNB, + [CHAINLIST_CHAIN_IDS_MAP.BASE]: CHAINLIST_CURRENCY_SYMBOLS_MAP.BASE, + [CHAINLIST_CHAIN_IDS_MAP.ARBITRUM]: CHAINLIST_CURRENCY_SYMBOLS_MAP.ARBITRUM, + [CHAINLIST_CHAIN_IDS_MAP.LINEA_MAINNET]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.LINEA_MAINNET, + [CHAINLIST_CHAIN_IDS_MAP.MAINNET]: CHAINLIST_CURRENCY_SYMBOLS_MAP.ETH, + [CHAINLIST_CHAIN_IDS_MAP.OPBNB]: CHAINLIST_CURRENCY_SYMBOLS_MAP.OPBNB, + [CHAINLIST_CHAIN_IDS_MAP.OPTIMISM]: CHAINLIST_CURRENCY_SYMBOLS_MAP.OPTIMISM, + [CHAINLIST_CHAIN_IDS_MAP.POLYGON]: CHAINLIST_CURRENCY_SYMBOLS_MAP.MATIC, + [CHAINLIST_CHAIN_IDS_MAP.ZKSYNC_ERA]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.ZKSYNC_ERA, + [CHAINLIST_CHAIN_IDS_MAP.GOERLI]: + TEST_NETWORK_TICKER_MAP[NETWORK_TYPES.GOERLI], + [CHAINLIST_CHAIN_IDS_MAP.SEPOLIA]: + TEST_NETWORK_TICKER_MAP[NETWORK_TYPES.SEPOLIA], + [CHAINLIST_CHAIN_IDS_MAP.LINEA_GOERLI]: + TEST_NETWORK_TICKER_MAP[NETWORK_TYPES.LINEA_GOERLI], + [CHAINLIST_CHAIN_IDS_MAP.SCROLL]: CHAINLIST_CURRENCY_SYMBOLS_MAP.SCROLL, + [CHAINLIST_CHAIN_IDS_MAP.ZORA_MAINNET]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.ZORA_MAINNET, + [CHAINLIST_CHAIN_IDS_MAP.TAIKO_JOLNIR_L2_MAINNET]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.TAIKO_JOLNIR_L2_MAINNET, + [CHAINLIST_CHAIN_IDS_MAP.POLYGON_ZKEVM]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.POLYGON_ZKEVM, + [CHAINLIST_CHAIN_IDS_MAP.FANTOM_OPERA]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.FANTOM_OPERA, + [CHAINLIST_CHAIN_IDS_MAP.CELO_MAINNET]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.CELO_MAINNET, + [CHAINLIST_CHAIN_IDS_MAP.ARBITRUM_NOVA]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.ARBITRUM_NOVA, + [CHAINLIST_CHAIN_IDS_MAP.MANTLE]: CHAINLIST_CURRENCY_SYMBOLS_MAP.MANTLE, + [CHAINLIST_CHAIN_IDS_MAP.GNOSIS]: CHAINLIST_CURRENCY_SYMBOLS_MAP.GNOSIS, + [CHAINLIST_CHAIN_IDS_MAP.CORE_BLOCKCHAIN_MAINNET]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.CORE_BLOCKCHAIN_MAINNET, + [CHAINLIST_CHAIN_IDS_MAP.MANTA_PACIFIC_MAINNET]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.MANTA_PACIFIC_MAINNET, + [CHAINLIST_CHAIN_IDS_MAP.PULSECHAIN_MAINNET]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.PULSECHAIN_MAINNET, + [CHAINLIST_CHAIN_IDS_MAP.MOONBEAM]: CHAINLIST_CURRENCY_SYMBOLS_MAP.MOONBEAM, + [CHAINLIST_CHAIN_IDS_MAP.FUSE_GOLD_MAINNET]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.FUSE_GOLD_MAINNET, + [CHAINLIST_CHAIN_IDS_MAP.KAVA_EVM]: CHAINLIST_CURRENCY_SYMBOLS_MAP.KAVA_EVM, + [CHAINLIST_CHAIN_IDS_MAP.DFK_CHAIN]: CHAINLIST_CURRENCY_SYMBOLS_MAP.DFK_CHAIN, + [CHAINLIST_CHAIN_IDS_MAP.HARMONY_MAINNET_SHARD_0]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.HARMONY_MAINNET_SHARD_0, + [CHAINLIST_CHAIN_IDS_MAP.PGN_PUBLIC_GOODS_NETWORK]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.PGN_PUBLIC_GOODS_NETWORK, + [CHAINLIST_CHAIN_IDS_MAP.LIGHTLINK_PHOENIX_MAINNET]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.LIGHTLINK_PHOENIX_MAINNET, + [CHAINLIST_CHAIN_IDS_MAP.NEAR_AURORA_MAINNET]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.NEAR_AURORA_MAINNET, + [CHAINLIST_CHAIN_IDS_MAP.KROMA_MAINNET]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.KROMA_MAINNET, + [CHAINLIST_CHAIN_IDS_MAP.NEBULA_MAINNET]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.NEBULA_MAINNET, + [CHAINLIST_CHAIN_IDS_MAP.KLAYTN_MAINNET_CYPRESS]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.KLAYTN_MAINNET_CYPRESS, + [CHAINLIST_CHAIN_IDS_MAP.MOONRIVER]: CHAINLIST_CURRENCY_SYMBOLS_MAP.MOONRIVER, + [CHAINLIST_CHAIN_IDS_MAP.ENDURANCE_SMART_CHAIN_MAINNET]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.ENDURANCE_SMART_CHAIN_MAINNET, + [CHAINLIST_CHAIN_IDS_MAP.CRONOS_MAINNET_BETA]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.CRONOS_MAINNET_BETA, + [CHAINLIST_CHAIN_IDS_MAP.FLARE_MAINNET]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.FLARE_MAINNET, + [CHAINLIST_CHAIN_IDS_MAP.KCC_MAINNET]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.KCC_MAINNET, + [CHAINLIST_CHAIN_IDS_MAP.SHARDEUM_SPHINX_1X]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.SHARDEUM_SPHINX_1X, + [CHAINLIST_CHAIN_IDS_MAP.ETHEREUM_CLASSIC_MAINNET]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.ETHEREUM_CLASSIC_MAINNET, + [CHAINLIST_CHAIN_IDS_MAP.HAQQ_NETWORK]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.HAQQ_NETWORK, + [CHAINLIST_CHAIN_IDS_MAP.SHARDEUM_LIBERTY_2X]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.SHARDEUM_LIBERTY_2X, + [CHAINLIST_CHAIN_IDS_MAP.BLACKFORT_EXCHANGE_NETWORK]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.BLACKFORT_EXCHANGE_NETWORK, + [CHAINLIST_CHAIN_IDS_MAP.CONFLUX_ESPACE]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.CONFLUX_ESPACE, + [CHAINLIST_CHAIN_IDS_MAP.FUSE_MAINNET]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.FUSE_MAINNET, + [CHAINLIST_CHAIN_IDS_MAP.CANTO]: CHAINLIST_CURRENCY_SYMBOLS_MAP.CANTO, + [CHAINLIST_CHAIN_IDS_MAP.SHIB_MAINNET]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.SHIB_MAINNET, + [CHAINLIST_CHAIN_IDS_MAP.OKXCHAIN_MAINNET]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.OKXCHAIN_MAINNET, + [CHAINLIST_CHAIN_IDS_MAP.ZKATANA]: CHAINLIST_CURRENCY_SYMBOLS_MAP.ZKATANA, + [CHAINLIST_CHAIN_IDS_MAP.DEXALOT_SUBNET]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.DEXALOT_SUBNET, + [CHAINLIST_CHAIN_IDS_MAP.ASTAR]: CHAINLIST_CURRENCY_SYMBOLS_MAP.ASTAR, + [CHAINLIST_CHAIN_IDS_MAP.EVMOS]: CHAINLIST_CURRENCY_SYMBOLS_MAP.EVMOS, + [CHAINLIST_CHAIN_IDS_MAP.BAHAMUT_MAINNET]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.BAHAMUT_MAINNET, + [CHAINLIST_CHAIN_IDS_MAP.SONGBIRD_CANARY_NETWORK]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.SONGBIRD_CANARY_NETWORK, + [CHAINLIST_CHAIN_IDS_MAP.STEP_NETWORK]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.STEP_NETWORK, + [CHAINLIST_CHAIN_IDS_MAP.VELAS_EVM_MAINNET]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.VELAS_EVM_MAINNET, + [CHAINLIST_CHAIN_IDS_MAP.Q_MAINNET]: CHAINLIST_CURRENCY_SYMBOLS_MAP.Q_MAINNET, + [CHAINLIST_CHAIN_IDS_MAP.TELOS_EVM_MAINNET]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.TELOS_EVM_MAINNET, + [CHAINLIST_CHAIN_IDS_MAP.TENET]: CHAINLIST_CURRENCY_SYMBOLS_MAP.TENET, + [CHAINLIST_CHAIN_IDS_MAP.DOGECHAIN_MAINNET]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.DOGECHAIN_MAINNET, + [CHAINLIST_CHAIN_IDS_MAP.OASYS_MAINNET]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.OASYS_MAINNET, + [CHAINLIST_CHAIN_IDS_MAP.HUOBI_ECO_CHAIN_MAINNET]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.HUOBI_ECO_CHAIN_MAINNET, + [CHAINLIST_CHAIN_IDS_MAP.ACALA_NETWORK]: + CHAINLIST_CURRENCY_SYMBOLS_MAP.ACALA_NETWORK, } as const; export const CHAIN_ID_TO_TYPE_MAP = { diff --git a/ui/hooks/useAccountTotalFiatBalance.test.js b/ui/hooks/useAccountTotalFiatBalance.test.js index 791548395593..70dd78211f7b 100644 --- a/ui/hooks/useAccountTotalFiatBalance.test.js +++ b/ui/hooks/useAccountTotalFiatBalance.test.js @@ -131,7 +131,7 @@ describe('useAccountTotalFiatBalance', () => { orderedTokenList: [ { fiatBalance: '1.85', - iconUrl: './images/optimism.svg', + iconUrl: './images/eth_logo.png', symbol: 'ETH', }, { From 5c0f6bc4a2ff1ad527a9692b6fd9d7b151ea7980 Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Fri, 15 Dec 2023 16:35:33 -0330 Subject: [PATCH 4/5] 1708 chainid symbol map part 2 (#22300) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** ### **Before** ### **After** ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've clearly explained what problem this PR is solving and how it is solved. - [ ] I've linked related issues - [ ] I've included manual testing steps - [ ] I've included screenshots/recordings if applicable - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. - [ ] I’ve properly set the pull request status: - [ ] In case it's not yet "ready for review", I've set it to "draft". - [ ] In case it's "ready for review", I've changed it from "draft" to "non-draft". ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --- ui/hooks/useIsOriginalNativeTokenSymbol.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ui/hooks/useIsOriginalNativeTokenSymbol.js b/ui/hooks/useIsOriginalNativeTokenSymbol.js index 8d3cbacc15e4..f13048f446e1 100644 --- a/ui/hooks/useIsOriginalNativeTokenSymbol.js +++ b/ui/hooks/useIsOriginalNativeTokenSymbol.js @@ -1,7 +1,7 @@ import { useEffect, useState } from 'react'; import { useSelector } from 'react-redux'; import fetchWithCache from '../../shared/lib/fetch-with-cache'; -import { BUILT_IN_NETWORKS } from '../../shared/constants/network'; +import { CHAIN_ID_TO_CURRENCY_SYMBOL_MAP } from '../../shared/constants/network'; import { DAY } from '../../shared/constants/time'; import { useSafeChainsListValidationSelector } from '../selectors'; @@ -18,10 +18,9 @@ export function useIsOriginalNativeTokenSymbol(chainId, ticker, type) { return; } - const matchedSymbolBuiltInNetwork = - BUILT_IN_NETWORKS[type]?.ticker ?? null; - if (matchedSymbolBuiltInNetwork) { - setIsOriginalNativeSymbol(matchedSymbolBuiltInNetwork === ticker); + const mappedCurrencySymbol = CHAIN_ID_TO_CURRENCY_SYMBOL_MAP[chainId]; + if (mappedCurrencySymbol) { + setIsOriginalNativeSymbol(mappedCurrencySymbol === ticker); return; } From 181f89cf67021f0b787379d7e796621c234a5dd3 Mon Sep 17 00:00:00 2001 From: Victor Thomas <10986371+vthomas13@users.noreply.github.com> Date: Fri, 15 Dec 2023 17:20:36 -0500 Subject: [PATCH 5/5] resolving map collision for token images --- shared/constants/network.ts | 19 ++++---- .../account-list-item.test.js.snap | 6 +-- .../send/__snapshots__/send.test.js.snap | 30 +++---------- .../useIsOriginalNativeTokenSymbol.test.js | 44 ++++++++++++++++--- ui/selectors/selectors.js | 7 ++- 5 files changed, 57 insertions(+), 49 deletions(-) diff --git a/shared/constants/network.ts b/shared/constants/network.ts index d617764812b6..18a0ab087d69 100644 --- a/shared/constants/network.ts +++ b/shared/constants/network.ts @@ -144,6 +144,7 @@ export const CHAIN_IDS = { CRONOS: '0x19', GNOSIS: '0x64', ZKSYNC_ERA: '0x144', + TEST_ETH: '0x539', } as const; const CHAINLIST_CHAIN_IDS_MAP = { @@ -612,15 +613,15 @@ export const CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP = { [CHAIN_IDS.LINEA_MAINNET]: NETWORK_TYPES.LINEA_MAINNET, } as const; -export const NATIVE_CURRENCY_TOKEN_IMAGE_MAP = { - [CURRENCY_SYMBOLS.ETH]: ETH_TOKEN_IMAGE_URL, - [CURRENCY_SYMBOLS.TEST_ETH]: TEST_ETH_TOKEN_IMAGE_URL, - [CURRENCY_SYMBOLS.BNB]: BNB_TOKEN_IMAGE_URL, - [CURRENCY_SYMBOLS.MATIC]: MATIC_TOKEN_IMAGE_URL, - [CURRENCY_SYMBOLS.AVALANCHE]: AVAX_TOKEN_IMAGE_URL, - [CURRENCY_SYMBOLS.OPTIMISM]: OPTIMISM_TOKEN_IMAGE_URL, - [CURRENCY_SYMBOLS.CELO]: CELO_TOKEN_IMAGE_URL, - [CURRENCY_SYMBOLS.GNOSIS]: GNOSIS_TOKEN_IMAGE_URL, +export const CHAIN_ID_TOKEN_IMAGE_MAP = { + [CHAIN_IDS.MAINNET]: ETH_TOKEN_IMAGE_URL, + [CHAIN_IDS.TEST_ETH]: TEST_ETH_TOKEN_IMAGE_URL, + [CHAIN_IDS.BSC]: BNB_TOKEN_IMAGE_URL, + [CHAIN_IDS.POLYGON]: MATIC_TOKEN_IMAGE_URL, + [CHAIN_IDS.AVALANCHE]: AVAX_TOKEN_IMAGE_URL, + [CHAIN_IDS.OPTIMISM]: OPTIMISM_TOKEN_IMAGE_URL, + [CHAIN_IDS.CELO]: CELO_TOKEN_IMAGE_URL, + [CHAIN_IDS.GNOSIS]: GNOSIS_TOKEN_IMAGE_URL, } as const; export const INFURA_BLOCKED_KEY = 'countryBlocked'; diff --git a/ui/components/multichain/account-list-item/__snapshots__/account-list-item.test.js.snap b/ui/components/multichain/account-list-item/__snapshots__/account-list-item.test.js.snap index 55f9a20757e8..ec4e56c9772d 100644 --- a/ui/components/multichain/account-list-item/__snapshots__/account-list-item.test.js.snap +++ b/ui/components/multichain/account-list-item/__snapshots__/account-list-item.test.js.snap @@ -105,11 +105,7 @@ exports[`AccountListItem renders AccountListItem component and shows account nam
- ETH logo + E
- ETH logo + E
- ETH logo + E
- ETH logo + E
- ETH logo + E
- ETH logo + E
{ // Expect the hook to return true when the native symbol matches the ticker expect(result.result.current).toBe(true); - expect(spyFetch).toHaveBeenCalled(); + expect(spyFetch).not.toHaveBeenCalled(); }); it('should return the correct value when the native symbol does not match the ticker', async () => { @@ -75,7 +75,7 @@ describe('useNativeTokenFiatAmount', () => { await act(async () => { result = renderHook(() => - useIsOriginalNativeTokenSymbol('0x1', 'ETH', 'mainnet'), + useIsOriginalNativeTokenSymbol('0x13a', 'FIL', 'mainnet'), ); }); @@ -97,7 +97,7 @@ describe('useNativeTokenFiatAmount', () => { await act(async () => { result = renderHook(() => - useIsOriginalNativeTokenSymbol('0x1', 'ETH', 'mainnet'), + useIsOriginalNativeTokenSymbol('0x13a', 'FIL', 'mainnet'), ); }); @@ -106,7 +106,7 @@ describe('useNativeTokenFiatAmount', () => { expect(spyFetch).toHaveBeenCalled(); }); - it('should return the correct symbol from build Network', async () => { + it('should return the correct value when the chainId is in the CHAIN_ID_TO_CURRENCY_SYMBOL_MAP', async () => { useSelector.mockImplementation(generateUseSelectorRouter(true)); // Mock the safeChainsList response with a different native symbol @@ -128,14 +128,46 @@ describe('useNativeTokenFiatAmount', () => { await act(async () => { result = renderHook(() => - useIsOriginalNativeTokenSymbol('0x1', 'GoerliETH', 'goerli'), + useIsOriginalNativeTokenSymbol('0x5', 'GoerliETH', 'goerli'), ); }); - + // expect this to pass because the chainId is in the CHAIN_ID_TO_CURRENCY_SYMBOL_MAP expect(result.result.current).toBe(true); + // expect that the chainlist API was not called expect(spyFetch).not.toHaveBeenCalled(); }); + it('should return the correct value when the chainId is not in the CHAIN_ID_TO_CURRENCY_SYMBOL_MAP', async () => { + useSelector.mockImplementation(generateUseSelectorRouter(true)); + // Mock the safeChainsList response + const safeChainsList = [ + { + chainId: 314, + nativeCurrency: { + symbol: 'FIL', + }, + }, + ]; + + // Mock the fetchWithCache function to return the safeChainsList + const spyFetch = jest + .spyOn(fetchWithCacheModule, 'default') + .mockResolvedValue(safeChainsList); + + let result; + + await act(async () => { + result = renderHook(() => + useIsOriginalNativeTokenSymbol('0x13a', 'FIL', 'mainnet'), + ); + }); + + // Expect the hook to return true when the native symbol matches the ticker + expect(result.result.current).toBe(true); + // Expect the chainslist API to have been called + expect(spyFetch).toHaveBeenCalled(); + }); + it('should return true if chain safe validation is disabled', async () => { useSelector.mockImplementation(generateUseSelectorRouter(false)); // Mock the safeChainsList response with a different native symbol diff --git a/ui/selectors/selectors.js b/ui/selectors/selectors.js index ef14673829f5..09cb7628c3f0 100644 --- a/ui/selectors/selectors.js +++ b/ui/selectors/selectors.js @@ -13,7 +13,6 @@ import { TransactionStatus } from '@metamask/transaction-controller'; import { addHexPrefix } from '../../app/scripts/lib/util'; import { TEST_CHAINS, - NATIVE_CURRENCY_TOKEN_IMAGE_MAP, BUYABLE_CHAINS_MAP, MAINNET_DISPLAY_NAME, BSC_DISPLAY_NAME, @@ -33,6 +32,7 @@ import { LINEA_MAINNET_DISPLAY_NAME, LINEA_MAINNET_TOKEN_IMAGE_URL, CHAIN_ID_TO_NETWORK_IMAGE_URL_MAP, + CHAIN_ID_TOKEN_IMAGE_MAP, } from '../../shared/constants/network'; import { WebHIDConnectedStatuses, @@ -66,7 +66,6 @@ import { STATIC_MAINNET_TOKEN_LIST } from '../../shared/constants/tokens'; import { DAY } from '../../shared/constants/time'; import { TERMS_OF_USE_LAST_UPDATED } from '../../shared/constants/terms'; import { - getNativeCurrency, getProviderConfig, getConversionRate, isNotEIP1559Network, @@ -945,8 +944,8 @@ export function getIsBuyableChain(state) { return Object.keys(BUYABLE_CHAINS_MAP).includes(chainId); } export function getNativeCurrencyImage(state) { - const nativeCurrency = getNativeCurrency(state)?.toUpperCase(); - return NATIVE_CURRENCY_TOKEN_IMAGE_MAP[nativeCurrency]; + const chainId = getCurrentChainId(state); + return CHAIN_ID_TOKEN_IMAGE_MAP[chainId]; } export function getNextSuggestedNonce(state) {