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