@metamask-previews/network-enablement-controller 6.0.5-preview-8bfa290fb → 7.0.0-preview-97d6b86c0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -2
- package/dist/{NetworkEnablementController-method-action-types.d.mts → NetworkEnablementController-method-action-types.d.ts} +2 -2
- package/dist/NetworkEnablementController-method-action-types.d.ts.map +1 -0
- package/dist/{NetworkEnablementController-method-action-types.mjs → NetworkEnablementController-method-action-types.js} +1 -1
- package/dist/NetworkEnablementController-method-action-types.js.map +1 -0
- package/dist/{NetworkEnablementController.d.cts → NetworkEnablementController.d.ts} +10 -10
- package/dist/NetworkEnablementController.d.ts.map +1 -0
- package/dist/{NetworkEnablementController.mjs → NetworkEnablementController.js} +167 -131
- package/dist/NetworkEnablementController.js.map +1 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/{constants.mjs → constants.js} +1 -1
- package/dist/constants.js.map +1 -0
- package/dist/{index.d.cts → index.d.ts} +6 -6
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/{selectors.d.cts → selectors.d.ts} +18 -30
- package/dist/selectors.d.ts.map +1 -0
- package/dist/{selectors.mjs → selectors.js} +4 -4
- package/dist/selectors.js.map +1 -0
- package/dist/services/{Slip44Service.d.cts → Slip44Service.d.ts} +1 -1
- package/dist/services/Slip44Service.d.ts.map +1 -0
- package/dist/services/Slip44Service.js +167 -0
- package/dist/services/Slip44Service.js.map +1 -0
- package/dist/services/{index.d.cts → index.d.ts} +2 -2
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/{index.mjs → index.js} +2 -2
- package/dist/services/index.js.map +1 -0
- package/dist/{utils.d.mts → utils.d.ts} +3 -3
- package/dist/utils.d.ts.map +1 -0
- package/dist/{utils.mjs → utils.js} +4 -4
- package/dist/utils.js.map +1 -0
- package/package.json +19 -23
- package/dist/NetworkEnablementController-method-action-types.cjs +0 -7
- package/dist/NetworkEnablementController-method-action-types.cjs.map +0 -1
- package/dist/NetworkEnablementController-method-action-types.d.cts +0 -185
- package/dist/NetworkEnablementController-method-action-types.d.cts.map +0 -1
- package/dist/NetworkEnablementController-method-action-types.d.mts.map +0 -1
- package/dist/NetworkEnablementController-method-action-types.mjs.map +0 -1
- package/dist/NetworkEnablementController.cjs +0 -590
- package/dist/NetworkEnablementController.cjs.map +0 -1
- package/dist/NetworkEnablementController.d.cts.map +0 -1
- package/dist/NetworkEnablementController.d.mts +0 -234
- package/dist/NetworkEnablementController.d.mts.map +0 -1
- package/dist/NetworkEnablementController.mjs.map +0 -1
- package/dist/constants.cjs +0 -22
- package/dist/constants.cjs.map +0 -1
- package/dist/constants.d.cts +0 -3
- package/dist/constants.d.cts.map +0 -1
- package/dist/constants.d.mts +0 -3
- package/dist/constants.d.mts.map +0 -1
- package/dist/constants.mjs.map +0 -1
- package/dist/index.cjs +0 -18
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts +0 -6
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -4
- package/dist/index.mjs.map +0 -1
- package/dist/selectors.cjs +0 -87
- package/dist/selectors.cjs.map +0 -1
- package/dist/selectors.d.cts.map +0 -1
- package/dist/selectors.d.mts +0 -280
- package/dist/selectors.d.mts.map +0 -1
- package/dist/selectors.mjs.map +0 -1
- package/dist/services/Slip44Service.cjs +0 -182
- package/dist/services/Slip44Service.cjs.map +0 -1
- package/dist/services/Slip44Service.d.cts.map +0 -1
- package/dist/services/Slip44Service.d.mts +0 -63
- package/dist/services/Slip44Service.d.mts.map +0 -1
- package/dist/services/Slip44Service.mjs +0 -175
- package/dist/services/Slip44Service.mjs.map +0 -1
- package/dist/services/index.cjs +0 -11
- package/dist/services/index.cjs.map +0 -1
- package/dist/services/index.d.cts.map +0 -1
- package/dist/services/index.d.mts +0 -5
- package/dist/services/index.d.mts.map +0 -1
- package/dist/services/index.mjs.map +0 -1
- package/dist/utils.cjs +0 -62
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.d.cts +0 -36
- package/dist/utils.d.cts.map +0 -1
- package/dist/utils.d.mts.map +0 -1
- package/dist/utils.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,10 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [7.0.0]
|
|
11
|
+
|
|
10
12
|
### Changed
|
|
11
13
|
|
|
12
|
-
-
|
|
14
|
+
- **BREAKING:** Drop CommonJS support ([#9536](https://github.com/MetaMask/core/pull/9536))
|
|
15
|
+
- This package is now ESM-only, but can still be used in CommonJS projects via `require(esm)` in modern Node.js versions (22+), or dynamic imports in older Node.js versions.
|
|
16
|
+
- **BREAKING:** Bump minimum Node.js version to 22 ([#9976](https://github.com/MetaMask/core/pull/9976))
|
|
17
|
+
- **BREAKING:** Bump TypeScript target to ES2022 ([#10019](https://github.com/MetaMask/core/pull/10019))
|
|
18
|
+
- This package now ships ES2022 code, requiring a compatible modern environment or bundler configuration to consume.
|
|
19
|
+
- Bump `@metamask/transaction-controller` from `^69.6.1` to `^70.0.0` ([#10046](https://github.com/MetaMask/core/pull/10046), [#10080](https://github.com/MetaMask/core/pull/10080), [#10124](https://github.com/MetaMask/core/pull/10124), [#10160](https://github.com/MetaMask/core/pull/10160))
|
|
13
20
|
- Bump `@metamask/utils` from `^11.11.0` to `^11.12.0` ([#10076](https://github.com/MetaMask/core/pull/10076))
|
|
21
|
+
- Bump `@metamask/base-controller` from `^9.1.0` to `^10.0.0` ([#10160](https://github.com/MetaMask/core/pull/10160))
|
|
22
|
+
- Bump `@metamask/config-registry-controller` from `^3.1.0` to `^4.0.0` ([#10160](https://github.com/MetaMask/core/pull/10160))
|
|
23
|
+
- Bump `@metamask/controller-utils` from `^12.3.0` to `^13.0.0` ([#10160](https://github.com/MetaMask/core/pull/10160))
|
|
24
|
+
- Bump `@metamask/messenger` from `^2.0.0` to `^3.0.0` ([#10160](https://github.com/MetaMask/core/pull/10160))
|
|
25
|
+
- Bump `@metamask/multichain-network-controller` from `^3.2.4` to `^4.0.0` ([#10160](https://github.com/MetaMask/core/pull/10160))
|
|
26
|
+
- Bump `@metamask/network-controller` from `^36.0.0` to `^37.0.0` ([#10160](https://github.com/MetaMask/core/pull/10160))
|
|
14
27
|
|
|
15
28
|
## [6.0.5]
|
|
16
29
|
|
|
@@ -417,7 +430,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
417
430
|
|
|
418
431
|
- Initial release ([#6028](https://github.com/MetaMask/core/pull/6028))
|
|
419
432
|
|
|
420
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/network-enablement-controller@
|
|
433
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/network-enablement-controller@7.0.0...HEAD
|
|
434
|
+
[7.0.0]: https://github.com/MetaMask/core/compare/@metamask/network-enablement-controller@6.0.5...@metamask/network-enablement-controller@7.0.0
|
|
421
435
|
[6.0.5]: https://github.com/MetaMask/core/compare/@metamask/network-enablement-controller@6.0.4...@metamask/network-enablement-controller@6.0.5
|
|
422
436
|
[6.0.4]: https://github.com/MetaMask/core/compare/@metamask/network-enablement-controller@6.0.3...@metamask/network-enablement-controller@6.0.4
|
|
423
437
|
[6.0.3]: https://github.com/MetaMask/core/compare/@metamask/network-enablement-controller@6.0.2...@metamask/network-enablement-controller@6.0.3
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* This file is auto generated.
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
*/
|
|
5
|
-
import type { NetworkEnablementController } from
|
|
5
|
+
import type { NetworkEnablementController } from './NetworkEnablementController.js';
|
|
6
6
|
/**
|
|
7
7
|
* Enables or disables a network for the user.
|
|
8
8
|
*
|
|
@@ -182,4 +182,4 @@ export type NetworkEnablementControllerListPopularNetworksAction = {
|
|
|
182
182
|
* Union of all NetworkEnablementController action types.
|
|
183
183
|
*/
|
|
184
184
|
export type NetworkEnablementControllerMethodActions = NetworkEnablementControllerEnableNetworkAction | NetworkEnablementControllerEnableNetworkInNamespaceAction | NetworkEnablementControllerEnableAllPopularNetworksAction | NetworkEnablementControllerInitAction | NetworkEnablementControllerInitNativeAssetIdentifiersAction | NetworkEnablementControllerDisableNetworkAction | NetworkEnablementControllerRestoreEnabledNetworkMapAction | NetworkEnablementControllerIsNetworkEnabledAction | NetworkEnablementControllerListPopularEvmNetworksAction | NetworkEnablementControllerListPopularMultichainNetworksAction | NetworkEnablementControllerListPopularNetworksAction;
|
|
185
|
-
//# sourceMappingURL=NetworkEnablementController-method-action-types.d.
|
|
185
|
+
//# sourceMappingURL=NetworkEnablementController-method-action-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NetworkEnablementController-method-action-types.d.ts","sourceRoot":"","sources":["../src/NetworkEnablementController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAEpF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,2CAA2C,CAAC;IAClD,OAAO,EAAE,2BAA2B,CAAC,eAAe,CAAC,CAAC;CACvD,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,yDAAyD,GAAG;IACtE,IAAI,EAAE,sDAAsD,CAAC;IAC7D,OAAO,EAAE,2BAA2B,CAAC,0BAA0B,CAAC,CAAC;CAClE,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,yDAAyD,GAAG;IACtE,IAAI,EAAE,sDAAsD,CAAC;IAC7D,OAAO,EAAE,2BAA2B,CAAC,0BAA0B,CAAC,CAAC;CAClE,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,MAAM,qCA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GAC9C,yDAAyD,GACzD,yDAAyD,GACzD,qCAAqC,GACrC,2DAA2D,GAC3D,+CAA+C,GAC/C,yDAAyD,GACzD,iDAAiD,GACjD,uDAAuD,GACvD,8DAA8D,GAC9D,oDAAoD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NetworkEnablementController-method-action-types.js","sourceRoot":"","sources":["../src/NetworkEnablementController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { NetworkEnablementController } from './NetworkEnablementController.js';\n\n/**\n * Enables or disables a network for the user.\n *\n * This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network). The method will automatically convert Hex chain IDs\n * to CAIP-2 format internally. This dual parameter support allows for backward\n * compatibility with existing EVM chain ID formats while supporting newer\n * multi-chain standards.\n *\n * When enabling a non-popular network, this method will disable all other networks\n * to ensure only one network is active at a time (exclusive mode).\n *\n * @param chainId - The chain ID of the network to enable or disable. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n */\nexport type NetworkEnablementControllerEnableNetworkAction = {\n type: `NetworkEnablementController:enableNetwork`;\n handler: NetworkEnablementController['enableNetwork'];\n};\n\n/**\n * Enables a network for the user within a specific namespace.\n *\n * This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network) and enables it within the specified namespace.\n * The method validates that the chainId belongs to the specified namespace for safety.\n *\n * Before enabling the target network, this method disables all other networks\n * in the same namespace to ensure exclusive behavior within the namespace.\n *\n * @param chainId - The chain ID of the network to enable. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n * @param namespace - The CAIP namespace where the network should be enabled\n * @throws Error if the chainId's derived namespace doesn't match the provided namespace\n */\nexport type NetworkEnablementControllerEnableNetworkInNamespaceAction = {\n type: `NetworkEnablementController:enableNetworkInNamespace`;\n handler: NetworkEnablementController['enableNetworkInNamespace'];\n};\n\n/**\n * Enables all popular networks and Solana mainnet.\n *\n * This method first disables all networks across all namespaces, then enables\n * all networks defined in POPULAR_NETWORKS (EVM networks), Solana mainnet, and\n * Bitcoin mainnet. This provides exclusive behavior - only popular networks will\n * be enabled after calling this method.\n *\n * Popular networks that don't exist in NetworkController or MultichainNetworkController configurations will be skipped silently.\n */\nexport type NetworkEnablementControllerEnableAllPopularNetworksAction = {\n type: `NetworkEnablementController:enableAllPopularNetworks`;\n handler: NetworkEnablementController['enableAllPopularNetworks'];\n};\n\n/**\n * Initializes the network enablement state from network controller configurations.\n *\n * This method reads the current network configurations from both NetworkController\n * and MultichainNetworkController and syncs the enabled network map and nativeAssetIdentifiers accordingly.\n * It ensures proper namespace buckets exist for all configured networks and only\n * adds missing networks with a default value of false, preserving existing user settings.\n *\n * This method should be called after the NetworkController and MultichainNetworkController\n * have been initialized and their configurations are available.\n */\nexport type NetworkEnablementControllerInitAction = {\n type: `NetworkEnablementController:init`;\n handler: NetworkEnablementController['init'];\n};\n\n/**\n * Initializes the native asset identifiers from network configurations.\n * This method should be called from the client during controller initialization\n * to populate the nativeAssetIdentifiers state based on actual network configurations.\n *\n * @param networks - Array of network configurations with chainId and nativeCurrency\n * @example\n * ```typescript\n * const evmNetworks = Object.values(networkControllerState.networkConfigurationsByChainId)\n * .map(config => ({\n * chainId: toEvmCaipChainId(config.chainId),\n * nativeCurrency: config.nativeCurrency,\n * }));\n *\n * const multichainNetworks = Object.values(multichainState.multichainNetworkConfigurationsByChainId)\n * .map(config => ({\n * chainId: config.chainId,\n * nativeCurrency: config.nativeCurrency,\n * }));\n *\n * await controller.initNativeAssetIdentifiers([...evmNetworks, ...multichainNetworks]);\n * ```\n */\nexport type NetworkEnablementControllerInitNativeAssetIdentifiersAction = {\n type: `NetworkEnablementController:initNativeAssetIdentifiers`;\n handler: NetworkEnablementController['initNativeAssetIdentifiers'];\n};\n\n/**\n * Disables a network for the user.\n *\n * This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network). The method will automatically convert Hex chain IDs\n * to CAIP-2 format internally.\n *\n * Note: This method will prevent disabling the last remaining enabled network\n * to ensure at least one network is always available.\n *\n * @param chainId - The chain ID of the network to disable. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n */\nexport type NetworkEnablementControllerDisableNetworkAction = {\n type: `NetworkEnablementController:disableNetwork`;\n handler: NetworkEnablementController['disableNetwork'];\n};\n\n/**\n * Restores the enabled network map to a previously snapshotted state.\n *\n * Not a general merge API: only updates keys already present in the current\n * map. Missing snapshot values default to `false`. Intended for callers with\n * direct controller access (e.g. extension) to undo `#onAddNetwork` filter\n * switches when adding a network without changing the active selection.\n *\n * @param enabledNetworkMap - Previously snapshotted enabledNetworkMap.\n */\nexport type NetworkEnablementControllerRestoreEnabledNetworkMapAction = {\n type: `NetworkEnablementController:restoreEnabledNetworkMap`;\n handler: NetworkEnablementController['restoreEnabledNetworkMap'];\n};\n\n/**\n * Checks if a network is enabled.\n *\n * @param chainId - The chain ID of the network to check. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n * @returns True if the network is enabled, false otherwise\n */\nexport type NetworkEnablementControllerIsNetworkEnabledAction = {\n type: `NetworkEnablementController:isNetworkEnabled`;\n handler: NetworkEnablementController['isNetworkEnabled'];\n};\n\n/**\n * Returns popular EVM network chain IDs in hex form, restricted to networks\n * that exist in NetworkController (networkConfigurationsByChainId). Source is\n * the bundled `POPULAR_NETWORKS` unioned with registry-featured EVM chains.\n *\n * @returns Hex chain IDs for popular EVM networks that are configured.\n */\nexport type NetworkEnablementControllerListPopularEvmNetworksAction = {\n type: `NetworkEnablementController:listPopularEvmNetworks`;\n handler: NetworkEnablementController['listPopularEvmNetworks'];\n};\n\n/**\n * Returns popular multichain (Bitcoin, Solana, Tron, Stellar) mainnet chain IDs in\n * CAIP-2 form, restricted to networks that exist in MultichainNetworkController\n * (multichainNetworkConfigurationsByChainId).\n *\n * @returns CAIP-2 chain IDs for Bitcoin, Solana, Tron, and Stellar mainnets that are configured.\n */\nexport type NetworkEnablementControllerListPopularMultichainNetworksAction = {\n type: `NetworkEnablementController:listPopularMultichainNetworks`;\n handler: NetworkEnablementController['listPopularMultichainNetworks'];\n};\n\n/**\n * Returns the list of popular network chain IDs in CAIP-2 form, restricted to\n * networks that exist in NetworkController (networkConfigurationsByChainId) and\n * MultichainNetworkController (multichainNetworkConfigurationsByChainId). EVM\n * popular networks come from POPULAR_NETWORKS; multichain popular are Bitcoin,\n * Solana, Tron, and Stellar mainnets.\n *\n * @returns CAIP-2 chain IDs for popular EVM networks and multichain mainnets that are configured.\n */\nexport type NetworkEnablementControllerListPopularNetworksAction = {\n type: `NetworkEnablementController:listPopularNetworks`;\n handler: NetworkEnablementController['listPopularNetworks'];\n};\n\n/**\n * Union of all NetworkEnablementController action types.\n */\nexport type NetworkEnablementControllerMethodActions =\n | NetworkEnablementControllerEnableNetworkAction\n | NetworkEnablementControllerEnableNetworkInNamespaceAction\n | NetworkEnablementControllerEnableAllPopularNetworksAction\n | NetworkEnablementControllerInitAction\n | NetworkEnablementControllerInitNativeAssetIdentifiersAction\n | NetworkEnablementControllerDisableNetworkAction\n | NetworkEnablementControllerRestoreEnabledNetworkMapAction\n | NetworkEnablementControllerIsNetworkEnabledAction\n | NetworkEnablementControllerListPopularEvmNetworksAction\n | NetworkEnablementControllerListPopularMultichainNetworksAction\n | NetworkEnablementControllerListPopularNetworksAction;\n"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { BaseController } from
|
|
2
|
-
import type { ControllerGetStateAction, ControllerStateChangeEvent } from
|
|
3
|
-
import type { ConfigRegistryControllerGetStateAction } from
|
|
4
|
-
import type { Messenger } from
|
|
5
|
-
import type { MultichainNetworkControllerGetStateAction } from
|
|
6
|
-
import type { NetworkControllerGetStateAction, NetworkControllerNetworkAddedEvent, NetworkControllerNetworkRemovedEvent, NetworkControllerStateChangeEvent } from
|
|
7
|
-
import type { TransactionControllerTransactionSubmittedEvent } from
|
|
8
|
-
import type { CaipChainId, CaipNamespace, Hex } from
|
|
9
|
-
import type { NetworkEnablementControllerMethodActions } from
|
|
1
|
+
import { BaseController } from '@metamask/base-controller';
|
|
2
|
+
import type { ControllerGetStateAction, ControllerStateChangeEvent } from '@metamask/base-controller';
|
|
3
|
+
import type { ConfigRegistryControllerGetStateAction } from '@metamask/config-registry-controller';
|
|
4
|
+
import type { Messenger } from '@metamask/messenger';
|
|
5
|
+
import type { MultichainNetworkControllerGetStateAction } from '@metamask/multichain-network-controller';
|
|
6
|
+
import type { NetworkControllerGetStateAction, NetworkControllerNetworkAddedEvent, NetworkControllerNetworkRemovedEvent, NetworkControllerStateChangeEvent } from '@metamask/network-controller';
|
|
7
|
+
import type { TransactionControllerTransactionSubmittedEvent } from '@metamask/transaction-controller';
|
|
8
|
+
import type { CaipChainId, CaipNamespace, Hex } from '@metamask/utils';
|
|
9
|
+
import type { NetworkEnablementControllerMethodActions } from './NetworkEnablementController-method-action-types.js';
|
|
10
10
|
declare const controllerName = "NetworkEnablementController";
|
|
11
11
|
/**
|
|
12
12
|
* Information about an ordered network.
|
|
@@ -231,4 +231,4 @@ export declare class NetworkEnablementController extends BaseController<typeof c
|
|
|
231
231
|
listPopularNetworks(): CaipChainId[];
|
|
232
232
|
}
|
|
233
233
|
export {};
|
|
234
|
-
//# sourceMappingURL=NetworkEnablementController.d.
|
|
234
|
+
//# sourceMappingURL=NetworkEnablementController.d.ts.map
|
|
@@ -0,0 +1 @@
|
|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;;;;;OASG;IACH,wBAAwB,IAAI,IAAI,CAmF/B;IAED;;;;;;;;;;OAUG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAoE1B;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,0BAA0B,CAAC,QAAQ,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA6CzE;IAED;;;;;;;;;;;;;OAaG;IACH,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,WAAW,GAAG,IAAI,CAO/C;IAED;;;;;;;;;OASG;IACH,wBAAwB,CACtB,iBAAiB,EAAE,gCAAgC,CAAC,mBAAmB,CAAC,GACvE,IAAI,CAaN;IAED;;;;;;;OAOG;IACH,gBAAgB,CAAC,OAAO,EAAE,GAAG,GAAG,WAAW,GAAG,OAAO,CAIpD;IAyLD;;;;;;OAMG;IACH,sBAAsB,IAAI,GAAG,EAAE,CAQ9B;IAED;;;;;;OAMG;IACH,6BAA6B,IAAI,WAAW,EAAE,CAc7C;IAED;;;;;;;;OAQG;IACH,mBAAmB,IAAI,WAAW,EAAE,CAInC;CACF"}
|
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { BtcScope, SolScope, TrxScope, XlmScope } from "@metamask/keyring-api";
|
|
10
|
-
import { toEvmCaipChainId } from "@metamask/multichain-network-controller";
|
|
11
|
-
import { KnownCaipNamespace, parseCaipChainId } from "@metamask/utils";
|
|
12
|
-
import { POPULAR_NETWORKS } from "./constants.mjs";
|
|
13
|
-
import { Slip44Service } from "./services/index.mjs";
|
|
14
|
-
import { deriveKeys, isOnlyNetworkEnabledInNamespace } from "./utils.mjs";
|
|
1
|
+
import { BaseController } from '@metamask/base-controller';
|
|
2
|
+
import { BuiltInNetworkName, ChainId, toHex } from '@metamask/controller-utils';
|
|
3
|
+
import { BtcScope, SolScope, TrxScope, XlmScope } from '@metamask/keyring-api';
|
|
4
|
+
import { toEvmCaipChainId } from '@metamask/multichain-network-controller';
|
|
5
|
+
import { KnownCaipNamespace, parseCaipChainId } from '@metamask/utils';
|
|
6
|
+
import { POPULAR_NETWORKS } from './constants.js';
|
|
7
|
+
import { Slip44Service } from './services/index.js';
|
|
8
|
+
import { deriveKeys, isOnlyNetworkEnabledInNamespace } from './utils.js';
|
|
15
9
|
const controllerName = 'NetworkEnablementController';
|
|
16
10
|
const MESSENGER_EXPOSED_METHODS = [
|
|
17
11
|
'init',
|
|
@@ -120,14 +114,13 @@ export class NetworkEnablementController extends BaseController {
|
|
|
120
114
|
...state,
|
|
121
115
|
},
|
|
122
116
|
});
|
|
123
|
-
_NetworkEnablementController_instances.add(this);
|
|
124
117
|
messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
125
118
|
messenger.subscribe('NetworkController:networkAdded', ({ chainId }) => {
|
|
126
119
|
// eslint-disable-next-line no-void
|
|
127
|
-
void
|
|
120
|
+
void this.#onAddNetwork(chainId);
|
|
128
121
|
});
|
|
129
122
|
messenger.subscribe('NetworkController:networkRemoved', ({ chainId }) => {
|
|
130
|
-
|
|
123
|
+
this.#removeNetworkEntry(chainId);
|
|
131
124
|
});
|
|
132
125
|
}
|
|
133
126
|
/**
|
|
@@ -188,7 +181,7 @@ export class NetworkEnablementController extends BaseController {
|
|
|
188
181
|
}
|
|
189
182
|
this.update((state) => {
|
|
190
183
|
// Ensure the namespace bucket exists
|
|
191
|
-
|
|
184
|
+
this.#ensureNamespaceBucket(state, namespace);
|
|
192
185
|
// Disable all networks in the specified namespace first
|
|
193
186
|
if (state.enabledNetworkMap[namespace]) {
|
|
194
187
|
Object.keys(state.enabledNetworkMap[namespace]).forEach((key) => {
|
|
@@ -221,12 +214,12 @@ export class NetworkEnablementController extends BaseController {
|
|
|
221
214
|
const networkControllerState = this.messenger.call('NetworkController:getState');
|
|
222
215
|
const multichainState = this.messenger.call('MultichainNetworkController:getState');
|
|
223
216
|
// Enable all popular EVM networks that exist in NetworkController configurations
|
|
224
|
-
|
|
217
|
+
this.#getPopularEvmChainIds().forEach((chainId) => {
|
|
225
218
|
const { namespace, storageKey } = deriveKeys(chainId);
|
|
226
219
|
// Check if network exists in NetworkController configurations
|
|
227
220
|
if (networkControllerState.networkConfigurationsByChainId[chainId]) {
|
|
228
221
|
// Ensure namespace bucket exists
|
|
229
|
-
|
|
222
|
+
this.#ensureNamespaceBucket(state, namespace);
|
|
230
223
|
// Enable the network
|
|
231
224
|
state.enabledNetworkMap[namespace][storageKey] = true;
|
|
232
225
|
}
|
|
@@ -235,7 +228,7 @@ export class NetworkEnablementController extends BaseController {
|
|
|
235
228
|
const solanaKeys = deriveKeys(SolScope.Mainnet);
|
|
236
229
|
if (multichainState.multichainNetworkConfigurationsByChainId[SolScope.Mainnet]) {
|
|
237
230
|
// Ensure namespace bucket exists
|
|
238
|
-
|
|
231
|
+
this.#ensureNamespaceBucket(state, solanaKeys.namespace);
|
|
239
232
|
// Enable Solana mainnet
|
|
240
233
|
state.enabledNetworkMap[solanaKeys.namespace][solanaKeys.storageKey] =
|
|
241
234
|
true;
|
|
@@ -244,7 +237,7 @@ export class NetworkEnablementController extends BaseController {
|
|
|
244
237
|
const bitcoinKeys = deriveKeys(BtcScope.Mainnet);
|
|
245
238
|
if (multichainState.multichainNetworkConfigurationsByChainId[BtcScope.Mainnet]) {
|
|
246
239
|
// Ensure namespace bucket exists
|
|
247
|
-
|
|
240
|
+
this.#ensureNamespaceBucket(state, bitcoinKeys.namespace);
|
|
248
241
|
// Enable Bitcoin mainnet
|
|
249
242
|
state.enabledNetworkMap[bitcoinKeys.namespace][bitcoinKeys.storageKey] =
|
|
250
243
|
true;
|
|
@@ -253,14 +246,14 @@ export class NetworkEnablementController extends BaseController {
|
|
|
253
246
|
const tronKeys = deriveKeys(TrxScope.Mainnet);
|
|
254
247
|
if (multichainState.multichainNetworkConfigurationsByChainId[TrxScope.Mainnet]) {
|
|
255
248
|
// Ensure namespace bucket exists
|
|
256
|
-
|
|
249
|
+
this.#ensureNamespaceBucket(state, tronKeys.namespace);
|
|
257
250
|
// Enable Tron mainnet
|
|
258
251
|
state.enabledNetworkMap[tronKeys.namespace][tronKeys.storageKey] = true;
|
|
259
252
|
}
|
|
260
253
|
// Enable Stellar mainnet if it exists in MultichainNetworkController configurations
|
|
261
254
|
const stellarKeys = deriveKeys(XlmScope.Pubnet);
|
|
262
255
|
if (multichainState.multichainNetworkConfigurationsByChainId[XlmScope.Pubnet]) {
|
|
263
|
-
|
|
256
|
+
this.#ensureNamespaceBucket(state, stellarKeys.namespace);
|
|
264
257
|
state.enabledNetworkMap[stellarKeys.namespace][stellarKeys.storageKey] =
|
|
265
258
|
true;
|
|
266
259
|
}
|
|
@@ -303,11 +296,10 @@ export class NetworkEnablementController extends BaseController {
|
|
|
303
296
|
this.update((state) => {
|
|
304
297
|
// Initialize namespace buckets for EVM networks from NetworkController
|
|
305
298
|
Object.entries(networkControllerState.networkConfigurationsByChainId).forEach(([chainId]) => {
|
|
306
|
-
var _a;
|
|
307
299
|
const { namespace, storageKey } = deriveKeys(chainId);
|
|
308
|
-
|
|
300
|
+
this.#ensureNamespaceBucket(state, namespace);
|
|
309
301
|
// Only add network if it doesn't already exist in state (preserves user settings)
|
|
310
|
-
|
|
302
|
+
state.enabledNetworkMap[namespace][storageKey] ??= false;
|
|
311
303
|
});
|
|
312
304
|
// Apply nativeAssetIdentifier updates
|
|
313
305
|
for (const { caipChainId, identifier } of evmNativeAssetUpdates) {
|
|
@@ -315,11 +307,10 @@ export class NetworkEnablementController extends BaseController {
|
|
|
315
307
|
}
|
|
316
308
|
// Initialize namespace buckets for all networks from MultichainNetworkController
|
|
317
309
|
Object.keys(multichainState.multichainNetworkConfigurationsByChainId).forEach((chainId) => {
|
|
318
|
-
var _a;
|
|
319
310
|
const { namespace, storageKey } = deriveKeys(chainId);
|
|
320
|
-
|
|
311
|
+
this.#ensureNamespaceBucket(state, namespace);
|
|
321
312
|
// Only add network if it doesn't already exist in state (preserves user settings)
|
|
322
|
-
|
|
313
|
+
state.enabledNetworkMap[namespace][storageKey] ??= false;
|
|
323
314
|
});
|
|
324
315
|
});
|
|
325
316
|
}
|
|
@@ -441,6 +432,150 @@ export class NetworkEnablementController extends BaseController {
|
|
|
441
432
|
const { namespace, storageKey } = derivedKeys;
|
|
442
433
|
return this.state.enabledNetworkMap[namespace]?.[storageKey] ?? false;
|
|
443
434
|
}
|
|
435
|
+
/**
|
|
436
|
+
* Ensures that a namespace bucket exists in the state.
|
|
437
|
+
*
|
|
438
|
+
* This method creates the namespace entry in the enabledNetworkMap if it doesn't
|
|
439
|
+
* already exist. This is used to prepare the state structure before adding
|
|
440
|
+
* network entries.
|
|
441
|
+
*
|
|
442
|
+
* @param state - The current controller state
|
|
443
|
+
* @param ns - The CAIP namespace to ensure exists
|
|
444
|
+
*/
|
|
445
|
+
#ensureNamespaceBucket(state, ns) {
|
|
446
|
+
if (!state.enabledNetworkMap[ns]) {
|
|
447
|
+
state.enabledNetworkMap[ns] = {};
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Checks if popular networks mode is active (more than 2 popular networks enabled).
|
|
452
|
+
*
|
|
453
|
+
* This method counts how many networks defined in POPULAR_NETWORKS are currently
|
|
454
|
+
* enabled in the state and returns true if more than 2 are enabled. It only checks
|
|
455
|
+
* networks that actually exist in the NetworkController configurations.
|
|
456
|
+
*
|
|
457
|
+
* @returns True if more than 2 popular networks are enabled, false otherwise
|
|
458
|
+
*/
|
|
459
|
+
#isInPopularNetworksMode() {
|
|
460
|
+
// Get current network configurations to check which popular networks exist
|
|
461
|
+
const networkControllerState = this.messenger.call('NetworkController:getState');
|
|
462
|
+
// Count how many popular networks are enabled
|
|
463
|
+
const enabledPopularNetworksCount = this.#getPopularEvmChainIds().reduce((count, chainId) => {
|
|
464
|
+
// Only check networks that actually exist in NetworkController configurations
|
|
465
|
+
if (!networkControllerState.networkConfigurationsByChainId[chainId]) {
|
|
466
|
+
return count; // Skip networks that don't exist
|
|
467
|
+
}
|
|
468
|
+
const { namespace, storageKey } = deriveKeys(chainId);
|
|
469
|
+
const isEnabled = this.state.enabledNetworkMap[namespace]?.[storageKey];
|
|
470
|
+
return isEnabled ? count + 1 : count;
|
|
471
|
+
}, 0);
|
|
472
|
+
// Return true if more than 2 popular networks are enabled
|
|
473
|
+
return enabledPopularNetworksCount > 1;
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Removes a network entry from the state.
|
|
477
|
+
*
|
|
478
|
+
* This method is called when a network is removed from the system. It cleans up
|
|
479
|
+
* the network entry from both enabledNetworkMap and nativeAssetIdentifiers, and ensures that
|
|
480
|
+
* at least one network remains enabled.
|
|
481
|
+
*
|
|
482
|
+
* @param chainId - The chain ID to remove (Hex or CAIP-2 format)
|
|
483
|
+
*/
|
|
484
|
+
#removeNetworkEntry(chainId) {
|
|
485
|
+
const derivedKeys = deriveKeys(chainId);
|
|
486
|
+
const { namespace, storageKey, caipChainId } = derivedKeys;
|
|
487
|
+
this.update((state) => {
|
|
488
|
+
// fallback and enable ethereum mainnet
|
|
489
|
+
if (isOnlyNetworkEnabledInNamespace(this.state, derivedKeys)) {
|
|
490
|
+
state.enabledNetworkMap[namespace][ChainId[BuiltInNetworkName.Mainnet]] = true;
|
|
491
|
+
}
|
|
492
|
+
if (namespace in state.enabledNetworkMap) {
|
|
493
|
+
delete state.enabledNetworkMap[namespace][storageKey];
|
|
494
|
+
}
|
|
495
|
+
// Remove from nativeAssetIdentifiers as well
|
|
496
|
+
delete state.nativeAssetIdentifiers[caipChainId];
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Handles the addition of a new EVM network to the controller.
|
|
501
|
+
*
|
|
502
|
+
* @param chainId - The chain ID to add (Hex format)
|
|
503
|
+
*
|
|
504
|
+
* @description
|
|
505
|
+
* - If in popular networks mode (>2 popular networks enabled) AND adding a popular network:
|
|
506
|
+
* - Keep current selection (add but don't enable the new network)
|
|
507
|
+
* - Otherwise:
|
|
508
|
+
* - Switch to the newly added network (disable all others, enable this one)
|
|
509
|
+
* - Also updates the nativeAssetIdentifiers with the CAIP-19-like identifier
|
|
510
|
+
*/
|
|
511
|
+
async #onAddNetwork(chainId) {
|
|
512
|
+
const { namespace, storageKey, reference, caipChainId } = deriveKeys(chainId);
|
|
513
|
+
// Parse reference (decimal string from CAIP-2) to number for chainid.network lookup
|
|
514
|
+
const numericChainId = parseInt(reference, 10);
|
|
515
|
+
// EVM networks: use getEvmSlip44 (chainid.network data)
|
|
516
|
+
const slip44CoinType = await Slip44Service.getEvmSlip44(numericChainId);
|
|
517
|
+
this.update((state) => {
|
|
518
|
+
// Ensure the namespace bucket exists
|
|
519
|
+
this.#ensureNamespaceBucket(state, namespace);
|
|
520
|
+
// Check if popular networks mode is active (>2 popular networks enabled)
|
|
521
|
+
const inPopularNetworksMode = this.#isInPopularNetworksMode();
|
|
522
|
+
// Check if the network being added is a popular network
|
|
523
|
+
const isAddedNetworkPopular = this.#getPopularEvmChainIds().includes(chainId);
|
|
524
|
+
// Keep current selection only if in popular networks mode AND adding a popular network
|
|
525
|
+
const shouldKeepCurrentSelection = inPopularNetworksMode && isAddedNetworkPopular;
|
|
526
|
+
if (shouldKeepCurrentSelection) {
|
|
527
|
+
// Add the popular network but don't enable it (keep current selection)
|
|
528
|
+
state.enabledNetworkMap[namespace][storageKey] = true;
|
|
529
|
+
}
|
|
530
|
+
else {
|
|
531
|
+
// Switch to the newly added network (disable all others, enable this one)
|
|
532
|
+
Object.keys(state.enabledNetworkMap).forEach((ns) => {
|
|
533
|
+
Object.keys(state.enabledNetworkMap[ns]).forEach((key) => {
|
|
534
|
+
state.enabledNetworkMap[ns][key] = false;
|
|
535
|
+
});
|
|
536
|
+
});
|
|
537
|
+
// Enable the newly added network
|
|
538
|
+
state.enabledNetworkMap[namespace][storageKey] = true;
|
|
539
|
+
}
|
|
540
|
+
// Update nativeAssetIdentifiers with the CAIP-19-like identifier
|
|
541
|
+
state.nativeAssetIdentifiers[caipChainId] = buildNativeAssetIdentifier(caipChainId, slip44CoinType);
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Returns the hex chain IDs of EVM networks the config registry currently
|
|
546
|
+
* marks as "popular" (i.e. featured + active + non-testnet).
|
|
547
|
+
*
|
|
548
|
+
* @returns Hex chain IDs of registry-featured EVM networks.
|
|
549
|
+
*/
|
|
550
|
+
#getRegistryPopularEvmChainIds() {
|
|
551
|
+
const { configs: { networks }, } = this.messenger.call('ConfigRegistryController:getState');
|
|
552
|
+
return Object.values(networks).reduce((popularChains, network) => {
|
|
553
|
+
if (network.config.isFeatured &&
|
|
554
|
+
network.config.isActive &&
|
|
555
|
+
!network.config.isTestnet &&
|
|
556
|
+
network.chainId.startsWith('eip155:')) {
|
|
557
|
+
const hexChainId = toHex(parseCaipChainId(network.chainId).reference);
|
|
558
|
+
popularChains.push(hexChainId);
|
|
559
|
+
}
|
|
560
|
+
return popularChains;
|
|
561
|
+
}, []);
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Returns the set of popular EVM chain IDs using registry configs as primary source
|
|
565
|
+
* and the bundled `POPULAR_NETWORKS` as fallback. This ensures that the list of popular networks is always available,
|
|
566
|
+
* even if the registry is unavailable or doesn't have any featured networks.
|
|
567
|
+
*
|
|
568
|
+
* @returns De-duplicated hex chain IDs considered popular.
|
|
569
|
+
*/
|
|
570
|
+
#getPopularEvmChainIds() {
|
|
571
|
+
return [
|
|
572
|
+
...new Set([
|
|
573
|
+
// `toHex` is used to normalize chain IDs from the bundled POPULAR_NETWORKS.
|
|
574
|
+
...POPULAR_NETWORKS.map((chainId) => toHex(chainId)),
|
|
575
|
+
...this.#getRegistryPopularEvmChainIds(),
|
|
576
|
+
]),
|
|
577
|
+
];
|
|
578
|
+
}
|
|
444
579
|
/**
|
|
445
580
|
* Returns popular EVM network chain IDs in hex form, restricted to networks
|
|
446
581
|
* that exist in NetworkController (networkConfigurationsByChainId). Source is
|
|
@@ -450,7 +585,7 @@ export class NetworkEnablementController extends BaseController {
|
|
|
450
585
|
*/
|
|
451
586
|
listPopularEvmNetworks() {
|
|
452
587
|
const networkControllerState = this.messenger.call('NetworkController:getState');
|
|
453
|
-
return
|
|
588
|
+
return this.#getPopularEvmChainIds().filter((chainIdHex) => networkControllerState.networkConfigurationsByChainId[chainIdHex]);
|
|
454
589
|
}
|
|
455
590
|
/**
|
|
456
591
|
* Returns popular multichain (Bitcoin, Solana, Tron, Stellar) mainnet chain IDs in
|
|
@@ -484,103 +619,4 @@ export class NetworkEnablementController extends BaseController {
|
|
|
484
619
|
return [...evmCaip, ...this.listPopularMultichainNetworks()];
|
|
485
620
|
}
|
|
486
621
|
}
|
|
487
|
-
|
|
488
|
-
if (!state.enabledNetworkMap[ns]) {
|
|
489
|
-
state.enabledNetworkMap[ns] = {};
|
|
490
|
-
}
|
|
491
|
-
}, _NetworkEnablementController_isInPopularNetworksMode = function _NetworkEnablementController_isInPopularNetworksMode() {
|
|
492
|
-
// Get current network configurations to check which popular networks exist
|
|
493
|
-
const networkControllerState = this.messenger.call('NetworkController:getState');
|
|
494
|
-
// Count how many popular networks are enabled
|
|
495
|
-
const enabledPopularNetworksCount = __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_getPopularEvmChainIds).call(this).reduce((count, chainId) => {
|
|
496
|
-
// Only check networks that actually exist in NetworkController configurations
|
|
497
|
-
if (!networkControllerState.networkConfigurationsByChainId[chainId]) {
|
|
498
|
-
return count; // Skip networks that don't exist
|
|
499
|
-
}
|
|
500
|
-
const { namespace, storageKey } = deriveKeys(chainId);
|
|
501
|
-
const isEnabled = this.state.enabledNetworkMap[namespace]?.[storageKey];
|
|
502
|
-
return isEnabled ? count + 1 : count;
|
|
503
|
-
}, 0);
|
|
504
|
-
// Return true if more than 2 popular networks are enabled
|
|
505
|
-
return enabledPopularNetworksCount > 1;
|
|
506
|
-
}, _NetworkEnablementController_removeNetworkEntry = function _NetworkEnablementController_removeNetworkEntry(chainId) {
|
|
507
|
-
const derivedKeys = deriveKeys(chainId);
|
|
508
|
-
const { namespace, storageKey, caipChainId } = derivedKeys;
|
|
509
|
-
this.update((state) => {
|
|
510
|
-
// fallback and enable ethereum mainnet
|
|
511
|
-
if (isOnlyNetworkEnabledInNamespace(this.state, derivedKeys)) {
|
|
512
|
-
state.enabledNetworkMap[namespace][ChainId[BuiltInNetworkName.Mainnet]] = true;
|
|
513
|
-
}
|
|
514
|
-
if (namespace in state.enabledNetworkMap) {
|
|
515
|
-
delete state.enabledNetworkMap[namespace][storageKey];
|
|
516
|
-
}
|
|
517
|
-
// Remove from nativeAssetIdentifiers as well
|
|
518
|
-
delete state.nativeAssetIdentifiers[caipChainId];
|
|
519
|
-
});
|
|
520
|
-
}, _NetworkEnablementController_onAddNetwork =
|
|
521
|
-
/**
|
|
522
|
-
* Handles the addition of a new EVM network to the controller.
|
|
523
|
-
*
|
|
524
|
-
* @param chainId - The chain ID to add (Hex format)
|
|
525
|
-
*
|
|
526
|
-
* @description
|
|
527
|
-
* - If in popular networks mode (>2 popular networks enabled) AND adding a popular network:
|
|
528
|
-
* - Keep current selection (add but don't enable the new network)
|
|
529
|
-
* - Otherwise:
|
|
530
|
-
* - Switch to the newly added network (disable all others, enable this one)
|
|
531
|
-
* - Also updates the nativeAssetIdentifiers with the CAIP-19-like identifier
|
|
532
|
-
*/
|
|
533
|
-
async function _NetworkEnablementController_onAddNetwork(chainId) {
|
|
534
|
-
const { namespace, storageKey, reference, caipChainId } = deriveKeys(chainId);
|
|
535
|
-
// Parse reference (decimal string from CAIP-2) to number for chainid.network lookup
|
|
536
|
-
const numericChainId = parseInt(reference, 10);
|
|
537
|
-
// EVM networks: use getEvmSlip44 (chainid.network data)
|
|
538
|
-
const slip44CoinType = await Slip44Service.getEvmSlip44(numericChainId);
|
|
539
|
-
this.update((state) => {
|
|
540
|
-
// Ensure the namespace bucket exists
|
|
541
|
-
__classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, state, namespace);
|
|
542
|
-
// Check if popular networks mode is active (>2 popular networks enabled)
|
|
543
|
-
const inPopularNetworksMode = __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_isInPopularNetworksMode).call(this);
|
|
544
|
-
// Check if the network being added is a popular network
|
|
545
|
-
const isAddedNetworkPopular = __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_getPopularEvmChainIds).call(this).includes(chainId);
|
|
546
|
-
// Keep current selection only if in popular networks mode AND adding a popular network
|
|
547
|
-
const shouldKeepCurrentSelection = inPopularNetworksMode && isAddedNetworkPopular;
|
|
548
|
-
if (shouldKeepCurrentSelection) {
|
|
549
|
-
// Add the popular network but don't enable it (keep current selection)
|
|
550
|
-
state.enabledNetworkMap[namespace][storageKey] = true;
|
|
551
|
-
}
|
|
552
|
-
else {
|
|
553
|
-
// Switch to the newly added network (disable all others, enable this one)
|
|
554
|
-
Object.keys(state.enabledNetworkMap).forEach((ns) => {
|
|
555
|
-
Object.keys(state.enabledNetworkMap[ns]).forEach((key) => {
|
|
556
|
-
state.enabledNetworkMap[ns][key] = false;
|
|
557
|
-
});
|
|
558
|
-
});
|
|
559
|
-
// Enable the newly added network
|
|
560
|
-
state.enabledNetworkMap[namespace][storageKey] = true;
|
|
561
|
-
}
|
|
562
|
-
// Update nativeAssetIdentifiers with the CAIP-19-like identifier
|
|
563
|
-
state.nativeAssetIdentifiers[caipChainId] = buildNativeAssetIdentifier(caipChainId, slip44CoinType);
|
|
564
|
-
});
|
|
565
|
-
}, _NetworkEnablementController_getRegistryPopularEvmChainIds = function _NetworkEnablementController_getRegistryPopularEvmChainIds() {
|
|
566
|
-
const { configs: { networks }, } = this.messenger.call('ConfigRegistryController:getState');
|
|
567
|
-
return Object.values(networks).reduce((popularChains, network) => {
|
|
568
|
-
if (network.config.isFeatured &&
|
|
569
|
-
network.config.isActive &&
|
|
570
|
-
!network.config.isTestnet &&
|
|
571
|
-
network.chainId.startsWith('eip155:')) {
|
|
572
|
-
const hexChainId = toHex(parseCaipChainId(network.chainId).reference);
|
|
573
|
-
popularChains.push(hexChainId);
|
|
574
|
-
}
|
|
575
|
-
return popularChains;
|
|
576
|
-
}, []);
|
|
577
|
-
}, _NetworkEnablementController_getPopularEvmChainIds = function _NetworkEnablementController_getPopularEvmChainIds() {
|
|
578
|
-
return [
|
|
579
|
-
...new Set([
|
|
580
|
-
// `toHex` is used to normalize chain IDs from the bundled POPULAR_NETWORKS.
|
|
581
|
-
...POPULAR_NETWORKS.map((chainId) => toHex(chainId)),
|
|
582
|
-
...__classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_getRegistryPopularEvmChainIds).call(this),
|
|
583
|
-
]),
|
|
584
|
-
];
|
|
585
|
-
};
|
|
586
|
-
//# sourceMappingURL=NetworkEnablementController.mjs.map
|
|
622
|
+
//# sourceMappingURL=NetworkEnablementController.js.map
|