Skip to content

Commit 53ddea6

Browse files
authored
chore: add network names for caip chainids (#31372)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** Some components use hex and some use caip so adding network name mappings for both chainId formats <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/31372?quickstart=1) ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] 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/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **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.
1 parent c4fd0d2 commit 53ddea6

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

shared/constants/bridge.ts

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
import { toEvmCaipChainId } from '@metamask/multichain-network-controller';
12
import {
23
BRIDGE_DEV_API_BASE_URL,
34
BRIDGE_PROD_API_BASE_URL,
45
} from '@metamask/bridge-controller';
56
import { MultichainNetworks } from './multichain/networks';
67
import { CHAIN_IDS, NETWORK_TO_NAME_MAP } from './network';
78

8-
// TODO read from feature flags
9-
export const ALLOWED_BRIDGE_CHAIN_IDS = [
9+
const ALLOWED_MULTICHAIN_BRIDGE_CHAIN_IDS = [
10+
///: BEGIN:ONLY_INCLUDE_IF(solana-swaps)
11+
MultichainNetworks.SOLANA,
12+
///: END:ONLY_INCLUDE_IF
13+
];
14+
15+
const ALLOWED_EVM_BRIDGE_CHAIN_IDS = [
1016
CHAIN_IDS.MAINNET,
1117
CHAIN_IDS.BSC,
1218
CHAIN_IDS.POLYGON,
@@ -16,12 +22,25 @@ export const ALLOWED_BRIDGE_CHAIN_IDS = [
1622
CHAIN_IDS.ARBITRUM,
1723
CHAIN_IDS.LINEA_MAINNET,
1824
CHAIN_IDS.BASE,
25+
];
26+
27+
export const ALLOWED_BRIDGE_CHAIN_IDS = [
28+
...ALLOWED_MULTICHAIN_BRIDGE_CHAIN_IDS,
29+
...ALLOWED_EVM_BRIDGE_CHAIN_IDS,
30+
CHAIN_IDS.LINEA_MAINNET,
31+
CHAIN_IDS.BASE,
1932
///: BEGIN:ONLY_INCLUDE_IF(solana-swaps)
2033
MultichainNetworks.SOLANA,
2134
///: END:ONLY_INCLUDE_IF
2235
];
2336

24-
export type AllowedBridgeChainIds = (typeof ALLOWED_BRIDGE_CHAIN_IDS)[number];
37+
const ALLOWED_BRIDGE_CHAIN_IDS_IN_CAIP = ALLOWED_EVM_BRIDGE_CHAIN_IDS.map(
38+
toEvmCaipChainId,
39+
).concat(ALLOWED_MULTICHAIN_BRIDGE_CHAIN_IDS);
40+
41+
export type AllowedBridgeChainIds =
42+
| (typeof ALLOWED_BRIDGE_CHAIN_IDS)[number]
43+
| (typeof ALLOWED_BRIDGE_CHAIN_IDS_IN_CAIP)[number];
2544

2645
export const BRIDGE_API_BASE_URL = process.env.BRIDGE_USE_DEV_APIS
2746
? BRIDGE_DEV_API_BASE_URL
@@ -41,6 +60,17 @@ export const NETWORK_TO_SHORT_NETWORK_NAME_MAP: Record<
4160
[CHAIN_IDS.OPTIMISM]: NETWORK_TO_NAME_MAP[CHAIN_IDS.OPTIMISM],
4261
[CHAIN_IDS.ZKSYNC_ERA]: 'ZkSync Era',
4362
[CHAIN_IDS.BASE]: 'Base',
63+
[toEvmCaipChainId(CHAIN_IDS.BASE)]: 'Base',
64+
[toEvmCaipChainId(CHAIN_IDS.LINEA_MAINNET)]: 'Linea',
65+
[toEvmCaipChainId(CHAIN_IDS.POLYGON)]: NETWORK_TO_NAME_MAP[CHAIN_IDS.POLYGON],
66+
[toEvmCaipChainId(CHAIN_IDS.AVALANCHE)]: 'Avalanche',
67+
[toEvmCaipChainId(CHAIN_IDS.BSC)]: NETWORK_TO_NAME_MAP[CHAIN_IDS.BSC],
68+
[toEvmCaipChainId(CHAIN_IDS.ARBITRUM)]:
69+
NETWORK_TO_NAME_MAP[CHAIN_IDS.ARBITRUM],
70+
[toEvmCaipChainId(CHAIN_IDS.OPTIMISM)]:
71+
NETWORK_TO_NAME_MAP[CHAIN_IDS.OPTIMISM],
72+
[toEvmCaipChainId(CHAIN_IDS.ZKSYNC_ERA)]: 'ZkSync Era',
73+
[toEvmCaipChainId(CHAIN_IDS.BASE)]: 'Base',
4474
///: BEGIN:ONLY_INCLUDE_IF(solana-swaps)
4575
[MultichainNetworks.SOLANA]: 'Solana',
4676
[MultichainNetworks.SOLANA_TESTNET]: 'Solana Testnet',

0 commit comments

Comments
 (0)