@metamask-previews/network-controller 24.1.0-preview-9a5f096 → 24.1.0-preview-f3f2e8c8

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +0 -17
  2. package/dist/NetworkController.cjs +196 -207
  3. package/dist/NetworkController.cjs.map +1 -1
  4. package/dist/NetworkController.d.cts +16 -20
  5. package/dist/NetworkController.d.cts.map +1 -1
  6. package/dist/NetworkController.d.mts +16 -20
  7. package/dist/NetworkController.d.mts.map +1 -1
  8. package/dist/NetworkController.mjs +196 -207
  9. package/dist/NetworkController.mjs.map +1 -1
  10. package/dist/create-auto-managed-network-client.cjs +1 -3
  11. package/dist/create-auto-managed-network-client.cjs.map +1 -1
  12. package/dist/create-auto-managed-network-client.d.cts +1 -4
  13. package/dist/create-auto-managed-network-client.d.cts.map +1 -1
  14. package/dist/create-auto-managed-network-client.d.mts +1 -4
  15. package/dist/create-auto-managed-network-client.d.mts.map +1 -1
  16. package/dist/create-auto-managed-network-client.mjs +1 -3
  17. package/dist/create-auto-managed-network-client.mjs.map +1 -1
  18. package/dist/create-network-client.cjs +1 -3
  19. package/dist/create-network-client.cjs.map +1 -1
  20. package/dist/create-network-client.d.cts +1 -4
  21. package/dist/create-network-client.d.cts.map +1 -1
  22. package/dist/create-network-client.d.mts +1 -4
  23. package/dist/create-network-client.d.mts.map +1 -1
  24. package/dist/create-network-client.mjs +1 -3
  25. package/dist/create-network-client.mjs.map +1 -1
  26. package/dist/rpc-service/rpc-service.cjs +3 -17
  27. package/dist/rpc-service/rpc-service.cjs.map +1 -1
  28. package/dist/rpc-service/rpc-service.d.cts +0 -5
  29. package/dist/rpc-service/rpc-service.d.cts.map +1 -1
  30. package/dist/rpc-service/rpc-service.d.mts +0 -5
  31. package/dist/rpc-service/rpc-service.d.mts.map +1 -1
  32. package/dist/rpc-service/rpc-service.mjs +5 -19
  33. package/dist/rpc-service/rpc-service.mjs.map +1 -1
  34. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -7,21 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
