@metamask-previews/network-controller 23.5.0-preview-d9a49231 → 23.5.1-preview-4ef4efd7

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/CHANGELOG.md CHANGED
@@ -7,14 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [23.5.1]
11
+
12
+ ### Changed
13
+
14
+ - Block tracker errors will no longer be wrapped under "PollingBlockTracker - encountered an error while attempting to update latest block" ([#5860](https://github.com/MetaMask/core/pull/5860))
15
+ - Bump dependencies ([#5867](https://github.com/MetaMask/core/pull/5867), [#5860](https://github.com/MetaMask/core/pull/5860))
16
+ - Bump `@metamask/eth-block-tracker` to `^12.0.1`
17
+ - Bump `@metamask/eth-json-rpc-infura` to `^10.2.0`
18
+ - Bump `@metamask/eth-json-rpc-middleware` to `^17.0.1`
19
+
10
20
  ### Fixed
11
21
 
12
- - Improved error handling in RPC service with more specific error types ([#5843](https://github.com/MetaMask/core/pull/5843)):
13
- - 401 responses now throw an "Unauthorized" error
14
- - 402/404/5xx responses now throw a "Resource Unavailable" error
15
- - 429 responses now throw a "Rate Limiting" error
16
- - Other 4xx responses now throw a generic HTTP client error
17
- - Invalid JSON responses now throw a "Parse" error
22
+ - Rather than throwing an error, NetworkController now corrects an invalid initial `selectedNetworkClientId` to point to the default RPC endpoint of the first network sorted by chain ID ([#5851](https://github.com/MetaMask/core/pull/5851))
23
+ - Fix the block tracker so that it will now reject if an error is thrown while making the request instead of hanging ([#5860](https://github.com/MetaMask/core/pull/5860))
18
24
 
19
25
  ## [23.5.0]
20
26
 
@@ -860,7 +866,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
860
866
 
861
867
  All changes listed after this point were applied to this package following the monorepo conversion.
862
868
 
863
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/network-controller@23.5.0...HEAD
869
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/network-controller@23.5.1...HEAD
870
+ [23.5.1]: https://github.com/MetaMask/core/compare/@metamask/network-controller@23.5.0...@metamask/network-controller@23.5.1
864
871
  [23.5.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@23.4.0...@metamask/network-controller@23.5.0
865
872
  [23.4.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@23.3.0...@metamask/network-controller@23.4.0
866
873
  [23.3.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@23.2.0...@metamask/network-controller@23.3.0
@@ -46,6 +46,7 @@ const rpc_errors_1 = require("@metamask/rpc-errors");
46
46
  const swappable_obj_proxy_1 = require("@metamask/swappable-obj-proxy");
47
47
  const utils_1 = require("@metamask/utils");
48
48
  const fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
49
+ const immer_1 = require("immer");
49
50
  const lodash_1 = require("lodash");
50
51
  const reselect_1 = require("reselect");
51
52
  const URI = __importStar(require("uri-js"));
@@ -300,7 +301,7 @@ function deriveInfuraNetworkNameFromRpcEndpointUrl(rpcEndpointUrl) {
300
301
  * @param state - The NetworkController state to verify.
301
302
  * @throws if the state is invalid in some way.
302
303
  */
303
- function validateNetworkControllerState(state) {
304
+ function validateInitialState(state) {
304
305
  const networkConfigurationEntries = Object.entries(state.networkConfigurationsByChainId);
305
306
  const networkClientIds = getAvailableNetworkClientIds(getNetworkConfigurations(state));
306
307
  if (networkConfigurationEntries.length === 0) {
@@ -324,12 +325,27 @@ function validateNetworkControllerState(state) {
324
325
  if ([...new Set(networkClientIds)].length < networkClientIds.length) {
325
326
  throw new Error('NetworkController state has invalid `networkConfigurationsByChainId`: Every RPC endpoint across all network configurations must have a unique `networkClientId`');
326
327
  }
327
- if (!networkClientIds.includes(state.selectedNetworkClientId)) {
328
- throw new Error(
329
- // This ESLint rule mistakenly produces an error.
330
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
331
- `NetworkController state is invalid: \`selectedNetworkClientId\` '${state.selectedNetworkClientId}' does not refer to an RPC endpoint within a network configuration`);
332
- }
328
+ }
329
+ /**
330
+ * Checks that the given initial NetworkController state is internally
331
+ * consistent similar to `validateInitialState`, but if an anomaly is detected,
332
+ * it does its best to correct the state and logs an error to Sentry.
333
+ *
334
+ * @param state - The NetworkController state to verify.
335
+ * @param messenger - The NetworkController messenger.
336
+ * @returns The corrected state.
337
+ */
338
+ function correctInitialState(state, messenger) {
339
+ const networkConfigurationsSortedByChainId = getNetworkConfigurations(state).sort((a, b) => a.chainId.localeCompare(b.chainId));
340
+ const networkClientIds = getAvailableNetworkClientIds(networkConfigurationsSortedByChainId);
341
+ return (0, immer_1.produce)(state, (newState) => {
342
+ if (!networkClientIds.includes(state.selectedNetworkClientId)) {
343
+ const firstNetworkConfiguration = networkConfigurationsSortedByChainId[0];
344
+ const newSelectedNetworkClientId = firstNetworkConfiguration.rpcEndpoints[firstNetworkConfiguration.defaultRpcEndpointIndex].networkClientId;
345
+ messenger.call('ErrorReportingService:captureException', new Error(`\`selectedNetworkClientId\` '${state.selectedNetworkClientId}' does not refer to an RPC endpoint within a network configuration; correcting to '${newSelectedNetworkClientId}'`));
346
+ newState.selectedNetworkClientId = newSelectedNetworkClientId;
347
+ }
348
+ });
333
349
  }
334
350
  /**
335
351
  * Transforms a map of chain ID to network configuration to a map of network
@@ -361,7 +377,8 @@ class NetworkController extends base_controller_1.BaseController {
361
377
  ...getDefaultNetworkControllerState(additionalDefaultNetworks),
362
378
  ...state,
363
379
  };
364
- validateNetworkControllerState(initialState);
380
+ validateInitialState(initialState);
381
+ const correctedInitialState = correctInitialState(initialState, messenger);
365
382
  if (!infuraProjectId || typeof infuraProjectId !== 'string') {
366
383
  throw new Error('Invalid Infura project ID');
367
384
  }
@@ -382,7 +399,7 @@ class NetworkController extends base_controller_1.BaseController {
382
399
  },
383
400
  },
384
401
  messenger,
385
- state: initialState,
402
+ state: correctedInitialState,
386
403
  });
387
404
  _NetworkController_instances.add(this);
388
405
  _NetworkController_ethQuery.set(this, void 0);