@metamask-previews/network-controller 23.1.0-preview-49487623 → 23.1.0-preview-8a8331b2
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 +5 -58
- package/dist/NetworkController.cjs.map +1 -1
- package/dist/NetworkController.d.cts +2 -8
- package/dist/NetworkController.d.cts.map +1 -1
- package/dist/NetworkController.d.mts +2 -8
- package/dist/NetworkController.d.mts.map +1 -1
- package/dist/NetworkController.mjs +6 -59
- package/dist/NetworkController.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -106,32 +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 [defaultNetworks] - An array of Hex Chain IDs representing the default networks to be included.
|
|
110
109
|
* @returns The default value for `networkConfigurationsByChainId`.
|
|
111
110
|
*/
|
|
112
|
-
function getDefaultNetworkConfigurationsByChainId(
|
|
113
|
-
const infuraNetworks = getDefaultInfuraNetworkConfigurationsByChainId();
|
|
114
|
-
const customNetworks = getDefaultCustomNetworkConfigurationsByChainId();
|
|
115
|
-
// If no default networks are provided, use the default Infura networks
|
|
116
|
-
if (!defaultNetworks || defaultNetworks.length === 0) {
|
|
117
|
-
return infuraNetworks;
|
|
118
|
-
}
|
|
119
|
-
return defaultNetworks.reduce((obj, chainId) => {
|
|
120
|
-
if ((0, utils_1.hasProperty)(infuraNetworks, chainId)) {
|
|
121
|
-
obj[chainId] = infuraNetworks[chainId];
|
|
122
|
-
}
|
|
123
|
-
else if ((0, utils_1.hasProperty)(customNetworks, chainId)) {
|
|
124
|
-
obj[chainId] = customNetworks[chainId];
|
|
125
|
-
}
|
|
126
|
-
return obj;
|
|
127
|
-
}, {});
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Constructs a `networkConfigurationsByChainId` object for all default Infura networks.
|
|
131
|
-
*
|
|
132
|
-
* @returns The `networkConfigurationsByChainId` object of all Infura networks.
|
|
133
|
-
*/
|
|
134
|
-
function getDefaultInfuraNetworkConfigurationsByChainId() {
|
|
111
|
+
function getDefaultNetworkConfigurationsByChainId() {
|
|
135
112
|
return Object.values(controller_utils_1.InfuraNetworkType).reduce((obj, infuraNetworkType) => {
|
|
136
113
|
const chainId = controller_utils_1.ChainId[infuraNetworkType];
|
|
137
114
|
const rpcEndpointUrl =
|
|
@@ -156,42 +133,15 @@ function getDefaultInfuraNetworkConfigurationsByChainId() {
|
|
|
156
133
|
return { ...obj, [chainId]: networkConfiguration };
|
|
157
134
|
}, {});
|
|
158
135
|
}
|
|
159
|
-
/**
|
|
160
|
-
* Constructs a `networkConfigurationsByChainId` object for all default custom networks.
|
|
161
|
-
*
|
|
162
|
-
* @returns The `networkConfigurationsByChainId` object of all custom networks.
|
|
163
|
-
*/
|
|
164
|
-
function getDefaultCustomNetworkConfigurationsByChainId() {
|
|
165
|
-
const { ticker, rpcPrefs } = controller_utils_1.BUILT_IN_NETWORKS[controller_utils_1.BuiltInNetworkName.MegaETHTestnet];
|
|
166
|
-
return {
|
|
167
|
-
[controller_utils_1.ChainId[controller_utils_1.BuiltInNetworkName.MegaETHTestnet]]: {
|
|
168
|
-
blockExplorerUrls: [rpcPrefs.blockExplorerUrl],
|
|
169
|
-
chainId: controller_utils_1.ChainId[controller_utils_1.BuiltInNetworkName.MegaETHTestnet],
|
|
170
|
-
defaultRpcEndpointIndex: 0,
|
|
171
|
-
defaultBlockExplorerUrlIndex: 0,
|
|
172
|
-
name: controller_utils_1.NetworkNickname[controller_utils_1.BuiltInNetworkName.MegaETHTestnet],
|
|
173
|
-
nativeCurrency: ticker,
|
|
174
|
-
rpcEndpoints: [
|
|
175
|
-
{
|
|
176
|
-
failoverUrls: [],
|
|
177
|
-
networkClientId: controller_utils_1.BuiltInNetworkName.MegaETHTestnet,
|
|
178
|
-
type: RpcEndpointType.Custom,
|
|
179
|
-
url: controller_utils_1.BUILT_IN_CUSTOM_NETWORKS_RPC.MEGAETH_TESTNET,
|
|
180
|
-
},
|
|
181
|
-
],
|
|
182
|
-
},
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
136
|
/**
|
|
186
137
|
* Constructs properties for the NetworkController state whose values will be
|
|
187
138
|
* used if not provided to the constructor.
|
|
188
139
|
*
|
|
189
|
-
* @param [defaultNetworks] - An array of Hex Chain IDs representing the default networks to be included.
|
|
190
140
|
* @returns The default NetworkController state.
|
|
191
141
|
*/
|
|
192
|
-
function getDefaultNetworkControllerState(
|
|
142
|
+
function getDefaultNetworkControllerState() {
|
|
193
143
|
const networksMetadata = {};
|
|
194
|
-
const networkConfigurationsByChainId = getDefaultNetworkConfigurationsByChainId(
|
|
144
|
+
const networkConfigurationsByChainId = getDefaultNetworkConfigurationsByChainId();
|
|
195
145
|
return {
|
|
196
146
|
selectedNetworkClientId: controller_utils_1.InfuraNetworkType.mainnet,
|
|
197
147
|
networksMetadata,
|
|
@@ -343,11 +293,8 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
343
293
|
* @param options - The options; see {@link NetworkControllerOptions}.
|
|
344
294
|
*/
|
|
345
295
|
constructor(options) {
|
|
346
|
-
const { messenger, state, infuraProjectId, log, getRpcServiceOptions
|
|
347
|
-
const initialState = {
|
|
348
|
-
...getDefaultNetworkControllerState(defaultNetworks),
|
|
349
|
-
...state,
|
|
350
|
-
};
|
|
296
|
+
const { messenger, state, infuraProjectId, log, getRpcServiceOptions } = options;
|
|
297
|
+
const initialState = { ...getDefaultNetworkControllerState(), ...state };
|
|
351
298
|
validateNetworkControllerState(initialState);
|
|
352
299
|
if (!infuraProjectId || typeof infuraProjectId !== 'string') {
|
|
353
300
|
throw new Error('Invalid Infura project ID');
|