@metamask-previews/network-controller 26.0.0-preview-d6fe4594 → 27.0.0-preview-84f90603

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,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [27.0.0]
11
+
10
12
  ### Added
11
13
 
12
14
  - Add `NetworkController:rpcEndpointChainAvailable` messenger event ([#7166](https://github.com/MetaMask/core/pull/7166))
@@ -31,6 +33,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
31
33
  - In clients, it is now possible for multiple versions of these packages to exist in the dependency tree.
32
34
  - For example, this scenario would be valid: a client relies on `@metamask/controller-a` 1.0.0 and `@metamask/controller-b` 1.0.0, and `@metamask/controller-b` depends on `@metamask/controller-a` 1.1.0.
33
35
  - Note, however, that the versions specified in the client's `package.json` always "win", and you are expected to keep them up to date so as not to break controller and service intercommunication.
36
+ - Automatically update network status metadata when chain-level RPC events are published ([#7186](https://github.com/MetaMask/core/pull/7186))
37
+ - `NetworkController` now automatically subscribes to `NetworkController:rpcEndpointChainUnavailable`, `NetworkController:rpcEndpointChainDegraded`, and `NetworkController:rpcEndpointChainAvailable` events and updates the corresponding network's status metadata in state when these events are published.
38
+ - This enables real-time network status updates without requiring explicit `lookupNetwork` calls, providing more accurate and timely network availability information.
34
39
 
35
40
  ## [26.0.0]
36
41
 
@@ -1040,7 +1045,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1040
1045
 
1041
1046
  All changes listed after this point were applied to this package following the monorepo conversion.
1042
1047
 
1043
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/network-controller@26.0.0...HEAD
1048
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/network-controller@27.0.0...HEAD
1049
+ [27.0.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@26.0.0...@metamask/network-controller@27.0.0
1044
1050
  [26.0.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@25.0.0...@metamask/network-controller@26.0.0
1045
1051
  [25.0.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@24.3.1...@metamask/network-controller@25.0.0
1046
1052
  [24.3.1]: https://github.com/MetaMask/core/compare/@metamask/network-controller@24.3.0...@metamask/network-controller@24.3.1
@@ -444,6 +444,21 @@ class NetworkController extends base_controller_1.BaseController {
444
444
  this.messenger.registerActionHandler(`${this.name}:addNetwork`, this.addNetwork.bind(this));
445
445
  this.messenger.registerActionHandler(`${this.name}:removeNetwork`, this.removeNetwork.bind(this));
446
446
  this.messenger.registerActionHandler(`${this.name}:updateNetwork`, this.updateNetwork.bind(this));
447
+ this.messenger.subscribe(`${this.name}:rpcEndpointChainUnavailable`, ({ networkClientId }) => {
448
+ __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_updateMetadataForNetwork).call(this, networkClientId, {
449
+ networkStatus: constants_1.NetworkStatus.Unavailable,
450
+ });
451
+ });
452
+ this.messenger.subscribe(`${this.name}:rpcEndpointChainDegraded`, ({ networkClientId }) => {
453
+ __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_updateMetadataForNetwork).call(this, networkClientId, {
454
+ networkStatus: constants_1.NetworkStatus.Degraded,
455
+ });
456
+ });
457
+ this.messenger.subscribe(`${this.name}:rpcEndpointChainAvailable`, ({ networkClientId }) => {
458
+ __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_updateMetadataForNetwork).call(this, networkClientId, {
459
+ networkStatus: constants_1.NetworkStatus.Available,
460
+ });
461
+ });
447
462
  }
448
463
  /**
449
464
  * Enables the RPC failover functionality. That is, if any RPC endpoints are
@@ -1144,7 +1159,10 @@ async function _NetworkController_determineNetworkMetadata(networkClientId) {
1144
1159
  */
1145
1160
  async function _NetworkController_lookupGivenNetwork(networkClientId) {
1146
1161
  const { networkStatus, isEIP1559Compatible } = await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_determineNetworkMetadata).call(this, networkClientId);
1147
- __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_updateMetadataForNetwork).call(this, networkClientId, networkStatus, isEIP1559Compatible);
1162
+ __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_updateMetadataForNetwork).call(this, networkClientId, {
1163
+ networkStatus,
1164
+ isEIP1559Compatible,
1165
+ });
1148
1166
  }, _NetworkController_lookupSelectedNetwork =
1149
1167
  /**
1150
1168
  * Uses a request for the latest block to gather the following information on
@@ -1204,7 +1222,10 @@ async function _NetworkController_lookupSelectedNetwork() {
1204
1222
  throw error;
1205
1223
  }
1206
1224
  }
1207
- __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_updateMetadataForNetwork).call(this, this.state.selectedNetworkClientId, networkStatus, isEIP1559Compatible);
1225
+ __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_updateMetadataForNetwork).call(this, this.state.selectedNetworkClientId, {
1226
+ networkStatus,
1227
+ isEIP1559Compatible,
1228
+ });
1208
1229
  if (isInfura) {
1209
1230
  if (networkStatus === constants_1.NetworkStatus.Available) {
1210
1231
  this.messenger.publish('NetworkController:infuraIsUnblocked');
@@ -1219,7 +1240,7 @@ async function _NetworkController_lookupSelectedNetwork() {
1219
1240
  // previously connected to an Infura network that was blocked
1220
1241
  this.messenger.publish('NetworkController:infuraIsUnblocked');
1221
1242
  }
1222
- }, _NetworkController_updateMetadataForNetwork = function _NetworkController_updateMetadataForNetwork(networkClientId, networkStatus, isEIP1559Compatible) {
1243
+ }, _NetworkController_updateMetadataForNetwork = function _NetworkController_updateMetadataForNetwork(networkClientId, metadata) {
1223
1244
  this.update((state) => {
1224
1245
  if (state.networksMetadata[networkClientId] === undefined) {
1225
1246
  state.networksMetadata[networkClientId] = {
@@ -1227,13 +1248,15 @@ async function _NetworkController_lookupSelectedNetwork() {
1227
1248
  EIPS: {},
1228
1249
  };
1229
1250
  }
1230
- const meta = state.networksMetadata[networkClientId];
1231
- meta.status = networkStatus;
1232
- if (isEIP1559Compatible === undefined) {
1233
- delete meta.EIPS[1559];
1234
- }
1235
- else {
1236
- meta.EIPS[1559] = isEIP1559Compatible;
1251
+ const newMetadata = state.networksMetadata[networkClientId];
1252
+ newMetadata.status = metadata.networkStatus;
1253
+ if ('isEIP1559Compatible' in metadata) {
1254
+ if (metadata.isEIP1559Compatible === undefined) {
1255
+ delete newMetadata.EIPS[1559];
1256
+ }
1257
+ else {
1258
+ newMetadata.EIPS[1559] = metadata.isEIP1559Compatible;
1259
+ }
1237
1260
  }
1238
1261
  });
1239
1262
  }, _NetworkController_getLatestBlock = function _NetworkController_getLatestBlock(networkClientId) {