@metamask-previews/network-controller 24.2.0-preview-622f3f09 → 24.2.0-preview-bc80f5a1

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
@@ -9,8 +9,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
 
10
10
  ### Changed
11
11
 
12
- - **BREAKING:** Use `InternalProvider` instead of `SafeEventEmitterProvider` ([#6796](https://github.com/MetaMask/core/pull/6796))
13
- - Providers accessible either via network clients or global proxies no longer emit events (or inherit from EventEmitter, for that matter).
14
12
  - Bump `@metamask/utils` from `^11.8.0` to `^11.8.1` ([#6708](https://github.com/MetaMask/core/pull/6708))
15
13
  - Update `@metamask/eth-json-rpc-middleware` from `^17.0.1` to `^18.0.0` ([#6714](https://github.com/MetaMask/core/pull/6714))
16
14
  - Bump `@metamask/error-reporting-service` from `^2.1.0` to `^2.2.0` ([#6782](https://github.com/MetaMask/core/pull/6782))
@@ -81,6 +81,8 @@ var RpcEndpointType;
81
81
  * @returns The keys of an object, typed according to the type of the object
82
82
  * itself.
83
83
  */
84
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
85
+ // eslint-disable-next-line @typescript-eslint/naming-convention
84
86
  function knownKeysOf(
85
87
  // TODO: Replace `any` with type
86
88
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -133,7 +135,7 @@ function getDefaultInfuraNetworkConfigurationsByChainId() {
133
135
  return obj;
134
136
  }
135
137
  const rpcEndpointUrl =
136
- // False positive - this is a string.
138
+ // This ESLint rule mistakenly produces an error.
137
139
  // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
138
140
  `https://${infuraNetworkType}.infura.io/v3/{infuraProjectId}`;
139
141
  const networkConfiguration = {
@@ -425,21 +427,54 @@ class NetworkController extends base_controller_1.BaseController {
425
427
  __classPrivateFieldSet(this, _NetworkController_isRpcFailoverEnabled, isRpcFailoverEnabled, "f");
426
428
  __classPrivateFieldSet(this, _NetworkController_previouslySelectedNetworkClientId, this.state.selectedNetworkClientId, "f");
427
429
  __classPrivateFieldSet(this, _NetworkController_networkConfigurationsByNetworkClientId, buildNetworkConfigurationsByNetworkClientId(this.state.networkConfigurationsByChainId), "f");
428
- this.messagingSystem.registerActionHandler(`${this.name}:getEthQuery`, () => {
430
+ this.messagingSystem.registerActionHandler(
431
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
432
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
433
+ `${this.name}:getEthQuery`, () => {
429
434
  return __classPrivateFieldGet(this, _NetworkController_ethQuery, "f");
430
435
  });
431
- this.messagingSystem.registerActionHandler(`${this.name}:getNetworkClientById`, this.getNetworkClientById.bind(this));
432
- this.messagingSystem.registerActionHandler(`${this.name}:getEIP1559Compatibility`, this.getEIP1559Compatibility.bind(this));
433
- this.messagingSystem.registerActionHandler(`${this.name}:setActiveNetwork`, this.setActiveNetwork.bind(this));
434
- this.messagingSystem.registerActionHandler(`${this.name}:setProviderType`, this.setProviderType.bind(this));
435
- this.messagingSystem.registerActionHandler(`${this.name}:findNetworkClientIdByChainId`, this.findNetworkClientIdByChainId.bind(this));
436
- this.messagingSystem.registerActionHandler(`${this.name}:getNetworkConfigurationByChainId`, this.getNetworkConfigurationByChainId.bind(this));
437
- this.messagingSystem.registerActionHandler(`${this.name}:getNetworkConfigurationByNetworkClientId`, this.getNetworkConfigurationByNetworkClientId.bind(this));
436
+ this.messagingSystem.registerActionHandler(
437
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
438
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
439
+ `${this.name}:getNetworkClientById`, this.getNetworkClientById.bind(this));
440
+ this.messagingSystem.registerActionHandler(
441
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
442
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
443
+ `${this.name}:getEIP1559Compatibility`, this.getEIP1559Compatibility.bind(this));
444
+ this.messagingSystem.registerActionHandler(
445
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
446
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
447
+ `${this.name}:setActiveNetwork`, this.setActiveNetwork.bind(this));
448
+ this.messagingSystem.registerActionHandler(
449
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
450
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
451
+ `${this.name}:setProviderType`, this.setProviderType.bind(this));
452
+ this.messagingSystem.registerActionHandler(
453
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
454
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
455
+ `${this.name}:findNetworkClientIdByChainId`, this.findNetworkClientIdByChainId.bind(this));
456
+ this.messagingSystem.registerActionHandler(
457
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
458
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
459
+ `${this.name}:getNetworkConfigurationByChainId`, this.getNetworkConfigurationByChainId.bind(this));
460
+ this.messagingSystem.registerActionHandler(
461
+ // ESLint is mistaken here; `name` is a string.
462
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
463
+ `${this.name}:getNetworkConfigurationByNetworkClientId`, this.getNetworkConfigurationByNetworkClientId.bind(this));
438
464
  this.messagingSystem.registerActionHandler(`${this.name}:getSelectedNetworkClient`, this.getSelectedNetworkClient.bind(this));
439
465
  this.messagingSystem.registerActionHandler(`${this.name}:getSelectedChainId`, this.getSelectedChainId.bind(this));
440
- this.messagingSystem.registerActionHandler(`${this.name}:addNetwork`, this.addNetwork.bind(this));
441
- this.messagingSystem.registerActionHandler(`${this.name}:removeNetwork`, this.removeNetwork.bind(this));
442
- this.messagingSystem.registerActionHandler(`${this.name}:updateNetwork`, this.updateNetwork.bind(this));
466
+ this.messagingSystem.registerActionHandler(
467
+ // ESLint is mistaken here; `name` is a string.
468
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
469
+ `${this.name}:addNetwork`, this.addNetwork.bind(this));
470
+ this.messagingSystem.registerActionHandler(
471
+ // ESLint is mistaken here; `name` is a string.
472
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
473
+ `${this.name}:removeNetwork`, this.removeNetwork.bind(this));
474
+ this.messagingSystem.registerActionHandler(
475
+ // ESLint is mistaken here; `name` is a string.
476
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
477
+ `${this.name}:updateNetwork`, this.updateNetwork.bind(this));
443
478
  }
444
479
  /**
445
480
  * Enables the RPC failover functionality. That is, if any RPC endpoints are
@@ -459,7 +494,6 @@ class NetworkController extends base_controller_1.BaseController {
459
494
  }
460
495
  /**
461
496
  * Accesses the provider and block tracker for the currently selected network.
462
- *
463
497
  * @returns The proxy and block tracker proxies.
464
498
  * @deprecated This method has been replaced by `getSelectedNetworkClient` (which has a more easily used return type) and will be removed in a future release.
465
499
  */
@@ -515,13 +549,19 @@ class NetworkController extends base_controller_1.BaseController {
515
549
  // This is impossible to reach
516
550
  /* istanbul ignore if */
517
551
  if (!infuraNetworkClient) {
518
- throw new Error(`No Infura network client was found with the ID "${networkClientId}".`);
552
+ throw new Error(
553
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
554
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
555
+ `No Infura network client was found with the ID "${networkClientId}".`);
519
556
  }
520
557
  return infuraNetworkClient;
521
558
  }
522
559
  const customNetworkClient = autoManagedNetworkClientRegistry[types_1.NetworkClientType.Custom][networkClientId];
523
560
  if (!customNetworkClient) {
524
- throw new Error(`No custom network client was found with the ID "${networkClientId}".`);
561
+ throw new Error(
562
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
563
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
564
+ `No custom network client was found with the ID "${networkClientId}".`);
525
565
  }
526
566
  return customNetworkClient;
527
567
  }
@@ -580,7 +620,10 @@ class NetworkController extends base_controller_1.BaseController {
580
620
  */
581
621
  async setProviderType(type) {
582
622
  if (type === controller_utils_1.NetworkType.rpc) {
583
- throw new Error(`NetworkController - cannot call "setProviderType" with type "${controller_utils_1.NetworkType.rpc}". Use "setActiveNetwork"`);
623
+ throw new Error(
624
+ // This ESLint rule mistakenly produces an error.
625
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
626
+ `NetworkController - cannot call "setProviderType" with type "${controller_utils_1.NetworkType.rpc}". Use "setActiveNetwork"`);
584
627
  }
585
628
  if (!(0, controller_utils_1.isInfuraNetworkType)(type)) {
586
629
  throw new Error(`Unknown Infura provider type "${String(type)}".`);
@@ -873,7 +916,10 @@ class NetworkController extends base_controller_1.BaseController {
873
916
  networkClientOperation.oldRpcEndpoint.networkClientId ===
874
917
  this.state.selectedNetworkClientId);
875
918
  })) {
876
- throw new Error(`Could not update network: Cannot update RPC endpoints in such a way that the selected network '${this.state.selectedNetworkClientId}' would be removed without a replacement. Choose a different RPC endpoint as the selected network via the \`replacementSelectedRpcEndpointIndex\` option.`);
919
+ throw new Error(
920
+ // This ESLint rule mistakenly produces an error.
921
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
922
+ `Could not update network: Cannot update RPC endpoints in such a way that the selected network '${this.state.selectedNetworkClientId}' would be removed without a replacement. Choose a different RPC endpoint as the selected network via the \`replacementSelectedRpcEndpointIndex\` option.`);
877
923
  }
878
924
  __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_registerNetworkClientsAsNeeded).call(this, {
879
925
  networkFields: fields,
@@ -1275,10 +1321,16 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
1275
1321
  const existingNetworkConfigurationViaChainId = this.state.networkConfigurationsByChainId[networkFields.chainId];
1276
1322
  if (existingNetworkConfigurationViaChainId !== undefined) {
1277
1323
  if (existingNetworkConfiguration === null) {
1278
- throw new Error(`Could not add network for chain ${args.networkFields.chainId} as another network for that chain already exists ('${existingNetworkConfigurationViaChainId.name}')`);
1324
+ throw new Error(
1325
+ // This ESLint rule mistakenly produces an error.
1326
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1327
+ `Could not add network for chain ${args.networkFields.chainId} as another network for that chain already exists ('${existingNetworkConfigurationViaChainId.name}')`);
1279
1328
  }
1280
1329
  else {
1281
- throw new Error(`Cannot move network from chain ${existingNetworkConfiguration.chainId} to ${networkFields.chainId} as another network for that chain already exists ('${existingNetworkConfigurationViaChainId.name}')`);
1330
+ throw new Error(
1331
+ // This ESLint rule mistakenly produces an error.
1332
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1333
+ `Cannot move network from chain ${existingNetworkConfiguration.chainId} to ${networkFields.chainId} as another network for that chain already exists ('${existingNetworkConfigurationViaChainId.name}')`);
1282
1334
  }
1283
1335
  }
1284
1336
  }
@@ -1294,7 +1346,10 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
1294
1346
  }
1295
1347
  for (const rpcEndpointFields of networkFields.rpcEndpoints) {
1296
1348
  if (!isValidUrl(rpcEndpointFields.url)) {
1297
- throw new Error(`${errorMessagePrefix}: An entry in \`rpcEndpoints\` has invalid URL '${rpcEndpointFields.url}'`);
1349
+ throw new Error(
1350
+ // This ESLint rule mistakenly produces an error.
1351
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1352
+ `${errorMessagePrefix}: An entry in \`rpcEndpoints\` has invalid URL '${rpcEndpointFields.url}'`);
1298
1353
  }
1299
1354
  const networkClientId = 'networkClientId' in rpcEndpointFields
1300
1355
  ? rpcEndpointFields.networkClientId
@@ -1302,13 +1357,19 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
1302
1357
  if (rpcEndpointFields.type === RpcEndpointType.Custom &&
1303
1358
  networkClientId !== undefined &&
1304
1359
  (0, controller_utils_1.isInfuraNetworkType)(networkClientId)) {
1305
- throw new Error(`${errorMessagePrefix}: Custom RPC endpoint '${rpcEndpointFields.url}' has invalid network client ID '${networkClientId}'`);
1360
+ throw new Error(
1361
+ // This is a string.
1362
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1363
+ `${errorMessagePrefix}: Custom RPC endpoint '${rpcEndpointFields.url}' has invalid network client ID '${networkClientId}'`);
1306
1364
  }
1307
1365
  if (mode === 'update' &&
1308
1366
  networkClientId !== undefined &&
1309
1367
  rpcEndpointFields.type === RpcEndpointType.Custom &&
1310
1368
  !Object.values(autoManagedNetworkClientRegistry).some((networkClientsById) => networkClientId in networkClientsById)) {
1311
- throw new Error(`${errorMessagePrefix}: RPC endpoint '${rpcEndpointFields.url}' refers to network client '${networkClientId}' that does not exist`);
1369
+ throw new Error(
1370
+ // This is a string.
1371
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1372
+ `${errorMessagePrefix}: RPC endpoint '${rpcEndpointFields.url}' refers to network client '${networkClientId}' that does not exist`);
1312
1373
  }
1313
1374
  if (networkFields.rpcEndpoints.some((otherRpcEndpointFields) => otherRpcEndpointFields !== rpcEndpointFields &&
1314
1375
  URI.equal(otherRpcEndpointFields.url, rpcEndpointFields.url))) {
@@ -1322,10 +1383,16 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
1322
1383
  const rpcEndpoint = networkConfiguration.rpcEndpoints.find((existingRpcEndpoint) => URI.equal(rpcEndpointFields.url, existingRpcEndpoint.url));
1323
1384
  if (rpcEndpoint) {
1324
1385
  if (mode === 'update') {
1325
- throw new Error(`Could not update network to point to same RPC endpoint as existing network for chain ${networkConfiguration.chainId} ('${networkConfiguration.name}')`);
1386
+ throw new Error(
1387
+ // This ESLint rule mistakenly produces an error.
1388
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1389
+ `Could not update network to point to same RPC endpoint as existing network for chain ${networkConfiguration.chainId} ('${networkConfiguration.name}')`);
1326
1390
  }
1327
1391
  else {
1328
- throw new Error(`Could not add network that points to same RPC endpoint as existing network for chain ${networkConfiguration.chainId} ('${networkConfiguration.name}')`);
1392
+ throw new Error(
1393
+ // This ESLint rule mistakenly produces an error.
1394
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1395
+ `Could not add network that points to same RPC endpoint as existing network for chain ${networkConfiguration.chainId} ('${networkConfiguration.name}')`);
1329
1396
  }
1330
1397
  }
1331
1398
  }
@@ -1353,8 +1420,12 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
1353
1420
  const infuraChainId = controller_utils_1.ChainId[infuraNetworkName];
1354
1421
  if (networkFields.chainId !== infuraChainId) {
1355
1422
  throw new Error(mode === 'add'
1356
- ? `Could not add network with chain ID ${networkFields.chainId} and Infura RPC endpoint for '${infuraNetworkNickname}' which represents ${infuraChainId}, as the two conflict`
1357
- : `Could not update network with chain ID ${networkFields.chainId} and Infura RPC endpoint for '${infuraNetworkNickname}' which represents ${infuraChainId}, as the two conflict`);
1423
+ ? // This is a string.
1424
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1425
+ `Could not add network with chain ID ${networkFields.chainId} and Infura RPC endpoint for '${infuraNetworkNickname}' which represents ${infuraChainId}, as the two conflict`
1426
+ : // This is a string.
1427
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1428
+ `Could not update network with chain ID ${networkFields.chainId} and Infura RPC endpoint for '${infuraNetworkNickname}' which represents ${infuraChainId}, as the two conflict`);
1358
1429
  }
1359
1430
  }
1360
1431
  if (networkFields.rpcEndpoints[networkFields.defaultRpcEndpointIndex] ===
@@ -1545,15 +1616,13 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
1545
1616
  __classPrivateFieldGet(this, _NetworkController_providerProxy, "f").setTarget(__classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClient, "f").provider);
1546
1617
  }
1547
1618
  else {
1548
- __classPrivateFieldSet(this, _NetworkController_providerProxy, (0, swappable_obj_proxy_1.createSwappableProxy)(__classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClient, "f").provider), "f");
1619
+ __classPrivateFieldSet(this, _NetworkController_providerProxy, (0, swappable_obj_proxy_1.createEventEmitterProxy)(__classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClient, "f").provider), "f");
1549
1620
  }
1550
1621
  if (__classPrivateFieldGet(this, _NetworkController_blockTrackerProxy, "f")) {
1551
1622
  __classPrivateFieldGet(this, _NetworkController_blockTrackerProxy, "f").setTarget(__classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClient, "f").blockTracker);
1552
1623
  }
1553
1624
  else {
1554
- __classPrivateFieldSet(this, _NetworkController_blockTrackerProxy, (0, swappable_obj_proxy_1.createEventEmitterProxy)(__classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClient, "f").blockTracker, {
1555
- eventFilter: 'skipInternal',
1556
- }), "f");
1625
+ __classPrivateFieldSet(this, _NetworkController_blockTrackerProxy, (0, swappable_obj_proxy_1.createEventEmitterProxy)(__classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClient, "f").blockTracker, { eventFilter: 'skipInternal' }), "f");
1557
1626
  }
1558
1627
  __classPrivateFieldSet(this, _NetworkController_ethQuery, new eth_query_1.default(__classPrivateFieldGet(this, _NetworkController_providerProxy, "f")), "f");
1559
1628
  };