@metamask-previews/network-controller 24.3.0-preview-e9856975 → 24.3.0-preview-83095132

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 CHANGED
@@ -7,11 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
- ### Changed
11
-
12
- - **BREAKING:** Use new `Messenger` from `@metamask/messenger` ([#6386](https://github.com/MetaMask/core/pull/6386))
13
- - Previously, `NetworkController` accepted a `RestrictedMessenger` instance from `@metamask/base-controller`.
14
-
15
10
  ## [24.3.0]
16
11
 
17
12
  ### Changed
@@ -39,7 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  var _NetworkController_instances, _NetworkController_ethQuery, _NetworkController_infuraProjectId, _NetworkController_previouslySelectedNetworkClientId, _NetworkController_providerProxy, _NetworkController_blockTrackerProxy, _NetworkController_autoManagedNetworkClientRegistry, _NetworkController_autoManagedNetworkClient, _NetworkController_log, _NetworkController_getRpcServiceOptions, _NetworkController_getBlockTrackerOptions, _NetworkController_networkConfigurationsByNetworkClientId, _NetworkController_isRpcFailoverEnabled, _NetworkController_updateRpcFailoverEnabled, _NetworkController_refreshNetwork, _NetworkController_determineNetworkMetadata, _NetworkController_lookupGivenNetwork, _NetworkController_lookupSelectedNetwork, _NetworkController_updateMetadataForNetwork, _NetworkController_getLatestBlock, _NetworkController_determineEIP1559Compatibility, _NetworkController_validateNetworkFields, _NetworkController_determineNetworkConfigurationToPersist, _NetworkController_registerNetworkClientsAsNeeded, _NetworkController_unregisterNetworkClientsAsNeeded, _NetworkController_updateNetworkConfigurations, _NetworkController_ensureAutoManagedNetworkClientRegistryPopulated, _NetworkController_createAutoManagedNetworkClientRegistry, _NetworkController_applyNetworkSelection;
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
41
  exports.NetworkController = exports.selectAvailableNetworkClientIds = exports.getAvailableNetworkClientIds = exports.selectNetworkConfigurations = exports.getNetworkConfigurations = exports.getDefaultNetworkControllerState = exports.knownKeysOf = exports.RpcEndpointType = void 0;
42
- const next_1 = require("@metamask/base-controller/next");
42
+ const base_controller_1 = require("@metamask/base-controller");
43
43
  const controller_utils_1 = require("@metamask/controller-utils");
44
44
  const eth_query_1 = __importDefault(require("@metamask/eth-query"));
45
45
  const rpc_errors_1 = require("@metamask/rpc-errors");
@@ -365,7 +365,7 @@ function buildNetworkConfigurationsByNetworkClientId(networkConfigurationsByChai
365
365
  /**
366
366
  * Controller that creates and manages an Ethereum network provider.
367
367
  */
368
- class NetworkController extends next_1.BaseController {
368
+ class NetworkController extends base_controller_1.BaseController {
369
369
  /**
370
370
  * Constructs a NetworkController.
371
371
  *
@@ -388,19 +388,19 @@ class NetworkController extends next_1.BaseController {
388
388
  selectedNetworkClientId: {
389
389
  includeInStateLogs: true,
390
390
  persist: true,
391
- includeInDebugSnapshot: false,
391
+ anonymous: false,
392
392
  usedInUi: true,
393
393
  },
394
394
  networksMetadata: {
395
395
  includeInStateLogs: true,
396
396
  persist: true,
397
- includeInDebugSnapshot: false,
397
+ anonymous: false,
398
398
  usedInUi: true,
399
399
  },
400
400
  networkConfigurationsByChainId: {
401
401
  includeInStateLogs: true,
402
402
  persist: true,
403
- includeInDebugSnapshot: false,
403
+ anonymous: false,
404
404
  usedInUi: true,
405
405
  },
406
406
  },
@@ -427,51 +427,51 @@ class NetworkController extends next_1.BaseController {
427
427
  __classPrivateFieldSet(this, _NetworkController_isRpcFailoverEnabled, isRpcFailoverEnabled, "f");
428
428
  __classPrivateFieldSet(this, _NetworkController_previouslySelectedNetworkClientId, this.state.selectedNetworkClientId, "f");
429
429
  __classPrivateFieldSet(this, _NetworkController_networkConfigurationsByNetworkClientId, buildNetworkConfigurationsByNetworkClientId(this.state.networkConfigurationsByChainId), "f");
430
- this.messenger.registerActionHandler(
430
+ this.messagingSystem.registerActionHandler(
431
431
  // TODO: Either fix this lint violation or explain why it's necessary to ignore.
432
432
  // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
433
433
  `${this.name}:getEthQuery`, () => {
434
434
  return __classPrivateFieldGet(this, _NetworkController_ethQuery, "f");
435
435
  });
436
- this.messenger.registerActionHandler(
436
+ this.messagingSystem.registerActionHandler(
437
437
  // TODO: Either fix this lint violation or explain why it's necessary to ignore.
438
438
  // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
439
439
  `${this.name}:getNetworkClientById`, this.getNetworkClientById.bind(this));
440
- this.messenger.registerActionHandler(
440
+ this.messagingSystem.registerActionHandler(
441
441
  // TODO: Either fix this lint violation or explain why it's necessary to ignore.
442
442
  // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
443
443
  `${this.name}:getEIP1559Compatibility`, this.getEIP1559Compatibility.bind(this));
444
- this.messenger.registerActionHandler(
444
+ this.messagingSystem.registerActionHandler(
445
445
  // TODO: Either fix this lint violation or explain why it's necessary to ignore.
446
446
  // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
447
447
  `${this.name}:setActiveNetwork`, this.setActiveNetwork.bind(this));
448
- this.messenger.registerActionHandler(
448
+ this.messagingSystem.registerActionHandler(
449
449
  // TODO: Either fix this lint violation or explain why it's necessary to ignore.
450
450
  // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
451
451
  `${this.name}:setProviderType`, this.setProviderType.bind(this));
452
- this.messenger.registerActionHandler(
452
+ this.messagingSystem.registerActionHandler(
453
453
  // TODO: Either fix this lint violation or explain why it's necessary to ignore.
454
454
  // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
455
455
  `${this.name}:findNetworkClientIdByChainId`, this.findNetworkClientIdByChainId.bind(this));
456
- this.messenger.registerActionHandler(
456
+ this.messagingSystem.registerActionHandler(
457
457
  // TODO: Either fix this lint violation or explain why it's necessary to ignore.
458
458
  // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
459
459
  `${this.name}:getNetworkConfigurationByChainId`, this.getNetworkConfigurationByChainId.bind(this));
460
- this.messenger.registerActionHandler(
460
+ this.messagingSystem.registerActionHandler(
461
461
  // ESLint is mistaken here; `name` is a string.
462
462
  // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
463
463
  `${this.name}:getNetworkConfigurationByNetworkClientId`, this.getNetworkConfigurationByNetworkClientId.bind(this));
464
- this.messenger.registerActionHandler(`${this.name}:getSelectedNetworkClient`, this.getSelectedNetworkClient.bind(this));
465
- this.messenger.registerActionHandler(`${this.name}:getSelectedChainId`, this.getSelectedChainId.bind(this));
466
- this.messenger.registerActionHandler(
464
+ this.messagingSystem.registerActionHandler(`${this.name}:getSelectedNetworkClient`, this.getSelectedNetworkClient.bind(this));
465
+ this.messagingSystem.registerActionHandler(`${this.name}:getSelectedChainId`, this.getSelectedChainId.bind(this));
466
+ this.messagingSystem.registerActionHandler(
467
467
  // ESLint is mistaken here; `name` is a string.
468
468
  // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
469
469
  `${this.name}:addNetwork`, this.addNetwork.bind(this));
470
- this.messenger.registerActionHandler(
470
+ this.messagingSystem.registerActionHandler(
471
471
  // ESLint is mistaken here; `name` is a string.
472
472
  // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
473
473
  `${this.name}:removeNetwork`, this.removeNetwork.bind(this));
474
- this.messenger.registerActionHandler(
474
+ this.messagingSystem.registerActionHandler(
475
475
  // ESLint is mistaken here; `name` is a string.
476
476
  // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
477
477
  `${this.name}:updateNetwork`, this.updateNetwork.bind(this));
@@ -758,7 +758,7 @@ class NetworkController extends next_1.BaseController {
758
758
  networkConfigurationToPersist: newNetworkConfiguration,
759
759
  });
760
760
  });
761
- this.messenger.publish(`${controllerName}:networkAdded`, newNetworkConfiguration);
761
+ this.messagingSystem.publish(`${controllerName}:networkAdded`, newNetworkConfiguration);
762
762
  return newNetworkConfiguration;
763
763
  }
764
764
  /**
@@ -1009,7 +1009,7 @@ class NetworkController extends next_1.BaseController {
1009
1009
  existingNetworkConfiguration,
1010
1010
  });
1011
1011
  });
1012
- this.messenger.publish('NetworkController:networkRemoved', existingNetworkConfiguration);
1012
+ this.messagingSystem.publish('NetworkController:networkRemoved', existingNetworkConfiguration);
1013
1013
  }
1014
1014
  /**
1015
1015
  * Assuming that the network has been previously switched, switches to this
@@ -1101,9 +1101,9 @@ _NetworkController_ethQuery = new WeakMap(), _NetworkController_infuraProjectId
1101
1101
  * @param options.updateState - Allows for updating state.
1102
1102
  */
1103
1103
  async function _NetworkController_refreshNetwork(networkClientId, options = {}) {
1104
- this.messenger.publish('NetworkController:networkWillChange', this.state);
1104
+ this.messagingSystem.publish('NetworkController:networkWillChange', this.state);
1105
1105
  __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_applyNetworkSelection).call(this, networkClientId, options);
1106
- this.messenger.publish('NetworkController:networkDidChange', this.state);
1106
+ this.messagingSystem.publish('NetworkController:networkDidChange', this.state);
1107
1107
  await this.lookupNetwork();
1108
1108
  }, _NetworkController_determineNetworkMetadata =
1109
1109
  /**
@@ -1204,7 +1204,7 @@ async function _NetworkController_lookupSelectedNetwork() {
1204
1204
  const listener = () => {
1205
1205
  networkChanged = true;
1206
1206
  try {
1207
- this.messenger.unsubscribe('NetworkController:networkDidChange', listener);
1207
+ this.messagingSystem.unsubscribe('NetworkController:networkDidChange', listener);
1208
1208
  }
1209
1209
  catch (error) {
1210
1210
  // In theory, this `catch` should not be necessary given that this error
@@ -1224,7 +1224,7 @@ async function _NetworkController_lookupSelectedNetwork() {
1224
1224
  }
1225
1225
  }
1226
1226
  };
1227
- this.messenger.subscribe('NetworkController:networkDidChange', listener);
1227
+ this.messagingSystem.subscribe('NetworkController:networkDidChange', listener);
1228
1228
  const { isInfura, networkStatus, isEIP1559Compatible } = await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_determineNetworkMetadata).call(this, this.state.selectedNetworkClientId);
1229
1229
  if (networkChanged) {
1230
1230
  // If the network has changed, then `lookupNetwork` either has been or is
@@ -1232,7 +1232,7 @@ async function _NetworkController_lookupSelectedNetwork() {
1232
1232
  return;
1233
1233
  }
1234
1234
  try {
1235
- this.messenger.unsubscribe('NetworkController:networkDidChange', listener);
1235
+ this.messagingSystem.unsubscribe('NetworkController:networkDidChange', listener);
1236
1236
  }
1237
1237
  catch (error) {
1238
1238
  if (!(error instanceof Error) ||
@@ -1244,17 +1244,17 @@ async function _NetworkController_lookupSelectedNetwork() {
1244
1244
  __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_updateMetadataForNetwork).call(this, this.state.selectedNetworkClientId, networkStatus, isEIP1559Compatible);
1245
1245
  if (isInfura) {
1246
1246
  if (networkStatus === constants_1.NetworkStatus.Available) {
1247
- this.messenger.publish('NetworkController:infuraIsUnblocked');
1247
+ this.messagingSystem.publish('NetworkController:infuraIsUnblocked');
1248
1248
  }
1249
1249
  else if (networkStatus === constants_1.NetworkStatus.Blocked) {
1250
- this.messenger.publish('NetworkController:infuraIsBlocked');
1250
+ this.messagingSystem.publish('NetworkController:infuraIsBlocked');
1251
1251
  }
1252
1252
  }
1253
1253
  else {
1254
1254
  // Always publish infuraIsUnblocked regardless of network status to
1255
1255
  // prevent consumers from being stuck in a blocked state if they were
1256
1256
  // previously connected to an Infura network that was blocked
1257
- this.messenger.publish('NetworkController:infuraIsUnblocked');
1257
+ this.messagingSystem.publish('NetworkController:infuraIsUnblocked');
1258
1258
  }
1259
1259
  }, _NetworkController_updateMetadataForNetwork = function _NetworkController_updateMetadataForNetwork(networkClientId, networkStatus, isEIP1559Compatible) {
1260
1260
  this.update((state) => {
@@ -1469,7 +1469,7 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
1469
1469
  },
1470
1470
  getRpcServiceOptions: __classPrivateFieldGet(this, _NetworkController_getRpcServiceOptions, "f"),
1471
1471
  getBlockTrackerOptions: __classPrivateFieldGet(this, _NetworkController_getBlockTrackerOptions, "f"),
1472
- messenger: this.messenger,
1472
+ messenger: this.messagingSystem,
1473
1473
  isRpcFailoverEnabled: __classPrivateFieldGet(this, _NetworkController_isRpcFailoverEnabled, "f"),
1474
1474
  logger: __classPrivateFieldGet(this, _NetworkController_log, "f"),
1475
1475
  });
@@ -1485,7 +1485,7 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
1485
1485
  },
1486
1486
  getRpcServiceOptions: __classPrivateFieldGet(this, _NetworkController_getRpcServiceOptions, "f"),
1487
1487
  getBlockTrackerOptions: __classPrivateFieldGet(this, _NetworkController_getBlockTrackerOptions, "f"),
1488
- messenger: this.messenger,
1488
+ messenger: this.messagingSystem,
1489
1489
  isRpcFailoverEnabled: __classPrivateFieldGet(this, _NetworkController_isRpcFailoverEnabled, "f"),
1490
1490
  logger: __classPrivateFieldGet(this, _NetworkController_log, "f"),
1491
1491
  });
@@ -1545,7 +1545,7 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
1545
1545
  },
1546
1546
  getRpcServiceOptions: __classPrivateFieldGet(this, _NetworkController_getRpcServiceOptions, "f"),
1547
1547
  getBlockTrackerOptions: __classPrivateFieldGet(this, _NetworkController_getBlockTrackerOptions, "f"),
1548
- messenger: this.messenger,
1548
+ messenger: this.messagingSystem,
1549
1549
  isRpcFailoverEnabled: __classPrivateFieldGet(this, _NetworkController_isRpcFailoverEnabled, "f"),
1550
1550
  logger: __classPrivateFieldGet(this, _NetworkController_log, "f"),
1551
1551
  }),
@@ -1563,7 +1563,7 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
1563
1563
  },
1564
1564
  getRpcServiceOptions: __classPrivateFieldGet(this, _NetworkController_getRpcServiceOptions, "f"),
1565
1565
  getBlockTrackerOptions: __classPrivateFieldGet(this, _NetworkController_getBlockTrackerOptions, "f"),
1566
- messenger: this.messenger,
1566
+ messenger: this.messagingSystem,
1567
1567
  isRpcFailoverEnabled: __classPrivateFieldGet(this, _NetworkController_isRpcFailoverEnabled, "f"),
1568
1568
  logger: __classPrivateFieldGet(this, _NetworkController_log, "f"),
1569
1569
  }),