@metamask-previews/network-controller 22.0.1-preview-c10c8117 → 22.0.1-preview-de5d2fda
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/dist/NetworkController.cjs +1 -90
- package/dist/NetworkController.cjs.map +1 -1
- package/dist/NetworkController.d.cts +3 -52
- package/dist/NetworkController.d.cts.map +1 -1
- package/dist/NetworkController.d.mts +3 -52
- package/dist/NetworkController.d.mts.map +1 -1
- package/dist/NetworkController.mjs +1 -90
- package/dist/NetworkController.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/package.json +1 -1
- package/dist/last-updated-at-network-configuration.cjs +0 -17
- package/dist/last-updated-at-network-configuration.cjs.map +0 -1
- package/dist/last-updated-at-network-configuration.d.cts +0 -11
- package/dist/last-updated-at-network-configuration.d.cts.map +0 -1
- package/dist/last-updated-at-network-configuration.d.mts +0 -11
- package/dist/last-updated-at-network-configuration.d.mts.map +0 -1
- package/dist/last-updated-at-network-configuration.mjs +0 -13
- package/dist/last-updated-at-network-configuration.mjs.map +0 -1
|
@@ -52,7 +52,6 @@ const util_1 = require("util");
|
|
|
52
52
|
const uuid_1 = require("uuid");
|
|
53
53
|
const constants_1 = require("./constants.cjs");
|
|
54
54
|
const create_auto_managed_network_client_1 = require("./create-auto-managed-network-client.cjs");
|
|
55
|
-
const last_updated_at_network_configuration_1 = require("./last-updated-at-network-configuration.cjs");
|
|
56
55
|
const logger_1 = require("./logger.cjs");
|
|
57
56
|
const types_1 = require("./types.cjs");
|
|
58
57
|
const debugLog = (0, logger_1.createModuleLogger)(logger_1.projectLogger, 'NetworkController');
|
|
@@ -337,19 +336,6 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
337
336
|
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
338
337
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
339
338
|
`${this.name}:getSelectedNetworkClient`, this.getSelectedNetworkClient.bind(this));
|
|
340
|
-
this.messagingSystem.registerActionHandler(
|
|
341
|
-
// ESLint is mistaken here; `name` is a string.
|
|
342
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
343
|
-
`${this.name}:addNetwork`, this.addNetwork.bind(this));
|
|
344
|
-
this.messagingSystem.registerActionHandler(
|
|
345
|
-
// ESLint is mistaken here; `name` is a string.
|
|
346
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
347
|
-
`${this.name}:updateNetwork`, this.updateNetwork.bind(this));
|
|
348
|
-
this.messagingSystem.registerActionHandler(
|
|
349
|
-
// ESLint is mistaken here; `name` is a string.
|
|
350
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
351
|
-
`${this.name}:removeNetwork`, this.removeNetwork.bind(this));
|
|
352
|
-
this.messagingSystem.registerActionHandler(`${this.name}:dangerouslySetNetworkConfiguration`, this.dangerouslySetNetworkConfiguration.bind(this));
|
|
353
339
|
}
|
|
354
340
|
/**
|
|
355
341
|
* Accesses the provider and block tracker for the currently selected network.
|
|
@@ -722,7 +708,7 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
722
708
|
const rpcEndpoint = defaultOrCustomRpcEndpointFields.type === RpcEndpointType.Custom
|
|
723
709
|
? {
|
|
724
710
|
...defaultOrCustomRpcEndpointFields,
|
|
725
|
-
networkClientId:
|
|
711
|
+
networkClientId: (0, uuid_1.v4)(),
|
|
726
712
|
}
|
|
727
713
|
: defaultOrCustomRpcEndpointFields;
|
|
728
714
|
return {
|
|
@@ -963,7 +949,6 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
963
949
|
networkClientOperations,
|
|
964
950
|
autoManagedNetworkClientRegistry,
|
|
965
951
|
});
|
|
966
|
-
this.messagingSystem.publish('NetworkController:networkUpdated', updatedNetworkConfiguration);
|
|
967
952
|
return updatedNetworkConfiguration;
|
|
968
953
|
}
|
|
969
954
|
/**
|
|
@@ -1002,79 +987,6 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
1002
987
|
});
|
|
1003
988
|
});
|
|
1004
989
|
__classPrivateFieldSet(this, _NetworkController_networkConfigurationsByNetworkClientId, buildNetworkConfigurationsByNetworkClientId(this.state.networkConfigurationsByChainId), "f");
|
|
1005
|
-
this.messagingSystem.publish('NetworkController:networkRemoved', existingNetworkConfiguration);
|
|
1006
|
-
}
|
|
1007
|
-
/**
|
|
1008
|
-
* This is used to override an existing network configuration.
|
|
1009
|
-
* This is only meant for internal use only and not to be exposed via the UI.
|
|
1010
|
-
* It is used as part of "Network Syncing", to sync networks, RPCs and block explorers cross devices.
|
|
1011
|
-
*
|
|
1012
|
-
* This will subsequently update the network client registry; state.networksMetadata, and state.selectedNetworkClientId
|
|
1013
|
-
* @param networkConfiguration - the network configuration to override
|
|
1014
|
-
*/
|
|
1015
|
-
async dangerouslySetNetworkConfiguration(networkConfiguration) {
|
|
1016
|
-
const prevNetworkConfig = networkConfiguration.chainId in this.state.networkConfigurationsByChainId
|
|
1017
|
-
? this.state.networkConfigurationsByChainId[networkConfiguration.chainId]
|
|
1018
|
-
: undefined;
|
|
1019
|
-
// Update Registry (remove old and add new)
|
|
1020
|
-
const autoManagedNetworkClientRegistry = __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_ensureAutoManagedNetworkClientRegistryPopulated).call(this);
|
|
1021
|
-
if (prevNetworkConfig) {
|
|
1022
|
-
const networkClientOperations = prevNetworkConfig.rpcEndpoints.map((rpcEndpoint) => {
|
|
1023
|
-
return {
|
|
1024
|
-
type: 'remove',
|
|
1025
|
-
rpcEndpoint,
|
|
1026
|
-
};
|
|
1027
|
-
});
|
|
1028
|
-
__classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_unregisterNetworkClientsAsNeeded).call(this, {
|
|
1029
|
-
networkClientOperations,
|
|
1030
|
-
autoManagedNetworkClientRegistry,
|
|
1031
|
-
});
|
|
1032
|
-
}
|
|
1033
|
-
const networkClientOperations = networkConfiguration.rpcEndpoints.map((rpcEndpoint) => {
|
|
1034
|
-
return {
|
|
1035
|
-
type: 'add',
|
|
1036
|
-
rpcEndpoint,
|
|
1037
|
-
};
|
|
1038
|
-
});
|
|
1039
|
-
__classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_registerNetworkClientsAsNeeded).call(this, {
|
|
1040
|
-
networkFields: networkConfiguration,
|
|
1041
|
-
networkClientOperations,
|
|
1042
|
-
autoManagedNetworkClientRegistry,
|
|
1043
|
-
});
|
|
1044
|
-
// update new `networkConfigurationsByChainId` (full replace)
|
|
1045
|
-
this.update((state) => {
|
|
1046
|
-
state.networkConfigurationsByChainId[networkConfiguration.chainId] =
|
|
1047
|
-
networkConfiguration;
|
|
1048
|
-
});
|
|
1049
|
-
__classPrivateFieldSet(this, _NetworkController_networkConfigurationsByNetworkClientId, buildNetworkConfigurationsByNetworkClientId(this.state.networkConfigurationsByChainId), "f");
|
|
1050
|
-
// update `networksMetadata` remove old
|
|
1051
|
-
if (prevNetworkConfig) {
|
|
1052
|
-
this.update((state) => {
|
|
1053
|
-
const newNetworksMetadata = {
|
|
1054
|
-
...state.networksMetadata,
|
|
1055
|
-
};
|
|
1056
|
-
prevNetworkConfig.rpcEndpoints.forEach((rpcEndpoint) => {
|
|
1057
|
-
delete newNetworksMetadata[rpcEndpoint.networkClientId];
|
|
1058
|
-
});
|
|
1059
|
-
});
|
|
1060
|
-
}
|
|
1061
|
-
// update `networksMetadata` update new
|
|
1062
|
-
for (const rpcEndpoint of networkConfiguration.rpcEndpoints) {
|
|
1063
|
-
await this.lookupNetwork(rpcEndpoint.networkClientId);
|
|
1064
|
-
}
|
|
1065
|
-
// update selectedNetworkId
|
|
1066
|
-
const selectedClientId = this.state.selectedNetworkClientId;
|
|
1067
|
-
const wasReplacedClientId = prevNetworkConfig?.rpcEndpoints.some((r) => r.networkClientId === selectedClientId);
|
|
1068
|
-
const isValidClientIdInNewNetworks = networkConfiguration.rpcEndpoints.some((r) => r.networkClientId === selectedClientId);
|
|
1069
|
-
if (wasReplacedClientId) {
|
|
1070
|
-
if (!isValidClientIdInNewNetworks) {
|
|
1071
|
-
// Update clientId to something that exists
|
|
1072
|
-
const newSelectedNetworkMetadata = networkConfiguration.rpcEndpoints.find((r) => r.networkClientId in this.state.networksMetadata)?.networkClientId;
|
|
1073
|
-
const anyClientId = Object.keys(this.state.networksMetadata)[0];
|
|
1074
|
-
const newlySelectedNetwork = newSelectedNetworkMetadata ?? anyClientId ?? selectedClientId;
|
|
1075
|
-
await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_refreshNetwork).call(this, newlySelectedNetwork);
|
|
1076
|
-
}
|
|
1077
|
-
}
|
|
1078
990
|
}
|
|
1079
991
|
/**
|
|
1080
992
|
* Assuming that the network has been previously switched, switches to this
|
|
@@ -1368,7 +1280,6 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1368
1280
|
delete state.networkConfigurationsByChainId[args.existingNetworkConfiguration.chainId];
|
|
1369
1281
|
}
|
|
1370
1282
|
if (mode === 'add' || mode === 'update') {
|
|
1371
|
-
(0, last_updated_at_network_configuration_1.lastUpdatedNetworkConfiguration)(args.networkConfigurationToPersist);
|
|
1372
1283
|
state.networkConfigurationsByChainId[args.networkFields.chainId] =
|
|
1373
1284
|
args.networkConfigurationToPersist;
|
|
1374
1285
|
}
|