- ### Added
11
-
12
- - Add two new controller state metadata properties: `includeInStateLogs` and `usedInUi` ([#6525](https://github.com/MetaMask/core/pull/6525))
13
-
14
- ### Changed
15
-
16
- - Bump `@metamask/base-controller` from `^8.1.0` to `^8.3.0` ([#6355](https://github.com/MetaMask/core/pull/6355), [#6465](https://github.com/MetaMask/core/pull/6465))
17
- - Rephrase "circuit broken" errors so they are more user-friendly ([#6423](https://github.com/MetaMask/core/pull/6423))
18
- - These are errors produced when a request is made to an RPC endpoint after it returns too many consecutive 5xx responses and the underlying circuit is open.
19
-
20
- ### Deprecated
21
-
22
- - Deprecate `lookupNetworkByClientId` ([#6308](https://github.com/MetaMask/core/pull/6308))
23
- - `lookupNetwork` already supports passing in a network client ID; please use this going forward instead.
24
-
25
10
  ## [24.1.0]
26
11
 
27
12
  ### Added
@@ -33,8 +18,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
33
18
 
34
19
  - Bump `@metamask/base-controller` from `^8.0.1` to `^8.1.0` ([#6284](https://github.com/MetaMask/core/pull/6284))
35
20
  - Bump `@metamask/controller-utils` from `^11.11.0` to `^11.12.0` ([#6303](https://github.com/MetaMask/core/pull/6303))
36
- - This effectively changes the `onDegraded` property on `AbstractRpcService` so that the event listener payload may be an object with either a `endpointUrl` property, `error` + `endpointUrl` properties, or `value` + `endpointUrl` properties
37
- - **NOTE:** Although `error` and `value` are new, optional properties, this change makes an inadvertent breaking change to the signature of the event listener due to how TypeScript compares function types. We have conciously decided not to re-release this change under a major version, so be advised.
38
21
 
39
22
  ## [24.0.1]
40
23
 
@@ -36,7 +36,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
36
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
39
- var _NetworkController_instances, _NetworkController_ethQuery, _NetworkController_infuraProjectId, _NetworkController_previouslySelectedNetworkClientId, _NetworkController_providerProxy, _NetworkController_blockTrackerProxy, _NetworkController_autoManagedNetworkClientRegistry, _NetworkController_autoManagedNetworkClient, _NetworkController_log, _NetworkController_getRpcServiceOptions, _NetworkController_getBlockTrackerOptions, _NetworkController_networkConfigurationsByNetworkClientId, _NetworkController_isRpcFailoverEnabled, _NetworkController_updateRpcFailoverEnabled, _NetworkController_refreshNetwork, _NetworkController_determineNetworkMetadata, _NetworkController_lookupGivenNetwork, _NetworkController_lookupSelectedNetwork, _NetworkController_updateMetadataForNetwork, _NetworkController_getLatestBlock, _NetworkController_determineEIP1559Compatibility, _NetworkController_validateNetworkFields, _NetworkController_determineNetworkConfigurationToPersist, _NetworkController_registerNetworkClientsAsNeeded, _NetworkController_unregisterNetworkClientsAsNeeded, _NetworkController_updateNetworkConfigurations, _NetworkController_ensureAutoManagedNetworkClientRegistryPopulated, _NetworkController_createAutoManagedNetworkClientRegistry, _NetworkController_applyNetworkSelection;
39
+ var _NetworkController_instances, _NetworkController_ethQuery, _NetworkController_infuraProjectId, _NetworkController_previouslySelectedNetworkClientId, _NetworkController_providerProxy, _NetworkController_blockTrackerProxy, _NetworkController_autoManagedNetworkClientRegistry, _NetworkController_autoManagedNetworkClient, _NetworkController_log, _NetworkController_getRpcServiceOptions, _NetworkController_getBlockTrackerOptions, _NetworkController_networkConfigurationsByNetworkClientId, _NetworkController_isRpcFailoverEnabled, _NetworkController_updateRpcFailoverEnabled, _NetworkController_refreshNetwork, _NetworkController_getLatestBlock, _NetworkController_determineEIP1559Compatibility, _NetworkController_validateNetworkFields, _NetworkController_determineNetworkConfigurationToPersist, _NetworkController_registerNetworkClientsAsNeeded, _NetworkController_unregisterNetworkClientsAsNeeded, _NetworkController_updateNetworkConfigurations, _NetworkController_ensureAutoManagedNetworkClientRegistryPopulated, _NetworkController_createAutoManagedNetworkClientRegistry, _NetworkController_applyNetworkSelection;
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
41
  exports.NetworkController = exports.selectAvailableNetworkClientIds = exports.getAvailableNetworkClientIds = exports.selectNetworkConfigurations = exports.getNetworkConfigurations = exports.getDefaultNetworkControllerState = exports.knownKeysOf = exports.RpcEndpointType = void 0;
42
42
  const base_controller_1 = require("@metamask/base-controller");
@@ -386,22 +386,16 @@ class NetworkController extends base_controller_1.BaseController {
386
386
  name: controllerName,
387
387
  metadata: {
388
388
  selectedNetworkClientId: {
389
- includeInStateLogs: true,
390
389
  persist: true,
391
390
  anonymous: false,
392
- usedInUi: true,
393
391
  },
394
392
  networksMetadata: {
395
- includeInStateLogs: true,
396
393
  persist: true,
397
394
  anonymous: false,
398
- usedInUi: true,
399
395
  },
400
396
  networkConfigurationsByChainId: {
401
- includeInStateLogs: true,
402
397
  persist: true,
403
398
  anonymous: false,
404
- usedInUi: true,
405
399
  },
406
400
  },
407
401
  messenger,
@@ -575,43 +569,210 @@ class NetworkController extends base_controller_1.BaseController {
575
569
  await this.lookupNetwork();
576
570
  }
577
571
  /**
578
- * Uses a request for the latest block to gather the following information on
579
- * the given or selected network, persisting it to state:
572
+ * Refreshes the network meta with EIP-1559 support and the network status
573
+ * based on the given network client ID.
580
574
  *
581
- * - The connectivity status: whether it is available, geo-blocked (Infura
582
- * only), unavailable, or unknown
583
- * - The capabilities status: whether it supports EIP-1559, whether it does
584
- * not, or whether it is unknown
585
- *
586
- * @param networkClientId - The ID of the network client to inspect.
587
- * If no ID is provided, uses the currently selected network.
575
+ * @param networkClientId - The ID of the network client to update.
588
576
  */
589
- async lookupNetwork(networkClientId) {
590
- if (networkClientId) {
591
- await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_lookupGivenNetwork).call(this, networkClientId);
577
+ async lookupNetworkByClientId(networkClientId) {
578
+ const isInfura = (0, controller_utils_1.isInfuraNetworkType)(networkClientId);
579
+ let updatedNetworkStatus;
580
+ let updatedIsEIP1559Compatible;
581
+ try {
582
+ updatedIsEIP1559Compatible =
583
+ await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_determineEIP1559Compatibility).call(this, networkClientId);
584
+ updatedNetworkStatus = constants_1.NetworkStatus.Available;
592
585
  }
593
- else {
594
- await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_lookupSelectedNetwork).call(this);
586
+ catch (error) {
587
+ debugLog('NetworkController: lookupNetworkByClientId: ', error);
588
+ // TODO: mock ethQuery.sendAsync to throw error without error code
589
+ /* istanbul ignore else */
590
+ if (isErrorWithCode(error)) {
591
+ let responseBody;
592
+ if (isInfura &&
593
+ (0, utils_1.hasProperty)(error, 'message') &&
594
+ typeof error.message === 'string') {
595
+ try {
596
+ responseBody = JSON.parse(error.message);
597
+ }
598
+ catch {
599
+ // error.message must not be JSON
600
+ __classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetworkByClientId: json parse error: ', error);
601
+ }
602
+ }
603
+ if ((0, utils_1.isPlainObject)(responseBody) &&
604
+ responseBody.error === constants_1.INFURA_BLOCKED_KEY) {
605
+ updatedNetworkStatus = constants_1.NetworkStatus.Blocked;
606
+ }
607
+ else if (error.code === rpc_errors_1.errorCodes.rpc.internal) {
608
+ updatedNetworkStatus = constants_1.NetworkStatus.Unknown;
609
+ __classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetworkByClientId: rpc internal error: ', error);
610
+ }
611
+ else {
612
+ updatedNetworkStatus = constants_1.NetworkStatus.Unavailable;
613
+ __classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetworkByClientId: ', error);
614
+ }
615
+ }
616
+ else if (typeof Error !== 'undefined' &&
617
+ (0, utils_1.hasProperty)(error, 'message') &&
618
+ typeof error.message === 'string' &&
619
+ error.message.includes('No custom network client was found with the ID')) {
620
+ throw error;
621
+ }
622
+ else {
623
+ debugLog('NetworkController - could not determine network status', error);
624
+ updatedNetworkStatus = constants_1.NetworkStatus.Unknown;
625
+ __classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetworkByClientId: ', error);
626
+ }
595
627
  }
628
+ this.update((state) => {
629
+ if (state.networksMetadata[networkClientId] === undefined) {
630
+ state.networksMetadata[networkClientId] = {
631
+ status: constants_1.NetworkStatus.Unknown,
632
+ EIPS: {},
633
+ };
634
+ }
635
+ const meta = state.networksMetadata[networkClientId];
636
+ meta.status = updatedNetworkStatus;
637
+ if (updatedIsEIP1559Compatible === undefined) {
638
+ delete meta.EIPS[1559];
639
+ }
640
+ else {
641
+ meta.EIPS[1559] = updatedIsEIP1559Compatible;
642
+ }
643
+ });
596
644
  }
597
645
  /**
598
- * Uses a request for the latest block to gather the following information on
599
- * the given network, persisting it to state:
646
+ * Persists the following metadata about the given or selected network to
647
+ * state:
600
648
  *
601
- * - The connectivity status: whether the network is available, geo-blocked
602
- * (Infura only), unavailable, or unknown
603
- * - The feature compatibility status: whether the network supports EIP-1559,
604
- * whether it does not, or whether it is unknown
649
+ * - The status of the network, namely, whether it is available, geo-blocked
650
+ * (Infura only), or unavailable, or whether the status is unknown
651
+ * - Whether the network supports EIP-1559, or whether it is unknown
605
652
  *
606
- * @param networkClientId - The ID of the network client to inspect.
607
- * @deprecated Please use `lookupNetwork` and pass a network client ID
608
- * instead. This method will be removed in a future major version.
653
+ * Note that it is possible for the network to be switched while this data is
654
+ * being collected. If that is the case, no metadata for the (now previously)
655
+ * selected network will be updated.
656
+ *
657
+ * @param networkClientId - The ID of the network client to update.
658
+ * If no ID is provided, uses the currently selected network.
609
659
  */
610
- // We are planning on removing this so we aren't interested in testing this
611
- // right now.
612
- /* istanbul ignore next */
613
- async lookupNetworkByClientId(networkClientId) {
614
- await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_lookupGivenNetwork).call(this, networkClientId);
660
+ async lookupNetwork(networkClientId) {
661
+ if (networkClientId) {
662
+ await this.lookupNetworkByClientId(networkClientId);
663
+ return;
664
+ }
665
+ if (!__classPrivateFieldGet(this, _NetworkController_ethQuery, "f")) {
666
+ return;
667
+ }
668
+ const isInfura = __classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClient, "f")?.configuration.type ===
669
+ types_1.NetworkClientType.Infura;
670
+ let networkChanged = false;
671
+ const listener = () => {
672
+ networkChanged = true;
673
+ try {
674
+ this.messagingSystem.unsubscribe('NetworkController:networkDidChange', listener);
675
+ }
676
+ catch (error) {
677
+ // In theory, this `catch` should not be necessary given that this error
678
+ // would occur "inside" of the call to `#determineEIP1559Compatibility`
679
+ // below and so it should be caught by the `try`/`catch` below (it is
680
+ // impossible to reproduce in tests for that reason). However, somehow
681
+ // it occurs within Mobile and so we have to add our own `try`/`catch`
682
+ // here.
683
+ /* istanbul ignore next */
684
+ if (!(error instanceof Error) ||
685
+ error.message !==
686
+ 'Subscription not found for event: NetworkController:networkDidChange') {
687
+ // Again, this error should not happen and is impossible to reproduce
688
+ // in tests.
689
+ /* istanbul ignore next */
690
+ throw error;
691
+ }
692
+ }
693
+ };
694
+ this.messagingSystem.subscribe('NetworkController:networkDidChange', listener);
695
+ let updatedNetworkStatus;
696
+ let updatedIsEIP1559Compatible;
697
+ try {
698
+ const isEIP1559Compatible = await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_determineEIP1559Compatibility).call(this, this.state.selectedNetworkClientId);
699
+ updatedNetworkStatus = constants_1.NetworkStatus.Available;
700
+ updatedIsEIP1559Compatible = isEIP1559Compatible;
701
+ }
702
+ catch (error) {
703
+ // TODO: mock ethQuery.sendAsync to throw error without error code
704
+ /* istanbul ignore else */
705
+ if (isErrorWithCode(error)) {
706
+ let responseBody;
707
+ if (isInfura &&
708
+ (0, utils_1.hasProperty)(error, 'message') &&
709
+ typeof error.message === 'string') {
710
+ try {
711
+ responseBody = JSON.parse(error.message);
712
+ }
713
+ catch (parseError) {
714
+ // error.message must not be JSON
715
+ __classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: json parse error', parseError);
716
+ }
717
+ }
718
+ if ((0, utils_1.isPlainObject)(responseBody) &&
719
+ responseBody.error === constants_1.INFURA_BLOCKED_KEY) {
720
+ updatedNetworkStatus = constants_1.NetworkStatus.Blocked;
721
+ }
722
+ else if (error.code === rpc_errors_1.errorCodes.rpc.internal) {
723
+ updatedNetworkStatus = constants_1.NetworkStatus.Unknown;
724
+ __classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: rpc internal error', error);
725
+ }
726
+ else {
727
+ updatedNetworkStatus = constants_1.NetworkStatus.Unavailable;
728
+ __classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: ', error);
729
+ }
730
+ }
731
+ else {
732
+ debugLog('NetworkController - could not determine network status', error);
733
+ updatedNetworkStatus = constants_1.NetworkStatus.Unknown;
734
+ __classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: ', error);
735
+ }
736
+ }
737
+ if (networkChanged) {
738
+ // If the network has changed, then `lookupNetwork` either has been or is
739
+ // in the process of being called, so we don't need to go further.
740
+ return;
741
+ }
742
+ try {
743
+ this.messagingSystem.unsubscribe('NetworkController:networkDidChange', listener);
744
+ }
745
+ catch (error) {
746
+ if (!(error instanceof Error) ||
747
+ error.message !==
748
+ 'Subscription not found for event: NetworkController:networkDidChange') {
749
+ throw error;
750
+ }
751
+ }
752
+ this.update((state) => {
753
+ const meta = state.networksMetadata[state.selectedNetworkClientId];
754
+ meta.status = updatedNetworkStatus;
755
+ if (updatedIsEIP1559Compatible === undefined) {
756
+ delete meta.EIPS[1559];
757
+ }
758
+ else {
759
+ meta.EIPS[1559] = updatedIsEIP1559Compatible;
760
+ }
761
+ });
762
+ if (isInfura) {
763
+ if (updatedNetworkStatus === constants_1.NetworkStatus.Available) {
764
+ this.messagingSystem.publish('NetworkController:infuraIsUnblocked');
765
+ }
766
+ else if (updatedNetworkStatus === constants_1.NetworkStatus.Blocked) {
767
+ this.messagingSystem.publish('NetworkController:infuraIsBlocked');
768
+ }
769
+ }
770
+ else {
771
+ // Always publish infuraIsUnblocked regardless of network status to
772
+ // prevent consumers from being stuck in a blocked state if they were
773
+ // previously connected to an Infura network that was blocked
774
+ this.messagingSystem.publish('NetworkController:infuraIsUnblocked');
775
+ }
615
776
  }
616
777
  /**
617
778
  * Convenience method to update provider network type settings.
@@ -1107,174 +1268,6 @@ async function _NetworkController_refreshNetwork(networkClientId, options = {})
1107
1268
  __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_applyNetworkSelection).call(this, networkClientId, options);
1108
1269
  this.messagingSystem.publish('NetworkController:networkDidChange', this.state);
1109
1270
  await this.lookupNetwork();
1110
- }, _NetworkController_determineNetworkMetadata =
1111
- /**
1112
- * Uses a request for the latest block to gather the following information on
1113
- * the given network:
1114
- *
1115
- * - The connectivity status: whether it is available, geo-blocked (Infura
1116
- * only), unavailable, or unknown
1117
- * - The capabilities status: whether it supports EIP-1559, whether it does
1118
- * not, or whether it is unknown
1119
- *
1120
- * @param networkClientId - The ID of the network client to inspect.
1121
- * If no ID is provided, uses the currently selected network.
1122
- * @returns The resulting metadata for the network.
1123
- */
1124
- async function _NetworkController_determineNetworkMetadata(networkClientId) {
1125
- // Force TypeScript to use one of the two overloads explicitly
1126
- const networkClient = (0, controller_utils_1.isInfuraNetworkType)(networkClientId)
1127
- ? this.getNetworkClientById(networkClientId)
1128
- : this.getNetworkClientById(networkClientId);
1129
- const isInfura = networkClient.configuration.type === types_1.NetworkClientType.Infura;
1130
- let networkStatus;
1131
- let isEIP1559Compatible;
1132
- try {
1133
- isEIP1559Compatible =
1134
- await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_determineEIP1559Compatibility).call(this, networkClientId);
1135
- networkStatus = constants_1.NetworkStatus.Available;
1136
- }
1137
- catch (error) {
1138
- debugLog('NetworkController: lookupNetwork: ', error);
1139
- if (isErrorWithCode(error)) {
1140
- let responseBody;
1141
- if (isInfura &&
1142
- (0, utils_1.hasProperty)(error, 'message') &&
1143
- typeof error.message === 'string') {
1144
- try {
1145
- responseBody = JSON.parse(error.message);
1146
- }
1147
- catch {
1148
- // error.message must not be JSON
1149
- __classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: json parse error: ', error);
1150
- }
1151
- }
1152
- if ((0, utils_1.isPlainObject)(responseBody) &&
1153
- responseBody.error === constants_1.INFURA_BLOCKED_KEY) {
1154
- networkStatus = constants_1.NetworkStatus.Blocked;
1155
- }
1156
- else if (error.code === rpc_errors_1.errorCodes.rpc.internal) {
1157
- networkStatus = constants_1.NetworkStatus.Unknown;
1158
- __classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: rpc internal error: ', error);
1159
- }
1160
- else {
1161
- networkStatus = constants_1.NetworkStatus.Unavailable;
1162
- __classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: ', error);
1163
- }
1164
- }
1165
- else {
1166
- debugLog('NetworkController - could not determine network status', error);
1167
- networkStatus = constants_1.NetworkStatus.Unknown;
1168
- __classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: ', error);
1169
- }
1170
- }
1171
- return { isInfura, networkStatus, isEIP1559Compatible };
1172
- }, _NetworkController_lookupGivenNetwork =
1173
- /**
1174
- * Uses a request for the latest block to gather the following information on
1175
- * the given network, persisting it to state:
1176
- *
1177
- * - The connectivity status: whether the network is available, geo-blocked
1178
- * (Infura only), unavailable, or unknown
1179
- * - The feature compatibility status: whether the network supports EIP-1559,
1180
- * whether it does not, or whether it is unknown
1181
- *
1182
- * @param networkClientId - The ID of the network client to inspect.
1183
- */
1184
- async function _NetworkController_lookupGivenNetwork(networkClientId) {
1185
- const { networkStatus, isEIP1559Compatible } = await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_determineNetworkMetadata).call(this, networkClientId);
1186
- __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_updateMetadataForNetwork).call(this, networkClientId, networkStatus, isEIP1559Compatible);
1187
- }, _NetworkController_lookupSelectedNetwork =
1188
- /**
1189
- * Uses a request for the latest block to gather the following information on
1190
- * the currently selected network, persisting it to state:
1191
- *
1192
- * - The connectivity status: whether the network is available, geo-blocked
1193
- * (Infura only), unavailable, or unknown
1194
- * - The feature compatibility status: whether the network supports EIP-1559,
1195
- * whether it does not, or whether it is unknown
1196
- *
1197
- * Note that it is possible for the current network to be switched while this
1198
- * method is running. If that is the case, it will exit early (as this method
1199
- * will also run for the new network).
1200
- */
1201
- async function _NetworkController_lookupSelectedNetwork() {
1202
- if (!__classPrivateFieldGet(this, _NetworkController_ethQuery, "f")) {
1203
- return;
1204
- }
1205
- let networkChanged = false;
1206
- const listener = () => {
1207
- networkChanged = true;
1208
- try {
1209
- this.messagingSystem.unsubscribe('NetworkController:networkDidChange', listener);
1210
- }
1211
- catch (error) {
1212
- // In theory, this `catch` should not be necessary given that this error
1213
- // would occur "inside" of the call to `#determineEIP1559Compatibility`
1214
- // below and so it should be caught by the `try`/`catch` below (it is
1215
- // impossible to reproduce in tests for that reason). However, somehow
1216
- // it occurs within Mobile and so we have to add our own `try`/`catch`
1217
- // here.
1218
- /* istanbul ignore next */
1219
- if (!(error instanceof Error) ||
1220
- error.message !==
1221
- 'Subscription not found for event: NetworkController:networkDidChange') {
1222
- // Again, this error should not happen and is impossible to reproduce
1223
- // in tests.
1224
- /* istanbul ignore next */
1225
- throw error;
1226
- }
1227
- }
1228
- };
1229
- this.messagingSystem.subscribe('NetworkController:networkDidChange', listener);
1230
- const { isInfura, networkStatus, isEIP1559Compatible } = await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_determineNetworkMetadata).call(this, this.state.selectedNetworkClientId);
1231
- if (networkChanged) {
1232
- // If the network has changed, then `lookupNetwork` either has been or is
1233
- // in the process of being called, so we don't need to go further.
1234
- return;
1235
- }
1236
- try {
1237
- this.messagingSystem.unsubscribe('NetworkController:networkDidChange', listener);
1238
- }
1239
- catch (error) {
1240
- if (!(error instanceof Error) ||
1241
- error.message !==
1242
- 'Subscription not found for event: NetworkController:networkDidChange') {
1243
- throw error;
1244
- }
1245
- }
1246
- __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_updateMetadataForNetwork).call(this, this.state.selectedNetworkClientId, networkStatus, isEIP1559Compatible);
1247
- if (isInfura) {
1248
- if (networkStatus === constants_1.NetworkStatus.Available) {
1249
- this.messagingSystem.publish('NetworkController:infuraIsUnblocked');
1250
- }
1251
- else if (networkStatus === constants_1.NetworkStatus.Blocked) {
1252
- this.messagingSystem.publish('NetworkController:infuraIsBlocked');
1253
- }
1254
- }
1255
- else {
1256
- // Always publish infuraIsUnblocked regardless of network status to
1257
- // prevent consumers from being stuck in a blocked state if they were
1258
- // previously connected to an Infura network that was blocked
1259
- this.messagingSystem.publish('NetworkController:infuraIsUnblocked');
1260
- }
1261
- }, _NetworkController_updateMetadataForNetwork = function _NetworkController_updateMetadataForNetwork(networkClientId, networkStatus, isEIP1559Compatible) {
1262
- this.update((state) => {
1263
- if (state.networksMetadata[networkClientId] === undefined) {
1264
- state.networksMetadata[networkClientId] = {
1265
- status: constants_1.NetworkStatus.Unknown,
1266
- EIPS: {},
1267
- };
1268
- }
1269
- const meta = state.networksMetadata[networkClientId];
1270
- meta.status = networkStatus;
1271
- if (isEIP1559Compatible === undefined) {
1272
- delete meta.EIPS[1559];
1273
- }
1274
- else {
1275
- meta.EIPS[1559] = isEIP1559Compatible;
1276
- }
1277
- });
1278
1271
  }, _NetworkController_getLatestBlock = function _NetworkController_getLatestBlock(networkClientId) {
1279
1272
  if (networkClientId === undefined) {
1280
1273
  networkClientId = this.state.selectedNetworkClientId;
@@ -1473,7 +1466,6 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
1473
1466
  getBlockTrackerOptions: __classPrivateFieldGet(this, _NetworkController_getBlockTrackerOptions, "f"),
1474
1467
  messenger: this.messagingSystem,
1475
1468
  isRpcFailoverEnabled: __classPrivateFieldGet(this, _NetworkController_isRpcFailoverEnabled, "f"),
1476
- logger: __classPrivateFieldGet(this, _NetworkController_log, "f"),
1477
1469
  });
1478
1470
  }
1479
1471
  else {
@@ -1489,7 +1481,6 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
1489
1481
  getBlockTrackerOptions: __classPrivateFieldGet(this, _NetworkController_getBlockTrackerOptions, "f"),
1490
1482
  messenger: this.messagingSystem,
1491
1483
  isRpcFailoverEnabled: __classPrivateFieldGet(this, _NetworkController_isRpcFailoverEnabled, "f"),
1492
- logger: __classPrivateFieldGet(this, _NetworkController_log, "f"),
1493
1484
  });
1494
1485
  }
1495
1486
  }
@@ -1549,7 +1540,6 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
1549
1540
  getBlockTrackerOptions: __classPrivateFieldGet(this, _NetworkController_getBlockTrackerOptions, "f"),
1550
1541
  messenger: this.messagingSystem,
1551
1542
  isRpcFailoverEnabled: __classPrivateFieldGet(this, _NetworkController_isRpcFailoverEnabled, "f"),
1552
- logger: __classPrivateFieldGet(this, _NetworkController_log, "f"),
1553
1543
  }),
1554
1544
  ];
1555
1545
  }
@@ -1567,7 +1557,6 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
1567
1557
  getBlockTrackerOptions: __classPrivateFieldGet(this, _NetworkController_getBlockTrackerOptions, "f"),
1568
1558
  messenger: this.messagingSystem,
1569
1559
  isRpcFailoverEnabled: __classPrivateFieldGet(this, _NetworkController_isRpcFailoverEnabled, "f"),
1570
- logger: __classPrivateFieldGet(this, _NetworkController_log, "f"),
1571
1560
  }),
1572
1561
  ];
1573
1562
  });