@metamask-previews/network-controller 25.0.0-preview-eee46d4b → 25.0.0-preview-ac95634
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 +2 -0
- package/dist/NetworkController.cjs +30 -99
- package/dist/NetworkController.cjs.map +1 -1
- package/dist/NetworkController.d.cts +1 -15
- package/dist/NetworkController.d.cts.map +1 -1
- package/dist/NetworkController.d.mts +1 -15
- package/dist/NetworkController.d.mts.map +1 -1
- package/dist/NetworkController.mjs +31 -100
- package/dist/NetworkController.mjs.map +1 -1
- package/dist/create-auto-managed-network-client.cjs +0 -2
- package/dist/create-auto-managed-network-client.cjs.map +1 -1
- package/dist/create-auto-managed-network-client.d.cts.map +1 -1
- package/dist/create-auto-managed-network-client.d.mts.map +1 -1
- package/dist/create-auto-managed-network-client.mjs +0 -2
- package/dist/create-auto-managed-network-client.mjs.map +1 -1
- package/dist/create-network-client.cjs +0 -2
- package/dist/create-network-client.cjs.map +1 -1
- package/dist/create-network-client.mjs +0 -2
- package/dist/create-network-client.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +2 -2
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +2 -2
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,8 @@ 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).
|
|
12
14
|
- Bump `@metamask/controller-utils` from `^11.14.1` to `^11.15.0` ([#7003](https://github.com/MetaMask/core/pull/7003))
|
|
13
15
|
|
|
14
16
|
## [25.0.0]
|
|
@@ -81,8 +81,6 @@ 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
|
|
86
84
|
function knownKeysOf(
|
|
87
85
|
// TODO: Replace `any` with type
|
|
88
86
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -135,7 +133,7 @@ function getDefaultInfuraNetworkConfigurationsByChainId() {
|
|
|
135
133
|
return obj;
|
|
136
134
|
}
|
|
137
135
|
const rpcEndpointUrl =
|
|
138
|
-
//
|
|
136
|
+
// False positive - this is a string.
|
|
139
137
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
140
138
|
`https://${infuraNetworkType}.infura.io/v3/{infuraProjectId}`;
|
|
141
139
|
const networkConfiguration = {
|
|
@@ -427,54 +425,21 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
427
425
|
__classPrivateFieldSet(this, _NetworkController_isRpcFailoverEnabled, isRpcFailoverEnabled, "f");
|
|
428
426
|
__classPrivateFieldSet(this, _NetworkController_previouslySelectedNetworkClientId, this.state.selectedNetworkClientId, "f");
|
|
429
427
|
__classPrivateFieldSet(this, _NetworkController_networkConfigurationsByNetworkClientId, buildNetworkConfigurationsByNetworkClientId(this.state.networkConfigurationsByChainId), "f");
|
|
430
|
-
this.messenger.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`, () => {
|
|
428
|
+
this.messenger.registerActionHandler(`${this.name}:getEthQuery`, () => {
|
|
434
429
|
return __classPrivateFieldGet(this, _NetworkController_ethQuery, "f");
|
|
435
430
|
});
|
|
436
|
-
this.messenger.registerActionHandler(
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
`${this.name}:
|
|
440
|
-
this.messenger.registerActionHandler(
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
`${this.name}:getEIP1559Compatibility`, this.getEIP1559Compatibility.bind(this));
|
|
444
|
-
this.messenger.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.messenger.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.messenger.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.messenger.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.messenger.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));
|
|
431
|
+
this.messenger.registerActionHandler(`${this.name}:getNetworkClientById`, this.getNetworkClientById.bind(this));
|
|
432
|
+
this.messenger.registerActionHandler(`${this.name}:getEIP1559Compatibility`, this.getEIP1559Compatibility.bind(this));
|
|
433
|
+
this.messenger.registerActionHandler(`${this.name}:setActiveNetwork`, this.setActiveNetwork.bind(this));
|
|
434
|
+
this.messenger.registerActionHandler(`${this.name}:setProviderType`, this.setProviderType.bind(this));
|
|
435
|
+
this.messenger.registerActionHandler(`${this.name}:findNetworkClientIdByChainId`, this.findNetworkClientIdByChainId.bind(this));
|
|
436
|
+
this.messenger.registerActionHandler(`${this.name}:getNetworkConfigurationByChainId`, this.getNetworkConfigurationByChainId.bind(this));
|
|
437
|
+
this.messenger.registerActionHandler(`${this.name}:getNetworkConfigurationByNetworkClientId`, this.getNetworkConfigurationByNetworkClientId.bind(this));
|
|
464
438
|
this.messenger.registerActionHandler(`${this.name}:getSelectedNetworkClient`, this.getSelectedNetworkClient.bind(this));
|
|
465
439
|
this.messenger.registerActionHandler(`${this.name}:getSelectedChainId`, this.getSelectedChainId.bind(this));
|
|
466
|
-
this.messenger.registerActionHandler(
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
`${this.name}:addNetwork`, this.addNetwork.bind(this));
|
|
470
|
-
this.messenger.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.messenger.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));
|
|
440
|
+
this.messenger.registerActionHandler(`${this.name}:addNetwork`, this.addNetwork.bind(this));
|
|
441
|
+
this.messenger.registerActionHandler(`${this.name}:removeNetwork`, this.removeNetwork.bind(this));
|
|
442
|
+
this.messenger.registerActionHandler(`${this.name}:updateNetwork`, this.updateNetwork.bind(this));
|
|
478
443
|
}
|
|
479
444
|
/**
|
|
480
445
|
* Enables the RPC failover functionality. That is, if any RPC endpoints are
|
|
@@ -494,6 +459,7 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
494
459
|
}
|
|
495
460
|
/**
|
|
496
461
|
* Accesses the provider and block tracker for the currently selected network.
|
|
462
|
+
*
|
|
497
463
|
* @returns The proxy and block tracker proxies.
|
|
498
464
|
* @deprecated This method has been replaced by `getSelectedNetworkClient` (which has a more easily used return type) and will be removed in a future release.
|
|
499
465
|
*/
|
|
@@ -549,19 +515,13 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
549
515
|
// This is impossible to reach
|
|
550
516
|
/* istanbul ignore if */
|
|
551
517
|
if (!infuraNetworkClient) {
|
|
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}".`);
|
|
518
|
+
throw new Error(`No Infura network client was found with the ID "${networkClientId}".`);
|
|
556
519
|
}
|
|
557
520
|
return infuraNetworkClient;
|
|
558
521
|
}
|
|
559
522
|
const customNetworkClient = autoManagedNetworkClientRegistry[types_1.NetworkClientType.Custom][networkClientId];
|
|
560
523
|
if (!customNetworkClient) {
|
|
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}".`);
|
|
524
|
+
throw new Error(`No custom network client was found with the ID "${networkClientId}".`);
|
|
565
525
|
}
|
|
566
526
|
return customNetworkClient;
|
|
567
527
|
}
|
|
@@ -620,10 +580,7 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
620
580
|
*/
|
|
621
581
|
async setProviderType(type) {
|
|
622
582
|
if (type === controller_utils_1.NetworkType.rpc) {
|
|
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"`);
|
|
583
|
+
throw new Error(`NetworkController - cannot call "setProviderType" with type "${controller_utils_1.NetworkType.rpc}". Use "setActiveNetwork"`);
|
|
627
584
|
}
|
|
628
585
|
if (!(0, controller_utils_1.isInfuraNetworkType)(type)) {
|
|
629
586
|
throw new Error(`Unknown Infura provider type "${String(type)}".`);
|
|
@@ -916,10 +873,7 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
916
873
|
networkClientOperation.oldRpcEndpoint.networkClientId ===
|
|
917
874
|
this.state.selectedNetworkClientId);
|
|
918
875
|
})) {
|
|
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.`);
|
|
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.`);
|
|
923
877
|
}
|
|
924
878
|
__classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_registerNetworkClientsAsNeeded).call(this, {
|
|
925
879
|
networkFields: fields,
|
|
@@ -1321,16 +1275,10 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1321
1275
|
const existingNetworkConfigurationViaChainId = this.state.networkConfigurationsByChainId[networkFields.chainId];
|
|
1322
1276
|
if (existingNetworkConfigurationViaChainId !== undefined) {
|
|
1323
1277
|
if (existingNetworkConfiguration === null) {
|
|
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}')`);
|
|
1278
|
+
throw new Error(`Could not add network for chain ${args.networkFields.chainId} as another network for that chain already exists ('${existingNetworkConfigurationViaChainId.name}')`);
|
|
1328
1279
|
}
|
|
1329
1280
|
else {
|
|
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}')`);
|
|
1281
|
+
throw new Error(`Cannot move network from chain ${existingNetworkConfiguration.chainId} to ${networkFields.chainId} as another network for that chain already exists ('${existingNetworkConfigurationViaChainId.name}')`);
|
|
1334
1282
|
}
|
|
1335
1283
|
}
|
|
1336
1284
|
}
|
|
@@ -1346,10 +1294,7 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1346
1294
|
}
|
|
1347
1295
|
for (const rpcEndpointFields of networkFields.rpcEndpoints) {
|
|
1348
1296
|
if (!isValidUrl(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}'`);
|
|
1297
|
+
throw new Error(`${errorMessagePrefix}: An entry in \`rpcEndpoints\` has invalid URL '${rpcEndpointFields.url}'`);
|
|
1353
1298
|
}
|
|
1354
1299
|
const networkClientId = 'networkClientId' in rpcEndpointFields
|
|
1355
1300
|
? rpcEndpointFields.networkClientId
|
|
@@ -1357,19 +1302,13 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1357
1302
|
if (rpcEndpointFields.type === RpcEndpointType.Custom &&
|
|
1358
1303
|
networkClientId !== undefined &&
|
|
1359
1304
|
(0, controller_utils_1.isInfuraNetworkType)(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}'`);
|
|
1305
|
+
throw new Error(`${errorMessagePrefix}: Custom RPC endpoint '${rpcEndpointFields.url}' has invalid network client ID '${networkClientId}'`);
|
|
1364
1306
|
}
|
|
1365
1307
|
if (mode === 'update' &&
|
|
1366
1308
|
networkClientId !== undefined &&
|
|
1367
1309
|
rpcEndpointFields.type === RpcEndpointType.Custom &&
|
|
1368
1310
|
!Object.values(autoManagedNetworkClientRegistry).some((networkClientsById) => networkClientId in networkClientsById)) {
|
|
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`);
|
|
1311
|
+
throw new Error(`${errorMessagePrefix}: RPC endpoint '${rpcEndpointFields.url}' refers to network client '${networkClientId}' that does not exist`);
|
|
1373
1312
|
}
|
|
1374
1313
|
if (networkFields.rpcEndpoints.some((otherRpcEndpointFields) => otherRpcEndpointFields !== rpcEndpointFields &&
|
|
1375
1314
|
URI.equal(otherRpcEndpointFields.url, rpcEndpointFields.url))) {
|
|
@@ -1383,16 +1322,10 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1383
1322
|
const rpcEndpoint = networkConfiguration.rpcEndpoints.find((existingRpcEndpoint) => URI.equal(rpcEndpointFields.url, existingRpcEndpoint.url));
|
|
1384
1323
|
if (rpcEndpoint) {
|
|
1385
1324
|
if (mode === 'update') {
|
|
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}')`);
|
|
1325
|
+
throw new Error(`Could not update network to point to same RPC endpoint as existing network for chain ${networkConfiguration.chainId} ('${networkConfiguration.name}')`);
|
|
1390
1326
|
}
|
|
1391
1327
|
else {
|
|
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}')`);
|
|
1328
|
+
throw new Error(`Could not add network that points to same RPC endpoint as existing network for chain ${networkConfiguration.chainId} ('${networkConfiguration.name}')`);
|
|
1396
1329
|
}
|
|
1397
1330
|
}
|
|
1398
1331
|
}
|
|
@@ -1420,12 +1353,8 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1420
1353
|
const infuraChainId = controller_utils_1.ChainId[infuraNetworkName];
|
|
1421
1354
|
if (networkFields.chainId !== infuraChainId) {
|
|
1422
1355
|
throw new Error(mode === 'add'
|
|
1423
|
-
?
|
|
1424
|
-
|
|
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`);
|
|
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`);
|
|
1429
1358
|
}
|
|
1430
1359
|
}
|
|
1431
1360
|
if (networkFields.rpcEndpoints[networkFields.defaultRpcEndpointIndex] ===
|
|
@@ -1616,13 +1545,15 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1616
1545
|
__classPrivateFieldGet(this, _NetworkController_providerProxy, "f").setTarget(__classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClient, "f").provider);
|
|
1617
1546
|
}
|
|
1618
1547
|
else {
|
|
1619
|
-
__classPrivateFieldSet(this, _NetworkController_providerProxy, (0, swappable_obj_proxy_1.
|
|
1548
|
+
__classPrivateFieldSet(this, _NetworkController_providerProxy, (0, swappable_obj_proxy_1.createSwappableProxy)(__classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClient, "f").provider), "f");
|
|
1620
1549
|
}
|
|
1621
1550
|
if (__classPrivateFieldGet(this, _NetworkController_blockTrackerProxy, "f")) {
|
|
1622
1551
|
__classPrivateFieldGet(this, _NetworkController_blockTrackerProxy, "f").setTarget(__classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClient, "f").blockTracker);
|
|
1623
1552
|
}
|
|
1624
1553
|
else {
|
|
1625
|
-
__classPrivateFieldSet(this, _NetworkController_blockTrackerProxy, (0, swappable_obj_proxy_1.createEventEmitterProxy)(__classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClient, "f").blockTracker, {
|
|
1554
|
+
__classPrivateFieldSet(this, _NetworkController_blockTrackerProxy, (0, swappable_obj_proxy_1.createEventEmitterProxy)(__classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClient, "f").blockTracker, {
|
|
1555
|
+
eventFilter: 'skipInternal',
|
|
1556
|
+
}), "f");
|
|
1626
1557
|
}
|
|
1627
1558
|
__classPrivateFieldSet(this, _NetworkController_ethQuery, new eth_query_1.default(__classPrivateFieldGet(this, _NetworkController_providerProxy, "f")), "f");
|
|
1628
1559
|
};
|