@metamask-previews/network-enablement-controller 4.0.0-preview-0c691324 → 4.0.0-preview-009e026d

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +0 -7
  2. package/dist/NetworkEnablementController.cjs +61 -240
  3. package/dist/NetworkEnablementController.cjs.map +1 -1
  4. package/dist/NetworkEnablementController.d.cts +2 -52
  5. package/dist/NetworkEnablementController.d.cts.map +1 -1
  6. package/dist/NetworkEnablementController.d.mts +2 -52
  7. package/dist/NetworkEnablementController.d.mts.map +1 -1
  8. package/dist/NetworkEnablementController.mjs +61 -240
  9. package/dist/NetworkEnablementController.mjs.map +1 -1
  10. package/dist/index.cjs +1 -5
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +1 -3
  13. package/dist/index.d.cts.map +1 -1
  14. package/dist/index.d.mts +1 -3
  15. package/dist/index.d.mts.map +1 -1
  16. package/dist/index.mjs +0 -1
  17. package/dist/index.mjs.map +1 -1
  18. package/package.json +1 -2
  19. package/dist/services/Slip44Service.cjs +0 -176
  20. package/dist/services/Slip44Service.cjs.map +0 -1
  21. package/dist/services/Slip44Service.d.cts +0 -74
  22. package/dist/services/Slip44Service.d.cts.map +0 -1
  23. package/dist/services/Slip44Service.d.mts +0 -74
  24. package/dist/services/Slip44Service.d.mts.map +0 -1
  25. package/dist/services/Slip44Service.mjs +0 -169
  26. package/dist/services/Slip44Service.mjs.map +0 -1
  27. package/dist/services/index.cjs +0 -9
  28. package/dist/services/index.cjs.map +0 -1
  29. package/dist/services/index.d.cts +0 -6
  30. package/dist/services/index.d.cts.map +0 -1
  31. package/dist/services/index.d.mts +0 -6
  32. package/dist/services/index.d.mts.map +0 -1
  33. package/dist/services/index.mjs +0 -6
  34. package/dist/services/index.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -7,13 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
