@metamask-previews/network-controller 25.0.0-preview-2e88eaea → 25.0.0-preview-c96ff8f

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
@@ -11,8 +11,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
11
11
 
12
12
  - **BREAKING:** Use `InternalProvider` instead of `SafeEventEmitterProvider` ([#6796](https://github.com/MetaMask/core/pull/6796))
13
13
  - Providers accessible either via network clients or global proxies no longer emit events (or inherit from EventEmitter, for that matter).
14
+ - **BREAKING:** Make `Provider` type more specific ([#7061](https://github.com/MetaMask/core/pull/7061))
15
+ - The `Provider` type is now an `InternalProvider` with a context type of `{ origin: string; skipCache: boolean } & Record<string, unknown>`.
16
+ - **BREAKING:** Stop retrying `undefined` results for methods that include a block tag parameter ([#7001](https://github.com/MetaMask/core/pull/7001))
17
+ - The network client middleware, via `@metamask/eth-json-rpc-middleware`, will now throw an error if it encounters an
18
+ `undefined` result when dispatching a request with a later block number than the originally requested block number.
19
+ - In practice, this should happen rarely if ever.
20
+ - **BREAKING:** Migrate `NetworkClient` to `JsonRpcEngineV2` ([#7065](https://github.com/MetaMask/core/pull/7065))
21
+ - This ought to be unobservable, but we mark it as breaking out of an abundance of caution.
14
22
  - Bump `@metamask/controller-utils` from `^11.14.1` to `^11.15.0` ([#7003](https://github.com/MetaMask/core/pull/7003))
15
23
 
24
+ ### Fixed
25
+
26
+ - Ensure `networksMetadata` never references old network client IDs ([#7047](https://github.com/MetaMask/core/pull/7047))
27
+ - When removing a network configuration, ensure that metadata for all RPC endpoints in the network configuration are also removed from `networksMetadata`
28
+ - When initializing the controller, remove metadata for RPC endpoints in `networksMetadata` that are not present in a network configuration
29
+
16
30
  ## [25.0.0]
17
31
 
18
32
  ### Changed
@@ -335,14 +335,21 @@ function validateInitialState(state) {
335
335
  */
336
336
  function correctInitialState(state, messenger) {
337
337
  const networkConfigurationsSortedByChainId = getNetworkConfigurations(state).sort((a, b) => a.chainId.localeCompare(b.chainId));
338
- const networkClientIds = getAvailableNetworkClientIds(networkConfigurationsSortedByChainId);
338
+ const availableNetworkClientIds = getAvailableNetworkClientIds(networkConfigurationsSortedByChainId);
339
+ const invalidNetworkClientIdsWithMetadata = Object.keys(state.networksMetadata).filter((networkClientId) => !availableNetworkClientIds.includes(networkClientId));
339
340
  return (0, immer_1.produce)(state, (newState) => {
340
- if (!networkClientIds.includes(state.selectedNetworkClientId)) {
341
+ if (!availableNetworkClientIds.includes(state.selectedNetworkClientId)) {
341
342
  const firstNetworkConfiguration = networkConfigurationsSortedByChainId[0];
342
343
  const newSelectedNetworkClientId = firstNetworkConfiguration.rpcEndpoints[firstNetworkConfiguration.defaultRpcEndpointIndex].networkClientId;
343
344
  messenger.call('ErrorReportingService:captureException', new Error(`\`selectedNetworkClientId\` '${state.selectedNetworkClientId}' does not refer to an RPC endpoint within a network configuration; correcting to '${newSelectedNetworkClientId}'`));
344
345
  newState.selectedNetworkClientId = newSelectedNetworkClientId;
345
346
  }
347
+ if (invalidNetworkClientIdsWithMetadata.length > 0) {
348
+ for (const invalidNetworkClientId of invalidNetworkClientIdsWithMetadata) {
349
+ delete newState.networksMetadata[invalidNetworkClientId];
350
+ }
351
+ messenger.call('ErrorReportingService:captureException', new Error('`networksMetadata` had invalid network client IDs, which have been removed'));
352
+ }
346
353
  });
347
354
  }
348
355
  /**
@@ -962,6 +969,9 @@ class NetworkController extends base_controller_1.BaseController {
962
969
  mode: 'remove',
963
970
  existingNetworkConfiguration,
964
971
  });
972
+ for (const rpcEndpoint of existingNetworkConfiguration.rpcEndpoints) {
973
+ delete state.networksMetadata[rpcEndpoint.networkClientId];
974
+ }
965
975
  });
966
976
  this.messenger.publish('NetworkController:networkRemoved', existingNetworkConfiguration);
967
977
  }
@@ -980,6 +990,8 @@ class NetworkController extends base_controller_1.BaseController {
980
990
  *
981
991
  * In-progress requests will not be aborted.
982
992
  */
993
+ // We're intentionally changing the signature of an extended method.
994
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
983
995
  async destroy() {
984
996
  await __classPrivateFieldGet(this, _NetworkController_blockTrackerProxy, "f")?.destroy();
985
997
  }
@@ -1236,6 +1248,8 @@ async function _NetworkController_lookupSelectedNetwork() {
1236
1248
  return new Promise((resolve, reject) => {
1237
1249
  ethQuery.sendAsync({ method: 'eth_getBlockByNumber', params: ['latest', false] }, (error, block) => {
1238
1250
  if (error) {
1251
+ // This error comes from JsonRpcEngine, we don't control it.
1252
+ // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
1239
1253
  reject(error);
1240
1254
  }
1241
1255
  else {