@metamask/network-controller 25.0.0 → 27.0.0
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 +64 -1
- package/dist/NetworkController.cjs +83 -114
- package/dist/NetworkController.cjs.map +1 -1
- package/dist/NetworkController.d.cts +136 -27
- package/dist/NetworkController.d.cts.map +1 -1
- package/dist/NetworkController.d.mts +136 -27
- package/dist/NetworkController.d.mts.map +1 -1
- package/dist/NetworkController.mjs +84 -115
- package/dist/NetworkController.mjs.map +1 -1
- package/dist/constants.cjs +18 -10
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +18 -10
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +18 -10
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +18 -10
- package/dist/constants.mjs.map +1 -1
- package/dist/create-auto-managed-network-client.cjs +4 -3
- package/dist/create-auto-managed-network-client.cjs.map +1 -1
- package/dist/create-auto-managed-network-client.d.cts +5 -2
- package/dist/create-auto-managed-network-client.d.cts.map +1 -1
- package/dist/create-auto-managed-network-client.d.mts +5 -2
- package/dist/create-auto-managed-network-client.d.mts.map +1 -1
- package/dist/create-auto-managed-network-client.mjs +4 -3
- package/dist/create-auto-managed-network-client.mjs.map +1 -1
- package/dist/create-network-client.cjs +177 -78
- package/dist/create-network-client.cjs.map +1 -1
- package/dist/create-network-client.d.cts +5 -2
- package/dist/create-network-client.d.cts.map +1 -1
- package/dist/create-network-client.d.mts +5 -2
- package/dist/create-network-client.d.mts.map +1 -1
- package/dist/create-network-client.mjs +178 -79
- package/dist/create-network-client.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/rpc-service/rpc-service-chain.cjs +247 -39
- package/dist/rpc-service/rpc-service-chain.cjs.map +1 -1
- package/dist/rpc-service/rpc-service-chain.d.cts +108 -27
- package/dist/rpc-service/rpc-service-chain.d.cts.map +1 -1
- package/dist/rpc-service/rpc-service-chain.d.mts +108 -27
- package/dist/rpc-service/rpc-service-chain.d.mts.map +1 -1
- package/dist/rpc-service/rpc-service-chain.mjs +247 -39
- package/dist/rpc-service/rpc-service-chain.mjs.map +1 -1
- package/dist/rpc-service/rpc-service-requestable.cjs.map +1 -1
- package/dist/rpc-service/rpc-service-requestable.d.cts +16 -6
- package/dist/rpc-service/rpc-service-requestable.d.cts.map +1 -1
- package/dist/rpc-service/rpc-service-requestable.d.mts +16 -6
- package/dist/rpc-service/rpc-service-requestable.d.mts.map +1 -1
- package/dist/rpc-service/rpc-service-requestable.mjs.map +1 -1
- package/dist/rpc-service/rpc-service.cjs +68 -34
- package/dist/rpc-service/rpc-service.cjs.map +1 -1
- package/dist/rpc-service/rpc-service.d.cts +33 -24
- package/dist/rpc-service/rpc-service.d.cts.map +1 -1
- package/dist/rpc-service/rpc-service.d.mts +33 -24
- package/dist/rpc-service/rpc-service.d.mts.map +1 -1
- package/dist/rpc-service/rpc-service.mjs +69 -35
- package/dist/rpc-service/rpc-service.mjs.map +1 -1
- package/dist/rpc-service/shared.cjs.map +1 -1
- package/dist/rpc-service/shared.d.cts +25 -3
- package/dist/rpc-service/shared.d.cts.map +1 -1
- package/dist/rpc-service/shared.d.mts +25 -3
- package/dist/rpc-service/shared.d.mts.map +1 -1
- package/dist/rpc-service/shared.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +6 -2
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +6 -2
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +13 -11
|
@@ -21,7 +21,7 @@ import { InfuraNetworkType, CustomNetworkType, NetworkType, isSafeChainId, isInf
|
|
|
21
21
|
import $EthQuery from "@metamask/eth-query";
|
|
22
22
|
const EthQuery = $importDefault($EthQuery);
|
|
23
23
|
import { errorCodes } from "@metamask/rpc-errors";
|
|
24
|
-
import { createEventEmitterProxy } from "@metamask/swappable-obj-proxy";
|
|
24
|
+
import { createEventEmitterProxy, createSwappableProxy } from "@metamask/swappable-obj-proxy";
|
|
25
25
|
import { hasProperty, isPlainObject, isStrictHexString } from "@metamask/utils";
|
|
26
26
|
import $deepEqual from "fast-deep-equal";
|
|
27
27
|
const deepEqual = $importDefault($deepEqual);
|
|
@@ -61,8 +61,6 @@ export var RpcEndpointType;
|
|
|
61
61
|
* @returns The keys of an object, typed according to the type of the object
|
|
62
62
|
* itself.
|
|
63
63
|
*/
|
|
64
|
-
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
65
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
66
64
|
export function knownKeysOf(
|
|
67
65
|
// TODO: Replace `any` with type
|
|
68
66
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -113,10 +111,7 @@ function getDefaultInfuraNetworkConfigurationsByChainId() {
|
|
|
113
111
|
if (DEPRECATED_NETWORKS.has(chainId)) {
|
|
114
112
|
return obj;
|
|
115
113
|
}
|
|
116
|
-
const rpcEndpointUrl =
|
|
117
|
-
// This ESLint rule mistakenly produces an error.
|
|
118
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
119
|
-
`https://${infuraNetworkType}.infura.io/v3/{infuraProjectId}`;
|
|
114
|
+
const rpcEndpointUrl = `https://${infuraNetworkType}.infura.io/v3/{infuraProjectId}`;
|
|
120
115
|
const networkConfiguration = {
|
|
121
116
|
blockExplorerUrls: [],
|
|
122
117
|
chainId,
|
|
@@ -313,14 +308,21 @@ function validateInitialState(state) {
|
|
|
313
308
|
*/
|
|
314
309
|
function correctInitialState(state, messenger) {
|
|
315
310
|
const networkConfigurationsSortedByChainId = getNetworkConfigurations(state).sort((a, b) => a.chainId.localeCompare(b.chainId));
|
|
316
|
-
const
|
|
311
|
+
const availableNetworkClientIds = getAvailableNetworkClientIds(networkConfigurationsSortedByChainId);
|
|
312
|
+
const invalidNetworkClientIdsWithMetadata = Object.keys(state.networksMetadata).filter((networkClientId) => !availableNetworkClientIds.includes(networkClientId));
|
|
317
313
|
return produce(state, (newState) => {
|
|
318
|
-
if (!
|
|
314
|
+
if (!availableNetworkClientIds.includes(state.selectedNetworkClientId)) {
|
|
319
315
|
const firstNetworkConfiguration = networkConfigurationsSortedByChainId[0];
|
|
320
316
|
const newSelectedNetworkClientId = firstNetworkConfiguration.rpcEndpoints[firstNetworkConfiguration.defaultRpcEndpointIndex].networkClientId;
|
|
321
317
|
messenger.call('ErrorReportingService:captureException', new Error(`\`selectedNetworkClientId\` '${state.selectedNetworkClientId}' does not refer to an RPC endpoint within a network configuration; correcting to '${newSelectedNetworkClientId}'`));
|
|
322
318
|
newState.selectedNetworkClientId = newSelectedNetworkClientId;
|
|
323
319
|
}
|
|
320
|
+
if (invalidNetworkClientIdsWithMetadata.length > 0) {
|
|
321
|
+
for (const invalidNetworkClientId of invalidNetworkClientIdsWithMetadata) {
|
|
322
|
+
delete newState.networksMetadata[invalidNetworkClientId];
|
|
323
|
+
}
|
|
324
|
+
messenger.call('ErrorReportingService:captureException', new Error('`networksMetadata` had invalid network client IDs, which have been removed'));
|
|
325
|
+
}
|
|
324
326
|
});
|
|
325
327
|
}
|
|
326
328
|
/**
|
|
@@ -403,54 +405,36 @@ export class NetworkController extends BaseController {
|
|
|
403
405
|
__classPrivateFieldSet(this, _NetworkController_isRpcFailoverEnabled, isRpcFailoverEnabled, "f");
|
|
404
406
|
__classPrivateFieldSet(this, _NetworkController_previouslySelectedNetworkClientId, this.state.selectedNetworkClientId, "f");
|
|
405
407
|
__classPrivateFieldSet(this, _NetworkController_networkConfigurationsByNetworkClientId, buildNetworkConfigurationsByNetworkClientId(this.state.networkConfigurationsByChainId), "f");
|
|
406
|
-
this.messenger.registerActionHandler(
|
|
407
|
-
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
408
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
409
|
-
`${this.name}:getEthQuery`, () => {
|
|
408
|
+
this.messenger.registerActionHandler(`${this.name}:getEthQuery`, () => {
|
|
410
409
|
return __classPrivateFieldGet(this, _NetworkController_ethQuery, "f");
|
|
411
410
|
});
|
|
412
|
-
this.messenger.registerActionHandler(
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
`${this.name}:
|
|
416
|
-
this.messenger.registerActionHandler(
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
`${this.name}:getEIP1559Compatibility`, this.getEIP1559Compatibility.bind(this));
|
|
420
|
-
this.messenger.registerActionHandler(
|
|
421
|
-
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
422
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
423
|
-
`${this.name}:setActiveNetwork`, this.setActiveNetwork.bind(this));
|
|
424
|
-
this.messenger.registerActionHandler(
|
|
425
|
-
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
426
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
427
|
-
`${this.name}:setProviderType`, this.setProviderType.bind(this));
|
|
428
|
-
this.messenger.registerActionHandler(
|
|
429
|
-
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
430
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
431
|
-
`${this.name}:findNetworkClientIdByChainId`, this.findNetworkClientIdByChainId.bind(this));
|
|
432
|
-
this.messenger.registerActionHandler(
|
|
433
|
-
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
434
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
435
|
-
`${this.name}:getNetworkConfigurationByChainId`, this.getNetworkConfigurationByChainId.bind(this));
|
|
436
|
-
this.messenger.registerActionHandler(
|
|
437
|
-
// ESLint is mistaken here; `name` is a string.
|
|
438
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
439
|
-
`${this.name}:getNetworkConfigurationByNetworkClientId`, this.getNetworkConfigurationByNetworkClientId.bind(this));
|
|
411
|
+
this.messenger.registerActionHandler(`${this.name}:getNetworkClientById`, this.getNetworkClientById.bind(this));
|
|
412
|
+
this.messenger.registerActionHandler(`${this.name}:getEIP1559Compatibility`, this.getEIP1559Compatibility.bind(this));
|
|
413
|
+
this.messenger.registerActionHandler(`${this.name}:setActiveNetwork`, this.setActiveNetwork.bind(this));
|
|
414
|
+
this.messenger.registerActionHandler(`${this.name}:setProviderType`, this.setProviderType.bind(this));
|
|
415
|
+
this.messenger.registerActionHandler(`${this.name}:findNetworkClientIdByChainId`, this.findNetworkClientIdByChainId.bind(this));
|
|
416
|
+
this.messenger.registerActionHandler(`${this.name}:getNetworkConfigurationByChainId`, this.getNetworkConfigurationByChainId.bind(this));
|
|
417
|
+
this.messenger.registerActionHandler(`${this.name}:getNetworkConfigurationByNetworkClientId`, this.getNetworkConfigurationByNetworkClientId.bind(this));
|
|
440
418
|
this.messenger.registerActionHandler(`${this.name}:getSelectedNetworkClient`, this.getSelectedNetworkClient.bind(this));
|
|
441
419
|
this.messenger.registerActionHandler(`${this.name}:getSelectedChainId`, this.getSelectedChainId.bind(this));
|
|
442
|
-
this.messenger.registerActionHandler(
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
`${this.name}:
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
this.messenger.
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
420
|
+
this.messenger.registerActionHandler(`${this.name}:addNetwork`, this.addNetwork.bind(this));
|
|
421
|
+
this.messenger.registerActionHandler(`${this.name}:removeNetwork`, this.removeNetwork.bind(this));
|
|
422
|
+
this.messenger.registerActionHandler(`${this.name}:updateNetwork`, this.updateNetwork.bind(this));
|
|
423
|
+
this.messenger.subscribe(`${this.name}:rpcEndpointChainUnavailable`, ({ networkClientId }) => {
|
|
424
|
+
__classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_updateMetadataForNetwork).call(this, networkClientId, {
|
|
425
|
+
networkStatus: NetworkStatus.Unavailable,
|
|
426
|
+
});
|
|
427
|
+
});
|
|
428
|
+
this.messenger.subscribe(`${this.name}:rpcEndpointChainDegraded`, ({ networkClientId }) => {
|
|
429
|
+
__classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_updateMetadataForNetwork).call(this, networkClientId, {
|
|
430
|
+
networkStatus: NetworkStatus.Degraded,
|
|
431
|
+
});
|
|
432
|
+
});
|
|
433
|
+
this.messenger.subscribe(`${this.name}:rpcEndpointChainAvailable`, ({ networkClientId }) => {
|
|
434
|
+
__classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_updateMetadataForNetwork).call(this, networkClientId, {
|
|
435
|
+
networkStatus: NetworkStatus.Available,
|
|
436
|
+
});
|
|
437
|
+
});
|
|
454
438
|
}
|
|
455
439
|
/**
|
|
456
440
|
* Enables the RPC failover functionality. That is, if any RPC endpoints are
|
|
@@ -470,6 +454,7 @@ export class NetworkController extends BaseController {
|
|
|
470
454
|
}
|
|
471
455
|
/**
|
|
472
456
|
* Accesses the provider and block tracker for the currently selected network.
|
|
457
|
+
*
|
|
473
458
|
* @returns The proxy and block tracker proxies.
|
|
474
459
|
* @deprecated This method has been replaced by `getSelectedNetworkClient` (which has a more easily used return type) and will be removed in a future release.
|
|
475
460
|
*/
|
|
@@ -525,19 +510,13 @@ export class NetworkController extends BaseController {
|
|
|
525
510
|
// This is impossible to reach
|
|
526
511
|
/* istanbul ignore if */
|
|
527
512
|
if (!infuraNetworkClient) {
|
|
528
|
-
throw new Error(
|
|
529
|
-
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
530
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
531
|
-
`No Infura network client was found with the ID "${networkClientId}".`);
|
|
513
|
+
throw new Error(`No Infura network client was found with the ID "${networkClientId}".`);
|
|
532
514
|
}
|
|
533
515
|
return infuraNetworkClient;
|
|
534
516
|
}
|
|
535
517
|
const customNetworkClient = autoManagedNetworkClientRegistry[NetworkClientType.Custom][networkClientId];
|
|
536
518
|
if (!customNetworkClient) {
|
|
537
|
-
throw new Error(
|
|
538
|
-
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
539
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
540
|
-
`No custom network client was found with the ID "${networkClientId}".`);
|
|
519
|
+
throw new Error(`No custom network client was found with the ID "${networkClientId}".`);
|
|
541
520
|
}
|
|
542
521
|
return customNetworkClient;
|
|
543
522
|
}
|
|
@@ -596,10 +575,7 @@ export class NetworkController extends BaseController {
|
|
|
596
575
|
*/
|
|
597
576
|
async setProviderType(type) {
|
|
598
577
|
if (type === NetworkType.rpc) {
|
|
599
|
-
throw new Error(
|
|
600
|
-
// This ESLint rule mistakenly produces an error.
|
|
601
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
602
|
-
`NetworkController - cannot call "setProviderType" with type "${NetworkType.rpc}". Use "setActiveNetwork"`);
|
|
578
|
+
throw new Error(`NetworkController - cannot call "setProviderType" with type "${NetworkType.rpc}". Use "setActiveNetwork"`);
|
|
603
579
|
}
|
|
604
580
|
if (!isInfuraNetworkType(type)) {
|
|
605
581
|
throw new Error(`Unknown Infura provider type "${String(type)}".`);
|
|
@@ -892,10 +868,7 @@ export class NetworkController extends BaseController {
|
|
|
892
868
|
networkClientOperation.oldRpcEndpoint.networkClientId ===
|
|
893
869
|
this.state.selectedNetworkClientId);
|
|
894
870
|
})) {
|
|
895
|
-
throw new Error(
|
|
896
|
-
// This ESLint rule mistakenly produces an error.
|
|
897
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
898
|
-
`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.`);
|
|
871
|
+
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.`);
|
|
899
872
|
}
|
|
900
873
|
__classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_registerNetworkClientsAsNeeded).call(this, {
|
|
901
874
|
networkFields: fields,
|
|
@@ -984,6 +957,9 @@ export class NetworkController extends BaseController {
|
|
|
984
957
|
mode: 'remove',
|
|
985
958
|
existingNetworkConfiguration,
|
|
986
959
|
});
|
|
960
|
+
for (const rpcEndpoint of existingNetworkConfiguration.rpcEndpoints) {
|
|
961
|
+
delete state.networksMetadata[rpcEndpoint.networkClientId];
|
|
962
|
+
}
|
|
987
963
|
});
|
|
988
964
|
this.messenger.publish('NetworkController:networkRemoved', existingNetworkConfiguration);
|
|
989
965
|
}
|
|
@@ -1002,6 +978,8 @@ export class NetworkController extends BaseController {
|
|
|
1002
978
|
*
|
|
1003
979
|
* In-progress requests will not be aborted.
|
|
1004
980
|
*/
|
|
981
|
+
// We're intentionally changing the signature of an extended method.
|
|
982
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
1005
983
|
async destroy() {
|
|
1006
984
|
await __classPrivateFieldGet(this, _NetworkController_blockTrackerProxy, "f")?.destroy();
|
|
1007
985
|
}
|
|
@@ -1156,7 +1134,10 @@ async function _NetworkController_determineNetworkMetadata(networkClientId) {
|
|
|
1156
1134
|
*/
|
|
1157
1135
|
async function _NetworkController_lookupGivenNetwork(networkClientId) {
|
|
1158
1136
|
const { networkStatus, isEIP1559Compatible } = await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_determineNetworkMetadata).call(this, networkClientId);
|
|
1159
|
-
__classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_updateMetadataForNetwork).call(this, networkClientId,
|
|
1137
|
+
__classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_updateMetadataForNetwork).call(this, networkClientId, {
|
|
1138
|
+
networkStatus,
|
|
1139
|
+
isEIP1559Compatible,
|
|
1140
|
+
});
|
|
1160
1141
|
}, _NetworkController_lookupSelectedNetwork =
|
|
1161
1142
|
/**
|
|
1162
1143
|
* Uses a request for the latest block to gather the following information on
|
|
@@ -1216,7 +1197,10 @@ async function _NetworkController_lookupSelectedNetwork() {
|
|
|
1216
1197
|
throw error;
|
|
1217
1198
|
}
|
|
1218
1199
|
}
|
|
1219
|
-
__classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_updateMetadataForNetwork).call(this, this.state.selectedNetworkClientId,
|
|
1200
|
+
__classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_updateMetadataForNetwork).call(this, this.state.selectedNetworkClientId, {
|
|
1201
|
+
networkStatus,
|
|
1202
|
+
isEIP1559Compatible,
|
|
1203
|
+
});
|
|
1220
1204
|
if (isInfura) {
|
|
1221
1205
|
if (networkStatus === NetworkStatus.Available) {
|
|
1222
1206
|
this.messenger.publish('NetworkController:infuraIsUnblocked');
|
|
@@ -1231,7 +1215,7 @@ async function _NetworkController_lookupSelectedNetwork() {
|
|
|
1231
1215
|
// previously connected to an Infura network that was blocked
|
|
1232
1216
|
this.messenger.publish('NetworkController:infuraIsUnblocked');
|
|
1233
1217
|
}
|
|
1234
|
-
}, _NetworkController_updateMetadataForNetwork = function _NetworkController_updateMetadataForNetwork(networkClientId,
|
|
1218
|
+
}, _NetworkController_updateMetadataForNetwork = function _NetworkController_updateMetadataForNetwork(networkClientId, metadata) {
|
|
1235
1219
|
this.update((state) => {
|
|
1236
1220
|
if (state.networksMetadata[networkClientId] === undefined) {
|
|
1237
1221
|
state.networksMetadata[networkClientId] = {
|
|
@@ -1239,13 +1223,15 @@ async function _NetworkController_lookupSelectedNetwork() {
|
|
|
1239
1223
|
EIPS: {},
|
|
1240
1224
|
};
|
|
1241
1225
|
}
|
|
1242
|
-
const
|
|
1243
|
-
|
|
1244
|
-
if (isEIP1559Compatible
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1226
|
+
const newMetadata = state.networksMetadata[networkClientId];
|
|
1227
|
+
newMetadata.status = metadata.networkStatus;
|
|
1228
|
+
if ('isEIP1559Compatible' in metadata) {
|
|
1229
|
+
if (metadata.isEIP1559Compatible === undefined) {
|
|
1230
|
+
delete newMetadata.EIPS[1559];
|
|
1231
|
+
}
|
|
1232
|
+
else {
|
|
1233
|
+
newMetadata.EIPS[1559] = metadata.isEIP1559Compatible;
|
|
1234
|
+
}
|
|
1249
1235
|
}
|
|
1250
1236
|
});
|
|
1251
1237
|
}, _NetworkController_getLatestBlock = function _NetworkController_getLatestBlock(networkClientId) {
|
|
@@ -1257,6 +1243,8 @@ async function _NetworkController_lookupSelectedNetwork() {
|
|
|
1257
1243
|
return new Promise((resolve, reject) => {
|
|
1258
1244
|
ethQuery.sendAsync({ method: 'eth_getBlockByNumber', params: ['latest', false] }, (error, block) => {
|
|
1259
1245
|
if (error) {
|
|
1246
|
+
// This error comes from JsonRpcEngine, we don't control it.
|
|
1247
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
1260
1248
|
reject(error);
|
|
1261
1249
|
}
|
|
1262
1250
|
else {
|
|
@@ -1296,16 +1284,10 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1296
1284
|
const existingNetworkConfigurationViaChainId = this.state.networkConfigurationsByChainId[networkFields.chainId];
|
|
1297
1285
|
if (existingNetworkConfigurationViaChainId !== undefined) {
|
|
1298
1286
|
if (existingNetworkConfiguration === null) {
|
|
1299
|
-
throw new Error(
|
|
1300
|
-
// This ESLint rule mistakenly produces an error.
|
|
1301
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
1302
|
-
`Could not add network for chain ${args.networkFields.chainId} as another network for that chain already exists ('${existingNetworkConfigurationViaChainId.name}')`);
|
|
1287
|
+
throw new Error(`Could not add network for chain ${args.networkFields.chainId} as another network for that chain already exists ('${existingNetworkConfigurationViaChainId.name}')`);
|
|
1303
1288
|
}
|
|
1304
1289
|
else {
|
|
1305
|
-
throw new Error(
|
|
1306
|
-
// This ESLint rule mistakenly produces an error.
|
|
1307
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
1308
|
-
`Cannot move network from chain ${existingNetworkConfiguration.chainId} to ${networkFields.chainId} as another network for that chain already exists ('${existingNetworkConfigurationViaChainId.name}')`);
|
|
1290
|
+
throw new Error(`Cannot move network from chain ${existingNetworkConfiguration.chainId} to ${networkFields.chainId} as another network for that chain already exists ('${existingNetworkConfigurationViaChainId.name}')`);
|
|
1309
1291
|
}
|
|
1310
1292
|
}
|
|
1311
1293
|
}
|
|
@@ -1321,10 +1303,7 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1321
1303
|
}
|
|
1322
1304
|
for (const rpcEndpointFields of networkFields.rpcEndpoints) {
|
|
1323
1305
|
if (!isValidUrl(rpcEndpointFields.url)) {
|
|
1324
|
-
throw new Error(
|
|
1325
|
-
// This ESLint rule mistakenly produces an error.
|
|
1326
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
1327
|
-
`${errorMessagePrefix}: An entry in \`rpcEndpoints\` has invalid URL '${rpcEndpointFields.url}'`);
|
|
1306
|
+
throw new Error(`${errorMessagePrefix}: An entry in \`rpcEndpoints\` has invalid URL '${rpcEndpointFields.url}'`);
|
|
1328
1307
|
}
|
|
1329
1308
|
const networkClientId = 'networkClientId' in rpcEndpointFields
|
|
1330
1309
|
? rpcEndpointFields.networkClientId
|
|
@@ -1332,19 +1311,13 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1332
1311
|
if (rpcEndpointFields.type === RpcEndpointType.Custom &&
|
|
1333
1312
|
networkClientId !== undefined &&
|
|
1334
1313
|
isInfuraNetworkType(networkClientId)) {
|
|
1335
|
-
throw new Error(
|
|
1336
|
-
// This is a string.
|
|
1337
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
1338
|
-
`${errorMessagePrefix}: Custom RPC endpoint '${rpcEndpointFields.url}' has invalid network client ID '${networkClientId}'`);
|
|
1314
|
+
throw new Error(`${errorMessagePrefix}: Custom RPC endpoint '${rpcEndpointFields.url}' has invalid network client ID '${networkClientId}'`);
|
|
1339
1315
|
}
|
|
1340
1316
|
if (mode === 'update' &&
|
|
1341
1317
|
networkClientId !== undefined &&
|
|
1342
1318
|
rpcEndpointFields.type === RpcEndpointType.Custom &&
|
|
1343
1319
|
!Object.values(autoManagedNetworkClientRegistry).some((networkClientsById) => networkClientId in networkClientsById)) {
|
|
1344
|
-
throw new Error(
|
|
1345
|
-
// This is a string.
|
|
1346
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
1347
|
-
`${errorMessagePrefix}: RPC endpoint '${rpcEndpointFields.url}' refers to network client '${networkClientId}' that does not exist`);
|
|
1320
|
+
throw new Error(`${errorMessagePrefix}: RPC endpoint '${rpcEndpointFields.url}' refers to network client '${networkClientId}' that does not exist`);
|
|
1348
1321
|
}
|
|
1349
1322
|
if (networkFields.rpcEndpoints.some((otherRpcEndpointFields) => otherRpcEndpointFields !== rpcEndpointFields &&
|
|
1350
1323
|
URI.equal(otherRpcEndpointFields.url, rpcEndpointFields.url))) {
|
|
@@ -1358,16 +1331,10 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1358
1331
|
const rpcEndpoint = networkConfiguration.rpcEndpoints.find((existingRpcEndpoint) => URI.equal(rpcEndpointFields.url, existingRpcEndpoint.url));
|
|
1359
1332
|
if (rpcEndpoint) {
|
|
1360
1333
|
if (mode === 'update') {
|
|
1361
|
-
throw new Error(
|
|
1362
|
-
// This ESLint rule mistakenly produces an error.
|
|
1363
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
1364
|
-
`Could not update network to point to same RPC endpoint as existing network for chain ${networkConfiguration.chainId} ('${networkConfiguration.name}')`);
|
|
1334
|
+
throw new Error(`Could not update network to point to same RPC endpoint as existing network for chain ${networkConfiguration.chainId} ('${networkConfiguration.name}')`);
|
|
1365
1335
|
}
|
|
1366
1336
|
else {
|
|
1367
|
-
throw new Error(
|
|
1368
|
-
// This ESLint rule mistakenly produces an error.
|
|
1369
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
1370
|
-
`Could not add network that points to same RPC endpoint as existing network for chain ${networkConfiguration.chainId} ('${networkConfiguration.name}')`);
|
|
1337
|
+
throw new Error(`Could not add network that points to same RPC endpoint as existing network for chain ${networkConfiguration.chainId} ('${networkConfiguration.name}')`);
|
|
1371
1338
|
}
|
|
1372
1339
|
}
|
|
1373
1340
|
}
|
|
@@ -1395,12 +1362,8 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1395
1362
|
const infuraChainId = ChainId[infuraNetworkName];
|
|
1396
1363
|
if (networkFields.chainId !== infuraChainId) {
|
|
1397
1364
|
throw new Error(mode === 'add'
|
|
1398
|
-
?
|
|
1399
|
-
|
|
1400
|
-
`Could not add network with chain ID ${networkFields.chainId} and Infura RPC endpoint for '${infuraNetworkNickname}' which represents ${infuraChainId}, as the two conflict`
|
|
1401
|
-
: // This is a string.
|
|
1402
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
1403
|
-
`Could not update network with chain ID ${networkFields.chainId} and Infura RPC endpoint for '${infuraNetworkNickname}' which represents ${infuraChainId}, as the two conflict`);
|
|
1365
|
+
? `Could not add network with chain ID ${networkFields.chainId} and Infura RPC endpoint for '${infuraNetworkNickname}' which represents ${infuraChainId}, as the two conflict`
|
|
1366
|
+
: `Could not update network with chain ID ${networkFields.chainId} and Infura RPC endpoint for '${infuraNetworkNickname}' which represents ${infuraChainId}, as the two conflict`);
|
|
1404
1367
|
}
|
|
1405
1368
|
}
|
|
1406
1369
|
if (networkFields.rpcEndpoints[networkFields.defaultRpcEndpointIndex] ===
|
|
@@ -1434,6 +1397,7 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1434
1397
|
for (const addedRpcEndpoint of addedRpcEndpoints) {
|
|
1435
1398
|
if (addedRpcEndpoint.type === RpcEndpointType.Infura) {
|
|
1436
1399
|
autoManagedNetworkClientRegistry[NetworkClientType.Infura][addedRpcEndpoint.networkClientId] = createAutoManagedNetworkClient({
|
|
1400
|
+
networkClientId: addedRpcEndpoint.networkClientId,
|
|
1437
1401
|
networkClientConfiguration: {
|
|
1438
1402
|
type: NetworkClientType.Infura,
|
|
1439
1403
|
chainId: networkFields.chainId,
|
|
@@ -1451,6 +1415,7 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1451
1415
|
}
|
|
1452
1416
|
else {
|
|
1453
1417
|
autoManagedNetworkClientRegistry[NetworkClientType.Custom][addedRpcEndpoint.networkClientId] = createAutoManagedNetworkClient({
|
|
1418
|
+
networkClientId: addedRpcEndpoint.networkClientId,
|
|
1454
1419
|
networkClientConfiguration: {
|
|
1455
1420
|
type: NetworkClientType.Custom,
|
|
1456
1421
|
chainId: networkFields.chainId,
|
|
@@ -1510,6 +1475,7 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1510
1475
|
return [
|
|
1511
1476
|
rpcEndpoint.networkClientId,
|
|
1512
1477
|
createAutoManagedNetworkClient({
|
|
1478
|
+
networkClientId: rpcEndpoint.networkClientId,
|
|
1513
1479
|
networkClientConfiguration: {
|
|
1514
1480
|
type: NetworkClientType.Infura,
|
|
1515
1481
|
network: infuraNetworkName,
|
|
@@ -1529,6 +1495,7 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1529
1495
|
return [
|
|
1530
1496
|
rpcEndpoint.networkClientId,
|
|
1531
1497
|
createAutoManagedNetworkClient({
|
|
1498
|
+
networkClientId: rpcEndpoint.networkClientId,
|
|
1532
1499
|
networkClientConfiguration: {
|
|
1533
1500
|
type: NetworkClientType.Custom,
|
|
1534
1501
|
chainId: networkConfiguration.chainId,
|
|
@@ -1591,13 +1558,15 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1591
1558
|
__classPrivateFieldGet(this, _NetworkController_providerProxy, "f").setTarget(__classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClient, "f").provider);
|
|
1592
1559
|
}
|
|
1593
1560
|
else {
|
|
1594
|
-
__classPrivateFieldSet(this, _NetworkController_providerProxy,
|
|
1561
|
+
__classPrivateFieldSet(this, _NetworkController_providerProxy, createSwappableProxy(__classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClient, "f").provider), "f");
|
|
1595
1562
|
}
|
|
1596
1563
|
if (__classPrivateFieldGet(this, _NetworkController_blockTrackerProxy, "f")) {
|
|
1597
1564
|
__classPrivateFieldGet(this, _NetworkController_blockTrackerProxy, "f").setTarget(__classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClient, "f").blockTracker);
|
|
1598
1565
|
}
|
|
1599
1566
|
else {
|
|
1600
|
-
__classPrivateFieldSet(this, _NetworkController_blockTrackerProxy, createEventEmitterProxy(__classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClient, "f").blockTracker, {
|
|
1567
|
+
__classPrivateFieldSet(this, _NetworkController_blockTrackerProxy, createEventEmitterProxy(__classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClient, "f").blockTracker, {
|
|
1568
|
+
eventFilter: 'skipInternal',
|
|
1569
|
+
}), "f");
|
|
1601
1570
|
}
|
|
1602
1571
|
__classPrivateFieldSet(this, _NetworkController_ethQuery, new EthQuery(__classPrivateFieldGet(this, _NetworkController_providerProxy, "f")), "f");
|
|
1603
1572
|
};
|