- ### Added
11
-
12
- - Add `nativeAssetIdentifiers` state property that maps CAIP-2 chain IDs to CAIP-19-like native asset identifiers (e.g., `eip155:1/slip44:60`) ([#7609](https://github.com/MetaMask/core/pull/7609))
13
- - Add `Slip44Service` to look up SLIP-44 coin types by native currency symbol ([#7609](https://github.com/MetaMask/core/pull/7609))
14
- - Add `@metamask/slip44` dependency for SLIP-44 coin type lookups ([#7609](https://github.com/MetaMask/core/pull/7609))
15
- - Subscribe to `NetworkController:stateChange` to update `nativeAssetIdentifiers` when a network's native currency changes ([#7609](https://github.com/MetaMask/core/pull/7609))
16
-
17
10
  ### Changed
18
11
 
19
12
  - Upgrade `@metamask/utils` from `^11.8.1` to `^11.9.0` ([#7511](https://github.com/MetaMask/core/pull/7511))
@@ -4,7 +4,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
4
4
  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");
5
5
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
6
  };
7
- var _NetworkEnablementController_instances, _NetworkEnablementController_onNativeCurrencyChange, _NetworkEnablementController_ensureNamespaceBucket, _NetworkEnablementController_updateNativeAssetIdentifier, _NetworkEnablementController_isInPopularNetworksMode, _NetworkEnablementController_removeNetworkEntry, _NetworkEnablementController_onAddNetwork;
7
+ var _NetworkEnablementController_instances, _NetworkEnablementController_ensureNamespaceBucket, _NetworkEnablementController_isInPopularNetworksMode, _NetworkEnablementController_removeNetworkEntry, _NetworkEnablementController_onAddNetwork;
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.NetworkEnablementController = void 0;
10
10
  const base_controller_1 = require("@metamask/base-controller");
@@ -12,19 +12,8 @@ const controller_utils_1 = require("@metamask/controller-utils");
12
12
  const keyring_api_1 = require("@metamask/keyring-api");
13
13
  const utils_1 = require("@metamask/utils");
14
14
  const constants_1 = require("./constants.cjs");
15
- const services_1 = require("./services/index.cjs");
16
15
  const utils_2 = require("./utils.cjs");
17
16
  const controllerName = 'NetworkEnablementController';
18
- /**
19
- * Builds a native asset identifier in CAIP-19-like format.
20
- *
21
- * @param caipChainId - The CAIP-2 chain ID (e.g., 'eip155:1', 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp')
22
- * @param slip44CoinType - The SLIP-44 coin type number
23
- * @returns The native asset identifier string (e.g., 'eip155:1/slip44:60')
24
- */
25
- function buildNativeAssetIdentifier(caipChainId, slip44CoinType) {
26
- return `${caipChainId}/slip44:${slip44CoinType}`;
27
- }
28
17
  /**
29
18
  * Gets the default state for the NetworkEnablementController.
30
19
  *
@@ -58,9 +47,6 @@ const getDefaultNetworkEnablementControllerState = () => ({
58
47
  [keyring_api_1.TrxScope.Shasta]: false,
59
48
  },
60
49
  },
61
- // nativeAssetIdentifiers is initialized as empty and should be populated
62
- // by the client using initNativeAssetIdentifiers() during controller init
63
- nativeAssetIdentifiers: {},
64
50
  });
65
51
  // Metadata for the controller state
66
52
  const metadata = {
@@ -70,12 +56,6 @@ const metadata = {
70
56
  includeInDebugSnapshot: true,
71
57
  usedInUi: true,
72
58
  },
73
- nativeAssetIdentifiers: {
74
- includeInStateLogs: true,
75
- persist: true,
76
- includeInDebugSnapshot: true,
77
- usedInUi: true,
78
- },
79
59
  };
80
60
  /**
81
61
  * Controller responsible for managing network enablement state across different blockchain networks.
@@ -105,20 +85,12 @@ class NetworkEnablementController extends base_controller_1.BaseController {
105
85
  },
106
86
  });
107
87
  _NetworkEnablementController_instances.add(this);
108
- messenger.subscribe('NetworkController:networkAdded', ({ chainId, nativeCurrency }) => {
109
- // eslint-disable-next-line no-void
110
- void __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_onAddNetwork).call(this, chainId, nativeCurrency);
88
+ messenger.subscribe('NetworkController:networkAdded', ({ chainId }) => {
89
+ __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_onAddNetwork).call(this, chainId);
111
90
  });
112
91
  messenger.subscribe('NetworkController:networkRemoved', ({ chainId }) => {
113
92
  __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_removeNetworkEntry).call(this, chainId);
114
93
  });
115
- // Subscribe to nativeCurrency changes using selector approach
116
- messenger.subscribe('NetworkController:stateChange', (currentNativeCurrencies, previousNativeCurrencies) => {
117
- // eslint-disable-next-line no-void
118
- void __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_onNativeCurrencyChange).call(this, currentNativeCurrencies, previousNativeCurrencies);
119
- },
120
- // Selector: extract chainId -> nativeCurrency map
121
- (networkState) => Object.fromEntries(Object.entries(networkState.networkConfigurationsByChainId).map(([chainId, config]) => [chainId, config.nativeCurrency])));
122
94
  }
123
95
  /**
124
96
  * Enables or disables a network for the user.
@@ -138,20 +110,20 @@ class NetworkEnablementController extends base_controller_1.BaseController {
138
110
  */
139
111
  enableNetwork(chainId) {
140
112
  const { namespace, storageKey } = (0, utils_2.deriveKeys)(chainId);
141
- this.update((state) => {
113
+ this.update((s) => {
142
114
  // disable all networks in all namespaces first
143
- Object.keys(state.enabledNetworkMap).forEach((ns) => {
144
- Object.keys(state.enabledNetworkMap[ns]).forEach((key) => {
145
- state.enabledNetworkMap[ns][key] = false;
115
+ Object.keys(s.enabledNetworkMap).forEach((ns) => {
116
+ Object.keys(s.enabledNetworkMap[ns]).forEach((key) => {
117
+ s.enabledNetworkMap[ns][key] = false;
146
118
  });
147
119
  });
148
120
  // if the namespace bucket does not exist, return
149
121
  // new nemespace are added only when a new network is added
150
- if (!state.enabledNetworkMap[namespace]) {
122
+ if (!s.enabledNetworkMap[namespace]) {
151
123
  return;
152
124
  }
153
125
  // enable the network
154
- state.enabledNetworkMap[namespace][storageKey] = true;
126
+ s.enabledNetworkMap[namespace][storageKey] = true;
155
127
  });
156
128
  }
157
129
  /**
@@ -176,17 +148,17 @@ class NetworkEnablementController extends base_controller_1.BaseController {
176
148
  if (derivedNamespace !== namespace) {
177
149
  throw new Error(`Chain ID ${chainId} belongs to namespace ${derivedNamespace}, but namespace ${namespace} was specified`);
178
150
  }
179
- this.update((state) => {
151
+ this.update((s) => {
180
152
  // Ensure the namespace bucket exists
181
- __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, state, namespace);
153
+ __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, s, namespace);
182
154
  // Disable all networks in the specified namespace first
183
- if (state.enabledNetworkMap[namespace]) {
184
- Object.keys(state.enabledNetworkMap[namespace]).forEach((key) => {
185
- state.enabledNetworkMap[namespace][key] = false;
155
+ if (s.enabledNetworkMap[namespace]) {
156
+ Object.keys(s.enabledNetworkMap[namespace]).forEach((key) => {
157
+ s.enabledNetworkMap[namespace][key] = false;
186
158
  });
187
159
  }
188
160
  // Enable the target network in the specified namespace
189
- state.enabledNetworkMap[namespace][storageKey] = true;
161
+ s.enabledNetworkMap[namespace][storageKey] = true;
190
162
  });
191
163
  }
192
164
  /**
@@ -200,11 +172,11 @@ class NetworkEnablementController extends base_controller_1.BaseController {
200
172
  * Popular networks that don't exist in NetworkController or MultichainNetworkController configurations will be skipped silently.
201
173
  */
202
174
  enableAllPopularNetworks() {
203
- this.update((state) => {
175
+ this.update((s) => {
204
176
  // First disable all networks across all namespaces
205
- Object.keys(state.enabledNetworkMap).forEach((ns) => {
206
- Object.keys(state.enabledNetworkMap[ns]).forEach((key) => {
207
- state.enabledNetworkMap[ns][key] = false;
177
+ Object.keys(s.enabledNetworkMap).forEach((ns) => {
178
+ Object.keys(s.enabledNetworkMap[ns]).forEach((key) => {
179
+ s.enabledNetworkMap[ns][key] = false;
208
180
  });
209
181
  });
210
182
  // Get current network configurations to check if networks exist
@@ -216,36 +188,35 @@ class NetworkEnablementController extends base_controller_1.BaseController {
216
188
  // Check if network exists in NetworkController configurations
217
189
  if (networkControllerState.networkConfigurationsByChainId[chainId]) {
218
190
  // Ensure namespace bucket exists
219
- __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, state, namespace);
191
+ __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, s, namespace);
220
192
  // Enable the network
221
- state.enabledNetworkMap[namespace][storageKey] = true;
193
+ s.enabledNetworkMap[namespace][storageKey] = true;
222
194
  }
223
195
  });
224
196
  // Enable Solana mainnet if it exists in MultichainNetworkController configurations
225
197
  const solanaKeys = (0, utils_2.deriveKeys)(keyring_api_1.SolScope.Mainnet);
226
198
  if (multichainState.multichainNetworkConfigurationsByChainId[keyring_api_1.SolScope.Mainnet]) {
227
199
  // Ensure namespace bucket exists
228
- __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, state, solanaKeys.namespace);
200
+ __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, s, solanaKeys.namespace);
229
201
  // Enable Solana mainnet
230
- state.enabledNetworkMap[solanaKeys.namespace][solanaKeys.storageKey] =
231
- true;
202
+ s.enabledNetworkMap[solanaKeys.namespace][solanaKeys.storageKey] = true;
232
203
  }
233
204
  // Enable Bitcoin mainnet if it exists in MultichainNetworkController configurations
234
205
  const bitcoinKeys = (0, utils_2.deriveKeys)(keyring_api_1.BtcScope.Mainnet);
235
206
  if (multichainState.multichainNetworkConfigurationsByChainId[keyring_api_1.BtcScope.Mainnet]) {
236
207
  // Ensure namespace bucket exists
237
- __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, state, bitcoinKeys.namespace);
208
+ __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, s, bitcoinKeys.namespace);
238
209
  // Enable Bitcoin mainnet
239
- state.enabledNetworkMap[bitcoinKeys.namespace][bitcoinKeys.storageKey] =
210
+ s.enabledNetworkMap[bitcoinKeys.namespace][bitcoinKeys.storageKey] =
240
211
  true;
241
212
  }
242
213
  // Enable Tron mainnet if it exists in MultichainNetworkController configurations
243
214
  const tronKeys = (0, utils_2.deriveKeys)(keyring_api_1.TrxScope.Mainnet);
244
215
  if (multichainState.multichainNetworkConfigurationsByChainId[keyring_api_1.TrxScope.Mainnet]) {
245
216
  // Ensure namespace bucket exists
246
- __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, state, tronKeys.namespace);
217
+ __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, s, tronKeys.namespace);
247
218
  // Enable Tron mainnet
248
- state.enabledNetworkMap[tronKeys.namespace][tronKeys.storageKey] = true;
219
+ s.enabledNetworkMap[tronKeys.namespace][tronKeys.storageKey] = true;
249
220
  }
250
221
  });
251
222
  }
@@ -253,124 +224,39 @@ class NetworkEnablementController extends base_controller_1.BaseController {
253
224
  * Initializes the network enablement state from network controller configurations.
254
225
  *
255
226
  * This method reads the current network configurations from both NetworkController
256
- * and MultichainNetworkController and syncs the enabled network map and nativeAssetIdentifiers accordingly.
227
+ * and MultichainNetworkController and syncs the enabled network map accordingly.
257
228
  * It ensures proper namespace buckets exist for all configured networks and only
258
229
  * adds missing networks with a default value of false, preserving existing user settings.
259
230
  *
260
231
  * This method should be called after the NetworkController and MultichainNetworkController
261
232
  * have been initialized and their configurations are available.
262
233
  */
263
- async init() {
264
- // Get network configurations from NetworkController (EVM networks)
265
- const networkControllerState = this.messenger.call('NetworkController:getState');
266
- // Get network configurations from MultichainNetworkController (all networks)
267
- const multichainState = this.messenger.call('MultichainNetworkController:getState');
268
- // Build nativeAssetIdentifiers for EVM networks using chainid.network
269
- const evmNativeAssetUpdates = [];
270
- for (const [chainId, config] of Object.entries(networkControllerState.networkConfigurationsByChainId)) {
271
- const { caipChainId } = (0, utils_2.deriveKeys)(chainId);
272
- // Skip if already in state
273
- if (this.state.nativeAssetIdentifiers[caipChainId] !== undefined) {
274
- continue;
275
- }
276
- // Parse hex chainId to number for chainid.network lookup
277
- const numericChainId = parseInt(chainId, 16);
278
- // EVM networks: use getSlip44ByChainId (chainid.network data)
279
- // Default to 60 (Ethereum) if no specific mapping is found
280
- const slip44CoinType = (await services_1.Slip44Service.getSlip44ByChainId(numericChainId, config.nativeCurrency)) ?? 60;
281
- evmNativeAssetUpdates.push({
282
- caipChainId,
283
- identifier: buildNativeAssetIdentifier(caipChainId, slip44CoinType),
284
- });
285
- }
286
- // Update state synchronously
287
- this.update((state) => {
234
+ init() {
235
+ this.update((s) => {
236
+ // Get network configurations from NetworkController (EVM networks)
237
+ const networkControllerState = this.messenger.call('NetworkController:getState');
238
+ // Get network configurations from MultichainNetworkController (all networks)
239
+ const multichainState = this.messenger.call('MultichainNetworkController:getState');
288
240
  // Initialize namespace buckets for EVM networks from NetworkController
289
- Object.entries(networkControllerState.networkConfigurationsByChainId).forEach(([chainId]) => {
290
- var _a;
241
+ Object.keys(networkControllerState.networkConfigurationsByChainId).forEach((chainId) => {
291
242
  const { namespace, storageKey } = (0, utils_2.deriveKeys)(chainId);
292
- __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, state, namespace);
243
+ __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, s, namespace);
293
244
  // Only add network if it doesn't already exist in state (preserves user settings)
294
- (_a = state.enabledNetworkMap[namespace])[storageKey] ?? (_a[storageKey] = false);
245
+ if (s.enabledNetworkMap[namespace][storageKey] === undefined) {
246
+ s.enabledNetworkMap[namespace][storageKey] = false;
247
+ }
295
248
  });
296
- // Apply nativeAssetIdentifier updates
297
- for (const { caipChainId, identifier } of evmNativeAssetUpdates) {
298
- state.nativeAssetIdentifiers[caipChainId] = identifier;
299
- }
300
249
  // Initialize namespace buckets for all networks from MultichainNetworkController
301
250
  Object.keys(multichainState.multichainNetworkConfigurationsByChainId).forEach((chainId) => {
302
- var _a;
303
251
  const { namespace, storageKey } = (0, utils_2.deriveKeys)(chainId);
304
- __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, state, namespace);
252
+ __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, s, namespace);
305
253
  // Only add network if it doesn't already exist in state (preserves user settings)
306
- (_a = state.enabledNetworkMap[namespace])[storageKey] ?? (_a[storageKey] = false);
254
+ if (s.enabledNetworkMap[namespace][storageKey] === undefined) {
255
+ s.enabledNetworkMap[namespace][storageKey] = false;
256
+ }
307
257
  });
308
258
  });
309
259
  }
310
- /**
311
- * Initializes the native asset identifiers from network configurations.
312
- * This method should be called from the client during controller initialization
313
- * to populate the nativeAssetIdentifiers state based on actual network configurations.
314
- *
315
- * @param networks - Array of network configurations with chainId and nativeCurrency
316
- * @example
317
- * ```typescript
318
- * const evmNetworks = Object.values(networkControllerState.networkConfigurationsByChainId)
319
- * .map(config => ({
320
- * chainId: toEvmCaipChainId(config.chainId),
321
- * nativeCurrency: config.nativeCurrency,
322
- * }));
323
- *
324
- * const multichainNetworks = Object.values(multichainState.multichainNetworkConfigurationsByChainId)
325
- * .map(config => ({
326
- * chainId: config.chainId,
327
- * nativeCurrency: config.nativeCurrency,
328
- * }));
329
- *
330
- * await controller.initNativeAssetIdentifiers([...evmNetworks, ...multichainNetworks]);
331
- * ```
332
- */
333
- async initNativeAssetIdentifiers(networks) {
334
- // Process networks and collect updates
335
- const updates = [];
336
- for (const { chainId, nativeCurrency } of networks) {
337
- // Check if nativeCurrency is already in CAIP-19 format (e.g., "bip122:.../slip44:0")
338
- // Non-EVM networks from MultichainNetworkController use this format
339
- if (nativeCurrency.includes('/slip44:')) {
340
- updates.push({
341
- chainId,
342
- identifier: nativeCurrency,
343
- });
344
- continue;
345
- }
346
- // Extract namespace from CAIP-2 chainId
347
- const [namespace, reference] = chainId.split(':');
348
- let slip44CoinType;
349
- if (namespace === 'eip155') {
350
- // EVM networks: use getSlip44ByChainId (chainid.network data)
351
- // Default to 60 (Ethereum) if no specific mapping is found
352
- const numericChainId = parseInt(reference, 10);
353
- slip44CoinType =
354
- (await services_1.Slip44Service.getSlip44ByChainId(numericChainId, nativeCurrency)) ?? 60;
355
- }
356
- else {
357
- // Non-EVM networks: use getSlip44BySymbol (@metamask/slip44 package)
358
- slip44CoinType = services_1.Slip44Service.getSlip44BySymbol(nativeCurrency);
359
- }
360
- if (slip44CoinType !== undefined) {
361
- updates.push({
362
- chainId,
363
- identifier: buildNativeAssetIdentifier(chainId, slip44CoinType),
364
- });
365
- }
366
- }
367
- // Apply all updates synchronously
368
- this.update((state) => {
369
- for (const { chainId, identifier } of updates) {
370
- state.nativeAssetIdentifiers[chainId] = identifier;
371
- }
372
- });
373
- }
374
260
  /**
375
261
  * Disables a network for the user.
376
262
  *
@@ -388,8 +274,8 @@ class NetworkEnablementController extends base_controller_1.BaseController {
388
274
  disableNetwork(chainId) {
389
275
  const derivedKeys = (0, utils_2.deriveKeys)(chainId);
390
276
  const { namespace, storageKey } = derivedKeys;
391
- this.update((state) => {
392
- state.enabledNetworkMap[namespace][storageKey] = false;
277
+ this.update((s) => {
278
+ s.enabledNetworkMap[namespace][storageKey] = false;
393
279
  });
394
280
  }
395
281
  /**
@@ -407,53 +293,10 @@ class NetworkEnablementController extends base_controller_1.BaseController {
407
293
  }
408
294
  }
409
295
  exports.NetworkEnablementController = NetworkEnablementController;
410
- _NetworkEnablementController_instances = new WeakSet(), _NetworkEnablementController_onNativeCurrencyChange =
411
- /**
412
- * Handles changes to network nativeCurrency values.
413
- * Compares current and previous nativeCurrency maps to detect updates.
414
- *
415
- * @param currentNativeCurrencies - Current map of chainId to nativeCurrency
416
- * @param previousNativeCurrencies - Previous map of chainId to nativeCurrency
417
- */
418
- async function _NetworkEnablementController_onNativeCurrencyChange(currentNativeCurrencies, previousNativeCurrencies) {
419
- // Skip if no previous state (initial subscription)
420
- if (!previousNativeCurrencies) {
421
- return;
422
- }
423
- // Find chains where nativeCurrency has changed
424
- for (const [chainId, currentCurrency] of Object.entries(currentNativeCurrencies)) {
425
- const previousCurrency = previousNativeCurrencies[chainId];
426
- // Only update if the nativeCurrency changed (not for new chains - those are handled by networkAdded)
427
- if (previousCurrency !== undefined &&
428
- previousCurrency !== currentCurrency) {
429
- await __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_updateNativeAssetIdentifier).call(this, chainId, currentCurrency);
430
- }
431
- }
432
- }, _NetworkEnablementController_ensureNamespaceBucket = function _NetworkEnablementController_ensureNamespaceBucket(state, ns) {
296
+ _NetworkEnablementController_instances = new WeakSet(), _NetworkEnablementController_ensureNamespaceBucket = function _NetworkEnablementController_ensureNamespaceBucket(state, ns) {
433
297
  if (!state.enabledNetworkMap[ns]) {
434
298
  state.enabledNetworkMap[ns] = {};
435
299
  }
436
- }, _NetworkEnablementController_updateNativeAssetIdentifier =
437
- /**
438
- * Updates the native asset identifier for an EVM network based on its symbol.
439
- *
440
- * This method looks up the SLIP-44 coin type using chainid.network data
441
- * (via getSlip44ByChainId) and updates the nativeAssetIdentifiers state.
442
- * This is only called for EVM networks from NetworkController state changes.
443
- *
444
- * @param chainId - The chain ID of the network (Hex format)
445
- * @param symbol - The native currency symbol of the network (e.g., 'ETH')
446
- */
447
- async function _NetworkEnablementController_updateNativeAssetIdentifier(chainId, symbol) {
448
- const { caipChainId, reference } = (0, utils_2.deriveKeys)(chainId);
449
- // Parse hex chainId to number for chainid.network lookup
450
- const numericChainId = parseInt(reference, 16);
451
- // EVM networks: use getSlip44ByChainId (chainid.network data)
452
- // Default to 60 (Ethereum) if no specific mapping is found
453
- const slip44CoinType = (await services_1.Slip44Service.getSlip44ByChainId(numericChainId, symbol)) ?? 60;
454
- this.update((state) => {
455
- state.nativeAssetIdentifiers[caipChainId] = buildNativeAssetIdentifier(caipChainId, slip44CoinType);
456
- });
457
300
  }, _NetworkEnablementController_isInPopularNetworksMode = function _NetworkEnablementController_isInPopularNetworksMode() {
458
301
  // Get current network configurations to check which popular networks exist
459
302
  const networkControllerState = this.messenger.call('NetworkController:getState');
@@ -471,42 +314,22 @@ async function _NetworkEnablementController_updateNativeAssetIdentifier(chainId,
471
314
  return enabledPopularNetworksCount > 1;
472
315
  }, _NetworkEnablementController_removeNetworkEntry = function _NetworkEnablementController_removeNetworkEntry(chainId) {
473
316
  const derivedKeys = (0, utils_2.deriveKeys)(chainId);
474
- const { namespace, storageKey, caipChainId } = derivedKeys;
475
- this.update((state) => {
317
+ const { namespace, storageKey } = derivedKeys;
318
+ this.update((s) => {
476
319
  // fallback and enable ethereum mainnet
477
320
  if ((0, utils_2.isOnlyNetworkEnabledInNamespace)(this.state, derivedKeys)) {
478
- state.enabledNetworkMap[namespace][controller_utils_1.ChainId[controller_utils_1.BuiltInNetworkName.Mainnet]] = true;
321
+ s.enabledNetworkMap[namespace][controller_utils_1.ChainId[controller_utils_1.BuiltInNetworkName.Mainnet]] =
322
+ true;
479
323
  }
480
- if (namespace in state.enabledNetworkMap) {
481
- delete state.enabledNetworkMap[namespace][storageKey];
324
+ if (namespace in s.enabledNetworkMap) {
325
+ delete s.enabledNetworkMap[namespace][storageKey];
482
326
  }
483
- // Remove from nativeAssetIdentifiers as well
484
- delete state.nativeAssetIdentifiers[caipChainId];
485
327
  });
486
- }, _NetworkEnablementController_onAddNetwork =
487
- /**
488
- * Handles the addition of a new EVM network to the controller.
489
- *
490
- * @param chainId - The chain ID to add (Hex format)
491
- * @param nativeCurrency - The native currency symbol of the network (e.g., 'ETH')
492
- *
493
- * @description
494
- * - If in popular networks mode (>2 popular networks enabled) AND adding a popular network:
495
- * - Keep current selection (add but don't enable the new network)
496
- * - Otherwise:
497
- * - Switch to the newly added network (disable all others, enable this one)
498
- * - Also updates the nativeAssetIdentifiers with the CAIP-19-like identifier
499
- */
500
- async function _NetworkEnablementController_onAddNetwork(chainId, nativeCurrency) {
501
- const { namespace, storageKey, reference, caipChainId } = (0, utils_2.deriveKeys)(chainId);
502
- // Parse hex chainId to number for chainid.network lookup
503
- const numericChainId = parseInt(reference, 16);
504
- // EVM networks: use getSlip44ByChainId (chainid.network data)
505
- // Default to 60 (Ethereum) if no specific mapping is found
506
- const slip44CoinType = (await services_1.Slip44Service.getSlip44ByChainId(numericChainId, nativeCurrency)) ?? 60;
507
- this.update((state) => {
328
+ }, _NetworkEnablementController_onAddNetwork = function _NetworkEnablementController_onAddNetwork(chainId) {
329
+ const { namespace, storageKey, reference } = (0, utils_2.deriveKeys)(chainId);
330
+ this.update((s) => {
508
331
  // Ensure the namespace bucket exists
509
- __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, state, namespace);
332
+ __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_ensureNamespaceBucket).call(this, s, namespace);
510
333
  // Check if popular networks mode is active (>2 popular networks enabled)
511
334
  const inPopularNetworksMode = __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_isInPopularNetworksMode).call(this);
512
335
  // Check if the network being added is a popular network
@@ -515,20 +338,18 @@ async function _NetworkEnablementController_onAddNetwork(chainId, nativeCurrency
515
338
  const shouldKeepCurrentSelection = inPopularNetworksMode && isAddedNetworkPopular;
516
339
  if (shouldKeepCurrentSelection) {
517
340
  // Add the popular network but don't enable it (keep current selection)
518
- state.enabledNetworkMap[namespace][storageKey] = true;
341
+ s.enabledNetworkMap[namespace][storageKey] = true;
519
342
  }
520
343
  else {
521
344
  // Switch to the newly added network (disable all others, enable this one)
522
- Object.keys(state.enabledNetworkMap).forEach((ns) => {
523
- Object.keys(state.enabledNetworkMap[ns]).forEach((key) => {
524
- state.enabledNetworkMap[ns][key] = false;
345
+ Object.keys(s.enabledNetworkMap).forEach((ns) => {
346
+ Object.keys(s.enabledNetworkMap[ns]).forEach((key) => {
347
+ s.enabledNetworkMap[ns][key] = false;
525
348
  });
526
349
  });
527
350
  // Enable the newly added network
528
- state.enabledNetworkMap[namespace][storageKey] = true;
351
+ s.enabledNetworkMap[namespace][storageKey] = true;
529
352
  }
530
- // Update nativeAssetIdentifiers with the CAIP-19-like identifier
531
- state.nativeAssetIdentifiers[caipChainId] = buildNativeAssetIdentifier(caipChainId, slip44CoinType);
532
353
  });
533
354
  };
534
355
  //# sourceMappingURL=NetworkEnablementController.cjs.map