@metamask-previews/network-controller 23.1.0-preview-57dc1075 → 23.1.0-preview-9838d8a5
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 -53
- package/dist/NetworkController.cjs.map +1 -1
- package/dist/NetworkController.d.cts +2 -7
- package/dist/NetworkController.d.cts.map +1 -1
- package/dist/NetworkController.d.mts +2 -7
- package/dist/NetworkController.d.mts.map +1 -1
- package/dist/NetworkController.mjs +6 -54
- package/dist/NetworkController.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');
|