@metamask-previews/network-enablement-controller 4.0.0-preview-a033b2d7 → 4.0.0-preview-22f11ed5
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 +7 -0
- package/dist/NetworkEnablementController.cjs +152 -56
- package/dist/NetworkEnablementController.cjs.map +1 -1
- package/dist/NetworkEnablementController.d.cts +51 -1
- package/dist/NetworkEnablementController.d.cts.map +1 -1
- package/dist/NetworkEnablementController.d.mts +51 -1
- package/dist/NetworkEnablementController.d.mts.map +1 -1
- package/dist/NetworkEnablementController.mjs +152 -56
- package/dist/NetworkEnablementController.mjs.map +1 -1
- package/dist/index.cjs +3 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/services/Slip44Service.cjs +82 -0
- package/dist/services/Slip44Service.cjs.map +1 -0
- package/dist/services/Slip44Service.d.cts +46 -0
- package/dist/services/Slip44Service.d.cts.map +1 -0
- package/dist/services/Slip44Service.d.mts +46 -0
- package/dist/services/Slip44Service.d.mts.map +1 -0
- package/dist/services/Slip44Service.mjs +75 -0
- package/dist/services/Slip44Service.mjs.map +1 -0
- package/dist/services/index.cjs +6 -0
- package/dist/services/index.cjs.map +1 -0
- package/dist/services/index.d.cts +3 -0
- package/dist/services/index.d.cts.map +1 -0
- package/dist/services/index.d.mts +3 -0
- package/dist/services/index.d.mts.map +1 -0
- package/dist/services/index.mjs +2 -0
- package/dist/services/index.mjs.map +1 -0
- package/package.json +2 -1
|
@@ -21,8 +21,26 @@ export type NetworksInfo = {
|
|
|
21
21
|
* For other networks, the keys are CAIP chain IDs.
|
|
22
22
|
*/
|
|
23
23
|
type EnabledMap = Record<CaipNamespace, Record<CaipChainId | Hex, boolean>>;
|
|
24
|
+
/**
|
|
25
|
+
* A native asset identifier in CAIP-19-like format.
|
|
26
|
+
* Format: `{caip2ChainId}/slip44:{coinType}`
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* - `eip155:1/slip44:60` for Ethereum mainnet (ETH)
|
|
30
|
+
* - `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501` for Solana mainnet (SOL)
|
|
31
|
+
* - `bip122:000000000019d6689c085ae165831e93/slip44:0` for Bitcoin mainnet (BTC)
|
|
32
|
+
*/
|
|
33
|
+
export type NativeAssetIdentifier = `${CaipChainId}/slip44:${number}`;
|
|
34
|
+
/**
|
|
35
|
+
* A map of CAIP-2 chain IDs to their native asset identifiers.
|
|
36
|
+
* Uses CAIP-19-like format to identify the native asset for each chain.
|
|
37
|
+
*
|
|
38
|
+
* @see https://github.com/satoshilabs/slips/blob/master/slip-0044.md
|
|
39
|
+
*/
|
|
40
|
+
export type NativeAssetIdentifiersMap = Record<CaipChainId, NativeAssetIdentifier>;
|
|
24
41
|
export type NetworkEnablementControllerState = {
|
|
25
42
|
enabledNetworkMap: EnabledMap;
|
|
43
|
+
nativeAssetIdentifiers: NativeAssetIdentifiersMap;
|
|
26
44
|
};
|
|
27
45
|
export type NetworkEnablementControllerGetStateAction = ControllerGetStateAction<typeof controllerName, NetworkEnablementControllerState>;
|
|
28
46
|
export type NetworkEnablementControllerSetEnabledNetworksAction = {
|
|
@@ -45,6 +63,14 @@ export type NetworkEnablementControllerEvents = NetworkEnablementControllerState
|
|
|
45
63
|
*/
|
|
46
64
|
export type AllowedEvents = NetworkControllerNetworkAddedEvent | NetworkControllerNetworkRemovedEvent | NetworkControllerStateChangeEvent | TransactionControllerTransactionSubmittedEvent;
|
|
47
65
|
export type NetworkEnablementControllerMessenger = Messenger<typeof controllerName, NetworkEnablementControllerActions | AllowedActions, NetworkEnablementControllerEvents | AllowedEvents>;
|
|
66
|
+
/**
|
|
67
|
+
* Network configuration with chain ID and native currency symbol.
|
|
68
|
+
* Used to initialize native asset identifiers.
|
|
69
|
+
*/
|
|
70
|
+
export type NetworkConfig = {
|
|
71
|
+
chainId: CaipChainId;
|
|
72
|
+
nativeCurrency: string;
|
|
73
|
+
};
|
|
48
74
|
/**
|
|
49
75
|
* Controller responsible for managing network enablement state across different blockchain networks.
|
|
50
76
|
*
|
|
@@ -116,7 +142,7 @@ export declare class NetworkEnablementController extends BaseController<typeof c
|
|
|
116
142
|
* Initializes the network enablement state from network controller configurations.
|
|
117
143
|
*
|
|
118
144
|
* This method reads the current network configurations from both NetworkController
|
|
119
|
-
* and MultichainNetworkController and syncs the enabled network map accordingly.
|
|
145
|
+
* and MultichainNetworkController and syncs the enabled network map and nativeAssetIdentifiers accordingly.
|
|
120
146
|
* It ensures proper namespace buckets exist for all configured networks and only
|
|
121
147
|
* adds missing networks with a default value of false, preserving existing user settings.
|
|
122
148
|
*
|
|
@@ -124,6 +150,30 @@ export declare class NetworkEnablementController extends BaseController<typeof c
|
|
|
124
150
|
* have been initialized and their configurations are available.
|
|
125
151
|
*/
|
|
126
152
|
init(): void;
|
|
153
|
+
/**
|
|
154
|
+
* Initializes the native asset identifiers from network configurations.
|
|
155
|
+
* This method should be called from the client during controller initialization
|
|
156
|
+
* to populate the nativeAssetIdentifiers state based on actual network configurations.
|
|
157
|
+
*
|
|
158
|
+
* @param networks - Array of network configurations with chainId and nativeCurrency
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* const evmNetworks = Object.values(networkControllerState.networkConfigurationsByChainId)
|
|
162
|
+
* .map(config => ({
|
|
163
|
+
* chainId: toEvmCaipChainId(config.chainId),
|
|
164
|
+
* nativeCurrency: config.nativeCurrency,
|
|
165
|
+
* }));
|
|
166
|
+
*
|
|
167
|
+
* const multichainNetworks = Object.values(multichainState.multichainNetworkConfigurationsByChainId)
|
|
168
|
+
* .map(config => ({
|
|
169
|
+
* chainId: config.chainId,
|
|
170
|
+
* nativeCurrency: config.nativeCurrency,
|
|
171
|
+
* }));
|
|
172
|
+
*
|
|
173
|
+
* controller.initNativeAssetIdentifiers([...evmNetworks, ...multichainNetworks]);
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
initNativeAssetIdentifiers(networks: NetworkConfig[]): void;
|
|
127
177
|
/**
|
|
128
178
|
* Disables a network for the user.
|
|
129
179
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkEnablementController.d.cts","sourceRoot":"","sources":["../src/NetworkEnablementController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAGnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,yCAAyC,EAAE,gDAAgD;AACzG,OAAO,KAAK,EACV,+BAA+B,EAC/B,kCAAkC,EAClC,oCAAoC,EACpC,iCAAiC,EAClC,qCAAqC;AACtC,OAAO,KAAK,EAAE,8CAA8C,EAAE,yCAAyC;AACvG,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"NetworkEnablementController.d.cts","sourceRoot":"","sources":["../src/NetworkEnablementController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAGnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,yCAAyC,EAAE,gDAAgD;AACzG,OAAO,KAAK,EACV,+BAA+B,EAC/B,kCAAkC,EAClC,oCAAoC,EACpC,iCAAiC,EAClC,qCAAqC;AACtC,OAAO,KAAK,EAAE,8CAA8C,EAAE,yCAAyC;AACvG,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,EAAE,wBAAwB;AAWvE,QAAA,MAAM,cAAc,g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22
|
*/
|
|
23
23
|
type EnabledMap = Record<CaipNamespace, Record<CaipChainId | Hex, boolean>>;
|
|
24
|
+
/**
|
|
25
|
+
* A native asset identifier in CAIP-19-like format.
|
|
26
|
+
* Format: `{caip2ChainId}/slip44:{coinType}`
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* - `eip155:1/slip44:60` for Ethereum mainnet (ETH)
|
|
30
|
+
* - `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501` for Solana mainnet (SOL)
|
|
31
|
+
* - `bip122:000000000019d6689c085ae165831e93/slip44:0` for Bitcoin mainnet (BTC)
|
|
32
|
+
*/
|
|
33
|
+
export type NativeAssetIdentifier = `${CaipChainId}/slip44:${number}`;
|
|
34
|
+
/**
|
|
35
|
+
* A map of CAIP-2 chain IDs to their native asset identifiers.
|
|
36
|
+
* Uses CAIP-19-like format to identify the native asset for each chain.
|
|
37
|
+
*
|
|
38
|
+
* @see https://github.com/satoshilabs/slips/blob/master/slip-0044.md
|
|
39
|
+
*/
|
|
40
|
+
export type NativeAssetIdentifiersMap = Record<CaipChainId, NativeAssetIdentifier>;
|
|
24
41
|
export type NetworkEnablementControllerState = {
|
|
25
42
|
enabledNetworkMap: EnabledMap;
|
|
43
|
+
nativeAssetIdentifiers: NativeAssetIdentifiersMap;
|
|
26
44
|
};
|
|
27
45
|
export type NetworkEnablementControllerGetStateAction = ControllerGetStateAction<typeof controllerName, NetworkEnablementControllerState>;
|
|
28
46
|
export type NetworkEnablementControllerSetEnabledNetworksAction = {
|
|
@@ -45,6 +63,14 @@ export type NetworkEnablementControllerEvents = NetworkEnablementControllerState
|
|
|
45
63
|
*/
|
|
46
64
|
export type AllowedEvents = NetworkControllerNetworkAddedEvent | NetworkControllerNetworkRemovedEvent | NetworkControllerStateChangeEvent | TransactionControllerTransactionSubmittedEvent;
|
|
47
65
|
export type NetworkEnablementControllerMessenger = Messenger<typeof controllerName, NetworkEnablementControllerActions | AllowedActions, NetworkEnablementControllerEvents | AllowedEvents>;
|
|
66
|
+
/**
|
|
67
|
+
* Network configuration with chain ID and native currency symbol.
|
|
68
|
+
* Used to initialize native asset identifiers.
|
|
69
|
+
*/
|
|
70
|
+
export type NetworkConfig = {
|
|
71
|
+
chainId: CaipChainId;
|
|
72
|
+
nativeCurrency: string;
|
|
73
|
+
};
|
|
48
74
|
/**
|
|
49
75
|
* Controller responsible for managing network enablement state across different blockchain networks.
|
|
50
76
|
*
|
|
@@ -116,7 +142,7 @@ export declare class NetworkEnablementController extends BaseController<typeof c
|
|
|
116
142
|
* Initializes the network enablement state from network controller configurations.
|
|
117
143
|
*
|
|
118
144
|
* This method reads the current network configurations from both NetworkController
|
|
119
|
-
* and MultichainNetworkController and syncs the enabled network map accordingly.
|
|
145
|
+
* and MultichainNetworkController and syncs the enabled network map and nativeAssetIdentifiers accordingly.
|
|
120
146
|
* It ensures proper namespace buckets exist for all configured networks and only
|
|
121
147
|
* adds missing networks with a default value of false, preserving existing user settings.
|
|
122
148
|
*
|
|
@@ -124,6 +150,30 @@ export declare class NetworkEnablementController extends BaseController<typeof c
|
|
|
124
150
|
* have been initialized and their configurations are available.
|
|
125
151
|
*/
|
|
126
152
|
init(): void;
|
|
153
|
+
/**
|
|
154
|
+
* Initializes the native asset identifiers from network configurations.
|
|
155
|
+
* This method should be called from the client during controller initialization
|
|
156
|
+
* to populate the nativeAssetIdentifiers state based on actual network configurations.
|
|
157
|
+
*
|
|
158
|
+
* @param networks - Array of network configurations with chainId and nativeCurrency
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* const evmNetworks = Object.values(networkControllerState.networkConfigurationsByChainId)
|
|
162
|
+
* .map(config => ({
|
|
163
|
+
* chainId: toEvmCaipChainId(config.chainId),
|
|
164
|
+
* nativeCurrency: config.nativeCurrency,
|
|
165
|
+
* }));
|
|
166
|
+
*
|
|
167
|
+
* const multichainNetworks = Object.values(multichainState.multichainNetworkConfigurationsByChainId)
|
|
168
|
+
* .map(config => ({
|
|
169
|
+
* chainId: config.chainId,
|
|
170
|
+
* nativeCurrency: config.nativeCurrency,
|
|
171
|
+
* }));
|
|
172
|
+
*
|
|
173
|
+
* controller.initNativeAssetIdentifiers([...evmNetworks, ...multichainNetworks]);
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
initNativeAssetIdentifiers(networks: NetworkConfig[]): void;
|
|
127
177
|
/**
|
|
128
178
|
* Disables a network for the user.
|
|
129
179
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkEnablementController.d.mts","sourceRoot":"","sources":["../src/NetworkEnablementController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAGnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,yCAAyC,EAAE,gDAAgD;AACzG,OAAO,KAAK,EACV,+BAA+B,EAC/B,kCAAkC,EAClC,oCAAoC,EACpC,iCAAiC,EAClC,qCAAqC;AACtC,OAAO,KAAK,EAAE,8CAA8C,EAAE,yCAAyC;AACvG,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"NetworkEnablementController.d.mts","sourceRoot":"","sources":["../src/NetworkEnablementController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAGnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,yCAAyC,EAAE,gDAAgD;AACzG,OAAO,KAAK,EACV,+BAA+B,EAC/B,kCAAkC,EAClC,oCAAoC,EACpC,iCAAiC,EAClC,qCAAqC;AACtC,OAAO,KAAK,EAAE,8CAA8C,EAAE,yCAAyC;AAC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LtD"}
|
|
@@ -3,14 +3,25 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
3
3
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
4
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
5
|
};
|
|
6
|
-
var _NetworkEnablementController_instances, _NetworkEnablementController_ensureNamespaceBucket, _NetworkEnablementController_isInPopularNetworksMode, _NetworkEnablementController_removeNetworkEntry, _NetworkEnablementController_onAddNetwork;
|
|
6
|
+
var _NetworkEnablementController_instances, _NetworkEnablementController_onNetworkControllerStateChange, _NetworkEnablementController_ensureNamespaceBucket, _NetworkEnablementController_updateNativeAssetIdentifier, _NetworkEnablementController_isInPopularNetworksMode, _NetworkEnablementController_removeNetworkEntry, _NetworkEnablementController_onAddNetwork;
|
|
7
7
|
import { BaseController } from "@metamask/base-controller";
|
|
8
8
|
import { BuiltInNetworkName, ChainId } from "@metamask/controller-utils";
|
|
9
9
|
import { BtcScope, SolScope, TrxScope } from "@metamask/keyring-api";
|
|
10
10
|
import { KnownCaipNamespace } from "@metamask/utils";
|
|
11
11
|
import { POPULAR_NETWORKS } from "./constants.mjs";
|
|
12
|
+
import { Slip44Service } from "./services/index.mjs";
|
|
12
13
|
import { deriveKeys, isOnlyNetworkEnabledInNamespace, isPopularNetwork } from "./utils.mjs";
|
|
13
14
|
const controllerName = 'NetworkEnablementController';
|
|
15
|
+
/**
|
|
16
|
+
* Builds a native asset identifier in CAIP-19-like format.
|
|
17
|
+
*
|
|
18
|
+
* @param caipChainId - The CAIP-2 chain ID (e.g., 'eip155:1', 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp')
|
|
19
|
+
* @param slip44CoinType - The SLIP-44 coin type number
|
|
20
|
+
* @returns The native asset identifier string (e.g., 'eip155:1/slip44:60')
|
|
21
|
+
*/
|
|
22
|
+
function buildNativeAssetIdentifier(caipChainId, slip44CoinType) {
|
|
23
|
+
return `${caipChainId}/slip44:${slip44CoinType}`;
|
|
24
|
+
}
|
|
14
25
|
/**
|
|
15
26
|
* Gets the default state for the NetworkEnablementController.
|
|
16
27
|
*
|
|
@@ -44,6 +55,9 @@ const getDefaultNetworkEnablementControllerState = () => ({
|
|
|
44
55
|
[TrxScope.Shasta]: false,
|
|
45
56
|
},
|
|
46
57
|
},
|
|
58
|
+
// nativeAssetIdentifiers is initialized as empty and should be populated
|
|
59
|
+
// by the client using initNativeAssetIdentifiers() during controller init
|
|
60
|
+
nativeAssetIdentifiers: {},
|
|
47
61
|
});
|
|
48
62
|
// Metadata for the controller state
|
|
49
63
|
const metadata = {
|
|
@@ -53,6 +67,12 @@ const metadata = {
|
|
|
53
67
|
includeInDebugSnapshot: true,
|
|
54
68
|
usedInUi: true,
|
|
55
69
|
},
|
|
70
|
+
nativeAssetIdentifiers: {
|
|
71
|
+
includeInStateLogs: true,
|
|
72
|
+
persist: true,
|
|
73
|
+
includeInDebugSnapshot: true,
|
|
74
|
+
usedInUi: true,
|
|
75
|
+
},
|
|
56
76
|
};
|
|
57
77
|
/**
|
|
58
78
|
* Controller responsible for managing network enablement state across different blockchain networks.
|
|
@@ -82,12 +102,15 @@ export class NetworkEnablementController extends BaseController {
|
|
|
82
102
|
},
|
|
83
103
|
});
|
|
84
104
|
_NetworkEnablementController_instances.add(this);
|
|
85
|
-
messenger.subscribe('NetworkController:networkAdded', ({ chainId }) => {
|
|
86
|
-
__classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_onAddNetwork).call(this, chainId);
|
|
105
|
+
messenger.subscribe('NetworkController:networkAdded', ({ chainId, nativeCurrency }) => {
|
|
106
|
+
__classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_onAddNetwork).call(this, chainId, nativeCurrency);
|
|
87
107
|
});
|
|
88
108
|
messenger.subscribe('NetworkController:networkRemoved', ({ chainId }) => {
|
|
89
109
|
__classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_removeNetworkEntry).call(this, chainId);
|
|
90
110
|
});
|
|
111
|
+
messenger.subscribe('NetworkController:stateChange', (_newState, patches) => {
|
|
112
|
+
__classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_onNetworkControllerStateChange).call(this, patches);
|
|
113
|
+
});
|
|
91
114
|
}
|
|
92
115
|
/**
|
|
93
116
|
* Enables or disables a network for the user.
|
|
@@ -107,20 +130,20 @@ export class NetworkEnablementController extends BaseController {
|
|
|
107
130
|
*/
|
|
108
131
|
enableNetwork(chainId) {
|
|
109
132
|
const { namespace, storageKey } = deriveKeys(chainId);
|
|
110
|
-
this.update((
|
|
133
|
+
this.update((state) => {
|
|
111
134
|
// disable all networks in all namespaces first
|
|
112
|
-
Object.keys(
|
|
113
|
-
Object.keys(
|
|
114
|
-
|
|
135
|
+
Object.keys(state.enabledNetworkMap).forEach((ns) => {
|
|
136
|
+
Object.keys(state.enabledNetworkMap[ns]).forEach((key) => {
|
|
137
|
+
state.enabledNetworkMap[ns][key] = false;
|
|
115
138
|
});
|
|
116
139
|
});
|
|
117
140
|
// if the namespace bucket does not exist, return
|
|
118
141
|
// new nemespace are added only when a new network is added
|
|
119
|
-
if (!
|
|
142
|
+
if (!state.enabledNetworkMap[namespace]) {
|
|
120
143
|
return;
|
|
121
144
|
}
|
|
122
145
|
// enable the network
|
|
123
|
-
|
|
146
|
+
state.enabledNetworkMap[namespace][storageKey] = true;
|
|
124
147
|
});
|
|
125
148
|
}
|
|
126
149
|
/**
|
|
@@ -145,17 +168,17 @@ export class NetworkEnablementController extends BaseController {
|
|
|
145
168
|
if (derivedNamespace !== namespace) {
|
|
146
169
|
throw new Error(`Chain ID ${chainId} belongs to namespace ${derivedNamespace}, but namespace ${namespace} was specified`);
|
|
147
170
|
}
|
|
148
|
-
this.update((
|
|
171
|
+
this.update((state) => {
|
|
149
172
|
// Ensure the namespace bucket exists
|
|
150
|
-
__classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this,
|
|
173
|
+
__classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, state, namespace);
|
|
151
174
|
// Disable all networks in the specified namespace first
|
|
152
|
-
if (
|
|
153
|
-
Object.keys(
|
|
154
|
-
|
|
175
|
+
if (state.enabledNetworkMap[namespace]) {
|
|
176
|
+
Object.keys(state.enabledNetworkMap[namespace]).forEach((key) => {
|
|
177
|
+
state.enabledNetworkMap[namespace][key] = false;
|
|
155
178
|
});
|
|
156
179
|
}
|
|
157
180
|
// Enable the target network in the specified namespace
|
|
158
|
-
|
|
181
|
+
state.enabledNetworkMap[namespace][storageKey] = true;
|
|
159
182
|
});
|
|
160
183
|
}
|
|
161
184
|
/**
|
|
@@ -169,11 +192,11 @@ export class NetworkEnablementController extends BaseController {
|
|
|
169
192
|
* Popular networks that don't exist in NetworkController or MultichainNetworkController configurations will be skipped silently.
|
|
170
193
|
*/
|
|
171
194
|
enableAllPopularNetworks() {
|
|
172
|
-
this.update((
|
|
195
|
+
this.update((state) => {
|
|
173
196
|
// First disable all networks across all namespaces
|
|
174
|
-
Object.keys(
|
|
175
|
-
Object.keys(
|
|
176
|
-
|
|
197
|
+
Object.keys(state.enabledNetworkMap).forEach((ns) => {
|
|
198
|
+
Object.keys(state.enabledNetworkMap[ns]).forEach((key) => {
|
|
199
|
+
state.enabledNetworkMap[ns][key] = false;
|
|
177
200
|
});
|
|
178
201
|
});
|
|
179
202
|
// Get current network configurations to check if networks exist
|
|
@@ -185,35 +208,36 @@ export class NetworkEnablementController extends BaseController {
|
|
|
185
208
|
// Check if network exists in NetworkController configurations
|
|
186
209
|
if (networkControllerState.networkConfigurationsByChainId[chainId]) {
|
|
187
210
|
// Ensure namespace bucket exists
|
|
188
|
-
__classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this,
|
|
211
|
+
__classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, state, namespace);
|
|
189
212
|
// Enable the network
|
|
190
|
-
|
|
213
|
+
state.enabledNetworkMap[namespace][storageKey] = true;
|
|
191
214
|
}
|
|
192
215
|
});
|
|
193
216
|
// Enable Solana mainnet if it exists in MultichainNetworkController configurations
|
|
194
217
|
const solanaKeys = deriveKeys(SolScope.Mainnet);
|
|
195
218
|
if (multichainState.multichainNetworkConfigurationsByChainId[SolScope.Mainnet]) {
|
|
196
219
|
// Ensure namespace bucket exists
|
|
197
|
-
__classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this,
|
|
220
|
+
__classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, state, solanaKeys.namespace);
|
|
198
221
|
// Enable Solana mainnet
|
|
199
|
-
|
|
222
|
+
state.enabledNetworkMap[solanaKeys.namespace][solanaKeys.storageKey] =
|
|
223
|
+
true;
|
|
200
224
|
}
|
|
201
225
|
// Enable Bitcoin mainnet if it exists in MultichainNetworkController configurations
|
|
202
226
|
const bitcoinKeys = deriveKeys(BtcScope.Mainnet);
|
|
203
227
|
if (multichainState.multichainNetworkConfigurationsByChainId[BtcScope.Mainnet]) {
|
|
204
228
|
// Ensure namespace bucket exists
|
|
205
|
-
__classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this,
|
|
229
|
+
__classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, state, bitcoinKeys.namespace);
|
|
206
230
|
// Enable Bitcoin mainnet
|
|
207
|
-
|
|
231
|
+
state.enabledNetworkMap[bitcoinKeys.namespace][bitcoinKeys.storageKey] =
|
|
208
232
|
true;
|
|
209
233
|
}
|
|
210
234
|
// Enable Tron mainnet if it exists in MultichainNetworkController configurations
|
|
211
235
|
const tronKeys = deriveKeys(TrxScope.Mainnet);
|
|
212
236
|
if (multichainState.multichainNetworkConfigurationsByChainId[TrxScope.Mainnet]) {
|
|
213
237
|
// Ensure namespace bucket exists
|
|
214
|
-
__classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this,
|
|
238
|
+
__classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, state, tronKeys.namespace);
|
|
215
239
|
// Enable Tron mainnet
|
|
216
|
-
|
|
240
|
+
state.enabledNetworkMap[tronKeys.namespace][tronKeys.storageKey] = true;
|
|
217
241
|
}
|
|
218
242
|
});
|
|
219
243
|
}
|
|
@@ -221,7 +245,7 @@ export class NetworkEnablementController extends BaseController {
|
|
|
221
245
|
* Initializes the network enablement state from network controller configurations.
|
|
222
246
|
*
|
|
223
247
|
* This method reads the current network configurations from both NetworkController
|
|
224
|
-
* and MultichainNetworkController and syncs the enabled network map accordingly.
|
|
248
|
+
* and MultichainNetworkController and syncs the enabled network map and nativeAssetIdentifiers accordingly.
|
|
225
249
|
* It ensures proper namespace buckets exist for all configured networks and only
|
|
226
250
|
* adds missing networks with a default value of false, preserving existing user settings.
|
|
227
251
|
*
|
|
@@ -229,31 +253,70 @@ export class NetworkEnablementController extends BaseController {
|
|
|
229
253
|
* have been initialized and their configurations are available.
|
|
230
254
|
*/
|
|
231
255
|
init() {
|
|
232
|
-
this.update((
|
|
256
|
+
this.update((state) => {
|
|
233
257
|
// Get network configurations from NetworkController (EVM networks)
|
|
234
258
|
const networkControllerState = this.messenger.call('NetworkController:getState');
|
|
235
259
|
// Get network configurations from MultichainNetworkController (all networks)
|
|
236
260
|
const multichainState = this.messenger.call('MultichainNetworkController:getState');
|
|
237
261
|
// Initialize namespace buckets for EVM networks from NetworkController
|
|
238
|
-
Object.
|
|
239
|
-
|
|
240
|
-
|
|
262
|
+
Object.entries(networkControllerState.networkConfigurationsByChainId).forEach(([chainId, config]) => {
|
|
263
|
+
var _a;
|
|
264
|
+
const { namespace, storageKey, caipChainId } = deriveKeys(chainId);
|
|
265
|
+
__classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, state, namespace);
|
|
241
266
|
// Only add network if it doesn't already exist in state (preserves user settings)
|
|
242
|
-
|
|
243
|
-
|
|
267
|
+
(_a = state.enabledNetworkMap[namespace])[storageKey] ?? (_a[storageKey] = false);
|
|
268
|
+
// Sync nativeAssetIdentifiers using the nativeCurrency symbol
|
|
269
|
+
if (state.nativeAssetIdentifiers[caipChainId] === undefined) {
|
|
270
|
+
const slip44CoinType = Slip44Service.getSlip44BySymbol(config.nativeCurrency);
|
|
271
|
+
if (slip44CoinType !== undefined) {
|
|
272
|
+
state.nativeAssetIdentifiers[caipChainId] =
|
|
273
|
+
buildNativeAssetIdentifier(caipChainId, slip44CoinType);
|
|
274
|
+
}
|
|
244
275
|
}
|
|
245
276
|
});
|
|
246
277
|
// Initialize namespace buckets for all networks from MultichainNetworkController
|
|
247
278
|
Object.keys(multichainState.multichainNetworkConfigurationsByChainId).forEach((chainId) => {
|
|
279
|
+
var _a;
|
|
248
280
|
const { namespace, storageKey } = deriveKeys(chainId);
|
|
249
|
-
__classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this,
|
|
281
|
+
__classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, state, namespace);
|
|
250
282
|
// Only add network if it doesn't already exist in state (preserves user settings)
|
|
251
|
-
|
|
252
|
-
s.enabledNetworkMap[namespace][storageKey] = false;
|
|
253
|
-
}
|
|
283
|
+
(_a = state.enabledNetworkMap[namespace])[storageKey] ?? (_a[storageKey] = false);
|
|
254
284
|
});
|
|
255
285
|
});
|
|
256
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* Initializes the native asset identifiers from network configurations.
|
|
289
|
+
* This method should be called from the client during controller initialization
|
|
290
|
+
* to populate the nativeAssetIdentifiers state based on actual network configurations.
|
|
291
|
+
*
|
|
292
|
+
* @param networks - Array of network configurations with chainId and nativeCurrency
|
|
293
|
+
* @example
|
|
294
|
+
* ```typescript
|
|
295
|
+
* const evmNetworks = Object.values(networkControllerState.networkConfigurationsByChainId)
|
|
296
|
+
* .map(config => ({
|
|
297
|
+
* chainId: toEvmCaipChainId(config.chainId),
|
|
298
|
+
* nativeCurrency: config.nativeCurrency,
|
|
299
|
+
* }));
|
|
300
|
+
*
|
|
301
|
+
* const multichainNetworks = Object.values(multichainState.multichainNetworkConfigurationsByChainId)
|
|
302
|
+
* .map(config => ({
|
|
303
|
+
* chainId: config.chainId,
|
|
304
|
+
* nativeCurrency: config.nativeCurrency,
|
|
305
|
+
* }));
|
|
306
|
+
*
|
|
307
|
+
* controller.initNativeAssetIdentifiers([...evmNetworks, ...multichainNetworks]);
|
|
308
|
+
* ```
|
|
309
|
+
*/
|
|
310
|
+
initNativeAssetIdentifiers(networks) {
|
|
311
|
+
this.update((state) => {
|
|
312
|
+
for (const { chainId, nativeCurrency } of networks) {
|
|
313
|
+
const slip44CoinType = Slip44Service.getSlip44BySymbol(nativeCurrency);
|
|
314
|
+
if (slip44CoinType !== undefined) {
|
|
315
|
+
state.nativeAssetIdentifiers[chainId] = buildNativeAssetIdentifier(chainId, slip44CoinType);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
}
|
|
257
320
|
/**
|
|
258
321
|
* Disables a network for the user.
|
|
259
322
|
*
|
|
@@ -271,8 +334,8 @@ export class NetworkEnablementController extends BaseController {
|
|
|
271
334
|
disableNetwork(chainId) {
|
|
272
335
|
const derivedKeys = deriveKeys(chainId);
|
|
273
336
|
const { namespace, storageKey } = derivedKeys;
|
|
274
|
-
this.update((
|
|
275
|
-
|
|
337
|
+
this.update((state) => {
|
|
338
|
+
state.enabledNetworkMap[namespace][storageKey] = false;
|
|
276
339
|
});
|
|
277
340
|
}
|
|
278
341
|
/**
|
|
@@ -289,10 +352,36 @@ export class NetworkEnablementController extends BaseController {
|
|
|
289
352
|
return this.state.enabledNetworkMap[namespace]?.[storageKey] ?? false;
|
|
290
353
|
}
|
|
291
354
|
}
|
|
292
|
-
_NetworkEnablementController_instances = new WeakSet(),
|
|
355
|
+
_NetworkEnablementController_instances = new WeakSet(), _NetworkEnablementController_onNetworkControllerStateChange = function _NetworkEnablementController_onNetworkControllerStateChange(patches) {
|
|
356
|
+
// Look for patches that replace a network configuration
|
|
357
|
+
// Path format: ['networkConfigurationsByChainId', chainId]
|
|
358
|
+
for (const patch of patches) {
|
|
359
|
+
if (patch.path.length === 2 &&
|
|
360
|
+
patch.path[0] === 'networkConfigurationsByChainId' &&
|
|
361
|
+
patch.op === 'replace' &&
|
|
362
|
+
patch.value &&
|
|
363
|
+
typeof patch.value === 'object' &&
|
|
364
|
+
'nativeCurrency' in patch.value) {
|
|
365
|
+
const chainId = patch.path[1];
|
|
366
|
+
const networkConfig = patch.value;
|
|
367
|
+
__classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_updateNativeAssetIdentifier).call(this, chainId, networkConfig.nativeCurrency);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}, _NetworkEnablementController_ensureNamespaceBucket = function _NetworkEnablementController_ensureNamespaceBucket(state, ns) {
|
|
293
371
|
if (!state.enabledNetworkMap[ns]) {
|
|
294
372
|
state.enabledNetworkMap[ns] = {};
|
|
295
373
|
}
|
|
374
|
+
}, _NetworkEnablementController_updateNativeAssetIdentifier = function _NetworkEnablementController_updateNativeAssetIdentifier(chainId, symbol) {
|
|
375
|
+
const slip44CoinType = Slip44Service.getSlip44BySymbol(symbol);
|
|
376
|
+
const { caipChainId } = deriveKeys(chainId);
|
|
377
|
+
this.update((state) => {
|
|
378
|
+
if (slip44CoinType === undefined) {
|
|
379
|
+
// Remove the entry if no SLIP-44 mapping exists for the symbol
|
|
380
|
+
delete state.nativeAssetIdentifiers[caipChainId];
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
state.nativeAssetIdentifiers[caipChainId] = buildNativeAssetIdentifier(caipChainId, slip44CoinType);
|
|
384
|
+
});
|
|
296
385
|
}, _NetworkEnablementController_isInPopularNetworksMode = function _NetworkEnablementController_isInPopularNetworksMode() {
|
|
297
386
|
// Get current network configurations to check which popular networks exist
|
|
298
387
|
const networkControllerState = this.messenger.call('NetworkController:getState');
|
|
@@ -310,22 +399,25 @@ _NetworkEnablementController_instances = new WeakSet(), _NetworkEnablementContro
|
|
|
310
399
|
return enabledPopularNetworksCount > 1;
|
|
311
400
|
}, _NetworkEnablementController_removeNetworkEntry = function _NetworkEnablementController_removeNetworkEntry(chainId) {
|
|
312
401
|
const derivedKeys = deriveKeys(chainId);
|
|
313
|
-
const { namespace, storageKey } = derivedKeys;
|
|
314
|
-
this.update((
|
|
402
|
+
const { namespace, storageKey, caipChainId } = derivedKeys;
|
|
403
|
+
this.update((state) => {
|
|
315
404
|
// fallback and enable ethereum mainnet
|
|
316
405
|
if (isOnlyNetworkEnabledInNamespace(this.state, derivedKeys)) {
|
|
317
|
-
|
|
318
|
-
true;
|
|
406
|
+
state.enabledNetworkMap[namespace][ChainId[BuiltInNetworkName.Mainnet]] = true;
|
|
319
407
|
}
|
|
320
|
-
if (namespace in
|
|
321
|
-
delete
|
|
408
|
+
if (namespace in state.enabledNetworkMap) {
|
|
409
|
+
delete state.enabledNetworkMap[namespace][storageKey];
|
|
322
410
|
}
|
|
411
|
+
// Remove from nativeAssetIdentifiers as well
|
|
412
|
+
delete state.nativeAssetIdentifiers[caipChainId];
|
|
323
413
|
});
|
|
324
|
-
}, _NetworkEnablementController_onAddNetwork = function _NetworkEnablementController_onAddNetwork(chainId) {
|
|
325
|
-
const { namespace, storageKey, reference } = deriveKeys(chainId);
|
|
326
|
-
|
|
414
|
+
}, _NetworkEnablementController_onAddNetwork = function _NetworkEnablementController_onAddNetwork(chainId, nativeCurrency) {
|
|
415
|
+
const { namespace, storageKey, reference, caipChainId } = deriveKeys(chainId);
|
|
416
|
+
// Look up the SLIP-44 coin type for the native currency
|
|
417
|
+
const slip44CoinType = Slip44Service.getSlip44BySymbol(nativeCurrency);
|
|
418
|
+
this.update((state) => {
|
|
327
419
|
// Ensure the namespace bucket exists
|
|
328
|
-
__classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this,
|
|
420
|
+
__classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, state, namespace);
|
|
329
421
|
// Check if popular networks mode is active (>2 popular networks enabled)
|
|
330
422
|
const inPopularNetworksMode = __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_isInPopularNetworksMode).call(this);
|
|
331
423
|
// Check if the network being added is a popular network
|
|
@@ -334,17 +426,21 @@ _NetworkEnablementController_instances = new WeakSet(), _NetworkEnablementContro
|
|
|
334
426
|
const shouldKeepCurrentSelection = inPopularNetworksMode && isAddedNetworkPopular;
|
|
335
427
|
if (shouldKeepCurrentSelection) {
|
|
336
428
|
// Add the popular network but don't enable it (keep current selection)
|
|
337
|
-
|
|
429
|
+
state.enabledNetworkMap[namespace][storageKey] = true;
|
|
338
430
|
}
|
|
339
431
|
else {
|
|
340
432
|
// Switch to the newly added network (disable all others, enable this one)
|
|
341
|
-
Object.keys(
|
|
342
|
-
Object.keys(
|
|
343
|
-
|
|
433
|
+
Object.keys(state.enabledNetworkMap).forEach((ns) => {
|
|
434
|
+
Object.keys(state.enabledNetworkMap[ns]).forEach((key) => {
|
|
435
|
+
state.enabledNetworkMap[ns][key] = false;
|
|
344
436
|
});
|
|
345
437
|
});
|
|
346
438
|
// Enable the newly added network
|
|
347
|
-
|
|
439
|
+
state.enabledNetworkMap[namespace][storageKey] = true;
|
|
440
|
+
}
|
|
441
|
+
// Update nativeAssetIdentifiers with the CAIP-19-like identifier
|
|
442
|
+
if (slip44CoinType !== undefined) {
|
|
443
|
+
state.nativeAssetIdentifiers[caipChainId] = buildNativeAssetIdentifier(caipChainId, slip44CoinType);
|
|
348
444
|
}
|
|
349
445
|
});
|
|
350
446
|
};
|