@metamask-previews/network-controller 23.1.0-preview-8a8331b2 → 23.1.0-preview-57dc1075
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 +53 -5
- package/dist/NetworkController.cjs.map +1 -1
- package/dist/NetworkController.d.cts +7 -2
- package/dist/NetworkController.d.cts.map +1 -1
- package/dist/NetworkController.d.mts +7 -2
- package/dist/NetworkController.d.mts.map +1 -1
- package/dist/NetworkController.mjs +54 -6
- package/dist/NetworkController.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -106,9 +106,27 @@ 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.
|
|
109
110
|
* @returns The default value for `networkConfigurationsByChainId`.
|
|
110
111
|
*/
|
|
111
|
-
function getDefaultNetworkConfigurationsByChainId() {
|
|
112
|
+
function getDefaultNetworkConfigurationsByChainId(additionalDefaultNetworks = []) {
|
|
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() {
|
|
112
130
|
return Object.values(controller_utils_1.InfuraNetworkType).reduce((obj, infuraNetworkType) => {
|
|
113
131
|
const chainId = controller_utils_1.ChainId[infuraNetworkType];
|
|
114
132
|
const rpcEndpointUrl =
|
|
@@ -133,15 +151,42 @@ function getDefaultNetworkConfigurationsByChainId() {
|
|
|
133
151
|
return { ...obj, [chainId]: networkConfiguration };
|
|
134
152
|
}, {});
|
|
135
153
|
}
|
|
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
|
+
}
|
|
136
180
|
/**
|
|
137
181
|
* Constructs properties for the NetworkController state whose values will be
|
|
138
182
|
* used if not provided to the constructor.
|
|
139
183
|
*
|
|
184
|
+
* @param [additionalDefaultNetworks] - An array of Hex Chain IDs representing the additional networks to be included as default.
|
|
140
185
|
* @returns The default NetworkController state.
|
|
141
186
|
*/
|
|
142
|
-
function getDefaultNetworkControllerState() {
|
|
187
|
+
function getDefaultNetworkControllerState(additionalDefaultNetworks) {
|
|
143
188
|
const networksMetadata = {};
|
|
144
|
-
const networkConfigurationsByChainId = getDefaultNetworkConfigurationsByChainId();
|
|
189
|
+
const networkConfigurationsByChainId = getDefaultNetworkConfigurationsByChainId(additionalDefaultNetworks);
|
|
145
190
|
return {
|
|
146
191
|
selectedNetworkClientId: controller_utils_1.InfuraNetworkType.mainnet,
|
|
147
192
|
networksMetadata,
|
|
@@ -293,8 +338,11 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
293
338
|
* @param options - The options; see {@link NetworkControllerOptions}.
|
|
294
339
|
*/
|
|
295
340
|
constructor(options) {
|
|
296
|
-
const { messenger, state, infuraProjectId, log, getRpcServiceOptions } = options;
|
|
297
|
-
const initialState = {
|
|
341
|
+
const { messenger, state, infuraProjectId, log, getRpcServiceOptions, additionalDefaultNetworks, } = options;
|
|
342
|
+
const initialState = {
|
|
343
|
+
...getDefaultNetworkControllerState(additionalDefaultNetworks),
|
|
344
|
+
...state,
|
|
345
|
+
};
|
|
298
346
|
validateNetworkControllerState(initialState);
|
|
299
347
|
if (!infuraProjectId || typeof infuraProjectId !== 'string') {
|
|
300
348
|
throw new Error('Invalid Infura project ID');
|