@metamask-previews/network-controller 23.1.0-preview-9f91d514 → 23.1.0-preview-aa7690c1
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 +9 -64
- package/dist/NetworkController.cjs.map +1 -1
- package/dist/NetworkController.d.cts +3 -18
- package/dist/NetworkController.d.cts.map +1 -1
- package/dist/NetworkController.d.mts +3 -18
- package/dist/NetworkController.d.mts.map +1 -1
- package/dist/NetworkController.mjs +10 -65
- 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/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +1 -5
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +1 -5
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -106,27 +106,9 @@ const controllerName = 'NetworkController';
|
|
|
106
106
|
* Constructs a value for the state property `networkConfigurationsByChainId`
|
|
107
107
|
* which will be used if it has not been provided to the constructor.
|
|
108
108
|
*
|
|
109
|
-
* @param [additionalDefaultNetworks] - An array of Hex Chain IDs representing the additional networks to be included as default.
|
|
110
109
|
* @returns The default value for `networkConfigurationsByChainId`.
|
|
111
110
|
*/
|
|
112
|
-
function getDefaultNetworkConfigurationsByChainId(
|
|
113
|
-
const infuraNetworks = getDefaultInfuraNetworkConfigurationsByChainId();
|
|
114
|
-
const customNetworks = getDefaultCustomNetworkConfigurationsByChainId();
|
|
115
|
-
return additionalDefaultNetworks.reduce((obj, chainId) => {
|
|
116
|
-
if ((0, utils_1.hasProperty)(customNetworks, chainId)) {
|
|
117
|
-
obj[chainId] = customNetworks[chainId];
|
|
118
|
-
}
|
|
119
|
-
return obj;
|
|
120
|
-
},
|
|
121
|
-
// Always include the infura networks in the default networks
|
|
122
|
-
infuraNetworks);
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Constructs a `networkConfigurationsByChainId` object for all default Infura networks.
|
|
126
|
-
*
|
|
127
|
-
* @returns The `networkConfigurationsByChainId` object of all Infura networks.
|
|
128
|
-
*/
|
|
129
|
-
function getDefaultInfuraNetworkConfigurationsByChainId() {
|
|
111
|
+
function getDefaultNetworkConfigurationsByChainId() {
|
|
130
112
|
return Object.values(controller_utils_1.InfuraNetworkType).reduce((obj, infuraNetworkType) => {
|
|
131
113
|
const chainId = controller_utils_1.ChainId[infuraNetworkType];
|
|
132
114
|
const rpcEndpointUrl =
|
|
@@ -151,42 +133,15 @@ function getDefaultInfuraNetworkConfigurationsByChainId() {
|
|
|
151
133
|
return { ...obj, [chainId]: networkConfiguration };
|
|
152
134
|
}, {});
|
|
153
135
|
}
|
|
154
|
-
/**
|
|
155
|
-
* Constructs a `networkConfigurationsByChainId` object for all default custom networks.
|
|
156
|
-
*
|
|
157
|
-
* @returns The `networkConfigurationsByChainId` object of all custom networks.
|
|
158
|
-
*/
|
|
159
|
-
function getDefaultCustomNetworkConfigurationsByChainId() {
|
|
160
|
-
const { ticker, rpcPrefs } = controller_utils_1.BUILT_IN_NETWORKS[controller_utils_1.BuiltInNetworkName.MegaETHTestnet];
|
|
161
|
-
return {
|
|
162
|
-
[controller_utils_1.ChainId[controller_utils_1.BuiltInNetworkName.MegaETHTestnet]]: {
|
|
163
|
-
blockExplorerUrls: [rpcPrefs.blockExplorerUrl],
|
|
164
|
-
chainId: controller_utils_1.ChainId[controller_utils_1.BuiltInNetworkName.MegaETHTestnet],
|
|
165
|
-
defaultRpcEndpointIndex: 0,
|
|
166
|
-
defaultBlockExplorerUrlIndex: 0,
|
|
167
|
-
name: controller_utils_1.NetworkNickname[controller_utils_1.BuiltInNetworkName.MegaETHTestnet],
|
|
168
|
-
nativeCurrency: ticker,
|
|
169
|
-
rpcEndpoints: [
|
|
170
|
-
{
|
|
171
|
-
failoverUrls: [],
|
|
172
|
-
networkClientId: controller_utils_1.BuiltInNetworkName.MegaETHTestnet,
|
|
173
|
-
type: RpcEndpointType.Custom,
|
|
174
|
-
url: controller_utils_1.BUILT_IN_CUSTOM_NETWORKS_RPC.MEGAETH_TESTNET,
|
|
175
|
-
},
|
|
176
|
-
],
|
|
177
|
-
},
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
136
|
/**
|
|
181
137
|
* Constructs properties for the NetworkController state whose values will be
|
|
182
138
|
* used if not provided to the constructor.
|
|
183
139
|
*
|
|
184
|
-
* @param [additionalDefaultNetworks] - An array of Hex Chain IDs representing the additional networks to be included as default.
|
|
185
140
|
* @returns The default NetworkController state.
|
|
186
141
|
*/
|
|
187
|
-
function getDefaultNetworkControllerState(
|
|
142
|
+
function getDefaultNetworkControllerState() {
|
|
188
143
|
const networksMetadata = {};
|
|
189
|
-
const networkConfigurationsByChainId = getDefaultNetworkConfigurationsByChainId(
|
|
144
|
+
const networkConfigurationsByChainId = getDefaultNetworkConfigurationsByChainId();
|
|
190
145
|
return {
|
|
191
146
|
selectedNetworkClientId: controller_utils_1.InfuraNetworkType.mainnet,
|
|
192
147
|
networksMetadata,
|
|
@@ -338,11 +293,8 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
338
293
|
* @param options - The options; see {@link NetworkControllerOptions}.
|
|
339
294
|
*/
|
|
340
295
|
constructor(options) {
|
|
341
|
-
const { messenger, state, infuraProjectId, log, getRpcServiceOptions
|
|
342
|
-
const initialState = {
|
|
343
|
-
...getDefaultNetworkControllerState(additionalDefaultNetworks),
|
|
344
|
-
...state,
|
|
345
|
-
};
|
|
296
|
+
const { messenger, state, infuraProjectId, log, getRpcServiceOptions } = options;
|
|
297
|
+
const initialState = { ...getDefaultNetworkControllerState(), ...state };
|
|
346
298
|
validateNetworkControllerState(initialState);
|
|
347
299
|
if (!infuraProjectId || typeof infuraProjectId !== 'string') {
|
|
348
300
|
throw new Error('Invalid Infura project ID');
|
|
@@ -416,8 +368,10 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
416
368
|
// ESLint is mistaken here; `name` is a string.
|
|
417
369
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
418
370
|
`${this.name}:getNetworkConfigurationByNetworkClientId`, this.getNetworkConfigurationByNetworkClientId.bind(this));
|
|
419
|
-
this.messagingSystem.registerActionHandler(
|
|
420
|
-
|
|
371
|
+
this.messagingSystem.registerActionHandler(
|
|
372
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
373
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
374
|
+
`${this.name}:getSelectedNetworkClient`, this.getSelectedNetworkClient.bind(this));
|
|
421
375
|
this.messagingSystem.registerActionHandler(
|
|
422
376
|
// ESLint is mistaken here; `name` is a string.
|
|
423
377
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
@@ -456,15 +410,6 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
456
410
|
}
|
|
457
411
|
return undefined;
|
|
458
412
|
}
|
|
459
|
-
/**
|
|
460
|
-
* Accesses the chain ID from the selected network client.
|
|
461
|
-
*
|
|
462
|
-
* @returns The chain ID of the selected network client in hex format or undefined if there is no network client.
|
|
463
|
-
*/
|
|
464
|
-
getSelectedChainId() {
|
|
465
|
-
const networkConfiguration = this.getNetworkConfigurationByNetworkClientId(this.state.selectedNetworkClientId);
|
|
466
|
-
return networkConfiguration?.chainId;
|
|
467
|
-
}
|
|
468
413
|
/**
|
|
469
414
|
* Internally, the Infura and custom network clients are categorized by type
|
|
470
415
|
* so that when accessing either kind of network client, TypeScript knows
|