@metamask/network-controller 24.1.0 → 24.2.1

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 +40 -1
  2. package/dist/NetworkController.cjs +211 -202
  3. package/dist/NetworkController.cjs.map +1 -1
  4. package/dist/NetworkController.d.cts +62 -21
  5. package/dist/NetworkController.d.cts.map +1 -1
  6. package/dist/NetworkController.d.mts +62 -21
  7. package/dist/NetworkController.d.mts.map +1 -1
  8. package/dist/NetworkController.mjs +211 -202
  9. package/dist/NetworkController.mjs.map +1 -1
  10. package/dist/create-auto-managed-network-client.cjs +3 -1
  11. package/dist/create-auto-managed-network-client.cjs.map +1 -1
  12. package/dist/create-auto-managed-network-client.d.cts +4 -1
  13. package/dist/create-auto-managed-network-client.d.cts.map +1 -1
  14. package/dist/create-auto-managed-network-client.d.mts +4 -1
  15. package/dist/create-auto-managed-network-client.d.mts.map +1 -1
  16. package/dist/create-auto-managed-network-client.mjs +3 -1
  17. package/dist/create-auto-managed-network-client.mjs.map +1 -1
  18. package/dist/create-network-client.cjs +3 -1
  19. package/dist/create-network-client.cjs.map +1 -1
  20. package/dist/create-network-client.d.cts +4 -1
  21. package/dist/create-network-client.d.cts.map +1 -1
  22. package/dist/create-network-client.d.mts +4 -1
  23. package/dist/create-network-client.d.mts.map +1 -1
  24. package/dist/create-network-client.mjs +3 -1
  25. package/dist/create-network-client.mjs.map +1 -1
  26. package/dist/rpc-service/rpc-service.cjs +17 -3
  27. package/dist/rpc-service/rpc-service.cjs.map +1 -1
  28. package/dist/rpc-service/rpc-service.d.cts +5 -0
  29. package/dist/rpc-service/rpc-service.d.cts.map +1 -1
  30. package/dist/rpc-service/rpc-service.d.mts +5 -0
  31. package/dist/rpc-service/rpc-service.d.mts.map +1 -1
  32. package/dist/rpc-service/rpc-service.mjs +19 -5
  33. package/dist/rpc-service/rpc-service.mjs.map +1 -1
  34. package/package.json +8 -8
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- 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;
12
+ 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;
13
13
  function $importDefault(module) {
14
14
  if (module?.__esModule) {
15
15
  return module.default;
@@ -362,16 +362,22 @@ export class NetworkController extends BaseController {
362
362
  name: controllerName,
363
363
  metadata: {
364
364
  selectedNetworkClientId: {
365
+ includeInStateLogs: true,
365
366
  persist: true,
366
367
  anonymous: false,
368
+ usedInUi: true,
367
369
  },
368
370
  networksMetadata: {
371
+ includeInStateLogs: true,
369
372
  persist: true,
370
373
  anonymous: false,
374
+ usedInUi: true,
371
375
  },
372
376
  networkConfigurationsByChainId: {
377
+ includeInStateLogs: true,
373
378
  persist: true,
374
379
  anonymous: false,
380
+ usedInUi: true,
375
381
  },
376
382
  },
377
383
  messenger,
@@ -535,221 +541,52 @@ export class NetworkController extends BaseController {
535
541
  }
536
542
  return customNetworkClient;
537
543
  }
538
- /**
539
- * Ensures that network clients for Infura and custom RPC endpoints have been
540
- * created. Then, consulting state, initializes and establishes the currently
541
- * selected network client.
542
- */
543
- async initializeProvider() {
544
+ initializeProvider({ lookupNetwork = true, } = {}) {
544
545
  __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_applyNetworkSelection).call(this, this.state.selectedNetworkClientId);
545
- await this.lookupNetwork();
546
- }
547
- /**
548
- * Refreshes the network meta with EIP-1559 support and the network status
549
- * based on the given network client ID.
550
- *
551
- * @param networkClientId - The ID of the network client to update.
552
- */
553
- async lookupNetworkByClientId(networkClientId) {
554
- const isInfura = isInfuraNetworkType(networkClientId);
555
- let updatedNetworkStatus;
556
- let updatedIsEIP1559Compatible;
557
- try {
558
- updatedIsEIP1559Compatible =
559
- await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_determineEIP1559Compatibility).call(this, networkClientId);
560
- updatedNetworkStatus = NetworkStatus.Available;
546
+ if (lookupNetwork) {
547
+ return this.lookupNetwork();
561
548
  }
562
- catch (error) {
563
- debugLog('NetworkController: lookupNetworkByClientId: ', error);
564
- // TODO: mock ethQuery.sendAsync to throw error without error code
565
- /* istanbul ignore else */
566
- if (isErrorWithCode(error)) {
567
- let responseBody;
568
- if (isInfura &&
569
- hasProperty(error, 'message') &&
570
- typeof error.message === 'string') {
571
- try {
572
- responseBody = JSON.parse(error.message);
573
- }
574
- catch {
575
- // error.message must not be JSON
576
- __classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetworkByClientId: json parse error: ', error);
577
- }
578
- }
579
- if (isPlainObject(responseBody) &&
580
- responseBody.error === INFURA_BLOCKED_KEY) {
581
- updatedNetworkStatus = NetworkStatus.Blocked;
582
- }
583
- else if (error.code === errorCodes.rpc.internal) {
584
- updatedNetworkStatus = NetworkStatus.Unknown;
585
- __classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetworkByClientId: rpc internal error: ', error);
586
- }
587
- else {
588
- updatedNetworkStatus = NetworkStatus.Unavailable;
589
- __classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetworkByClientId: ', error);
590
- }
591
- }
592
- else if (typeof Error !== 'undefined' &&
593
- hasProperty(error, 'message') &&
594
- typeof error.message === 'string' &&
595
- error.message.includes('No custom network client was found with the ID')) {
596
- throw error;
597
- }
598
- else {
599
- debugLog('NetworkController - could not determine network status', error);
600
- updatedNetworkStatus = NetworkStatus.Unknown;
601
- __classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetworkByClientId: ', error);
602
- }
603
- }
604
- this.update((state) => {
605
- if (state.networksMetadata[networkClientId] === undefined) {
606
- state.networksMetadata[networkClientId] = {
607
- status: NetworkStatus.Unknown,
608
- EIPS: {},
609
- };
610
- }
611
- const meta = state.networksMetadata[networkClientId];
612
- meta.status = updatedNetworkStatus;
613
- if (updatedIsEIP1559Compatible === undefined) {
614
- delete meta.EIPS[1559];
615
- }
616
- else {
617
- meta.EIPS[1559] = updatedIsEIP1559Compatible;
618
- }
619
- });
549
+ return undefined;
620
550
  }
621
551
  /**
622
- * Persists the following metadata about the given or selected network to
623
- * state:
552
+ * Uses a request for the latest block to gather the following information on
553
+ * the given or selected network, persisting it to state:
624
554
  *
625
- * - The status of the network, namely, whether it is available, geo-blocked
626
- * (Infura only), or unavailable, or whether the status is unknown
627
- * - Whether the network supports EIP-1559, or whether it is unknown
555
+ * - The connectivity status: whether it is available, geo-blocked (Infura
556
+ * only), unavailable, or unknown
557
+ * - The capabilities status: whether it supports EIP-1559, whether it does
558
+ * not, or whether it is unknown
628
559
  *
629
- * Note that it is possible for the network to be switched while this data is
630
- * being collected. If that is the case, no metadata for the (now previously)
631
- * selected network will be updated.
632
- *
633
- * @param networkClientId - The ID of the network client to update.
560
+ * @param networkClientId - The ID of the network client to inspect.
634
561
  * If no ID is provided, uses the currently selected network.
635
562
  */
636
563
  async lookupNetwork(networkClientId) {
637
564
  if (networkClientId) {
638
- await this.lookupNetworkByClientId(networkClientId);
639
- return;
640
- }
641
- if (!__classPrivateFieldGet(this, _NetworkController_ethQuery, "f")) {
642
- return;
643
- }
644
- const isInfura = __classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClient, "f")?.configuration.type ===
645
- NetworkClientType.Infura;
646
- let networkChanged = false;
647
- const listener = () => {
648
- networkChanged = true;
649
- try {
650
- this.messagingSystem.unsubscribe('NetworkController:networkDidChange', listener);
651
- }
652
- catch (error) {
653
- // In theory, this `catch` should not be necessary given that this error
654
- // would occur "inside" of the call to `#determineEIP1559Compatibility`
655
- // below and so it should be caught by the `try`/`catch` below (it is
656
- // impossible to reproduce in tests for that reason). However, somehow
657
- // it occurs within Mobile and so we have to add our own `try`/`catch`
658
- // here.
659
- /* istanbul ignore next */
660
- if (!(error instanceof Error) ||
661
- error.message !==
662
- 'Subscription not found for event: NetworkController:networkDidChange') {
663
- // Again, this error should not happen and is impossible to reproduce
664
- // in tests.
665
- /* istanbul ignore next */
666
- throw error;
667
- }
668
- }
669
- };
670
- this.messagingSystem.subscribe('NetworkController:networkDidChange', listener);
671
- let updatedNetworkStatus;
672
- let updatedIsEIP1559Compatible;
673
- try {
674
- const isEIP1559Compatible = await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_determineEIP1559Compatibility).call(this, this.state.selectedNetworkClientId);
675
- updatedNetworkStatus = NetworkStatus.Available;
676
- updatedIsEIP1559Compatible = isEIP1559Compatible;
677
- }
678
- catch (error) {
679
- // TODO: mock ethQuery.sendAsync to throw error without error code
680
- /* istanbul ignore else */
681
- if (isErrorWithCode(error)) {
682
- let responseBody;
683
- if (isInfura &&
684
- hasProperty(error, 'message') &&
685
- typeof error.message === 'string') {
686
- try {
687
- responseBody = JSON.parse(error.message);
688
- }
689
- catch (parseError) {
690
- // error.message must not be JSON
691
- __classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: json parse error', parseError);
692
- }
693
- }
694
- if (isPlainObject(responseBody) &&
695
- responseBody.error === INFURA_BLOCKED_KEY) {
696
- updatedNetworkStatus = NetworkStatus.Blocked;
697
- }
698
- else if (error.code === errorCodes.rpc.internal) {
699
- updatedNetworkStatus = NetworkStatus.Unknown;
700
- __classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: rpc internal error', error);
701
- }
702
- else {
703
- updatedNetworkStatus = NetworkStatus.Unavailable;
704
- __classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: ', error);
705
- }
706
- }
707
- else {
708
- debugLog('NetworkController - could not determine network status', error);
709
- updatedNetworkStatus = NetworkStatus.Unknown;
710
- __classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: ', error);
711
- }
712
- }
713
- if (networkChanged) {
714
- // If the network has changed, then `lookupNetwork` either has been or is
715
- // in the process of being called, so we don't need to go further.
716
- return;
717
- }
718
- try {
719
- this.messagingSystem.unsubscribe('NetworkController:networkDidChange', listener);
720
- }
721
- catch (error) {
722
- if (!(error instanceof Error) ||
723
- error.message !==
724
- 'Subscription not found for event: NetworkController:networkDidChange') {
725
- throw error;
726
- }
727
- }
728
- this.update((state) => {
729
- const meta = state.networksMetadata[state.selectedNetworkClientId];
730
- meta.status = updatedNetworkStatus;
731
- if (updatedIsEIP1559Compatible === undefined) {
732
- delete meta.EIPS[1559];
733
- }
734
- else {
735
- meta.EIPS[1559] = updatedIsEIP1559Compatible;
736
- }
737
- });
738
- if (isInfura) {
739
- if (updatedNetworkStatus === NetworkStatus.Available) {
740
- this.messagingSystem.publish('NetworkController:infuraIsUnblocked');
741
- }
742
- else if (updatedNetworkStatus === NetworkStatus.Blocked) {
743
- this.messagingSystem.publish('NetworkController:infuraIsBlocked');
744
- }
565
+ await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_lookupGivenNetwork).call(this, networkClientId);
745
566
  }
746
567
  else {
747
- // Always publish infuraIsUnblocked regardless of network status to
748
- // prevent consumers from being stuck in a blocked state if they were
749
- // previously connected to an Infura network that was blocked
750
- this.messagingSystem.publish('NetworkController:infuraIsUnblocked');
568
+ await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_lookupSelectedNetwork).call(this);
751
569
  }
752
570
  }
571
+ /**
572
+ * Uses a request for the latest block to gather the following information on
573
+ * the given network, persisting it to state:
574
+ *
575
+ * - The connectivity status: whether the network is available, geo-blocked
576
+ * (Infura only), unavailable, or unknown
577
+ * - The feature compatibility status: whether the network supports EIP-1559,
578
+ * whether it does not, or whether it is unknown
579
+ *
580
+ * @param networkClientId - The ID of the network client to inspect.
581
+ * @deprecated Please use `lookupNetwork` and pass a network client ID
582
+ * instead. This method will be removed in a future major version.
583
+ */
584
+ // We are planning on removing this so we aren't interested in testing this
585
+ // right now.
586
+ /* istanbul ignore next */
587
+ async lookupNetworkByClientId(networkClientId) {
588
+ await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_lookupGivenNetwork).call(this, networkClientId);
589
+ }
753
590
  /**
754
591
  * Convenience method to update provider network type settings.
755
592
  *
@@ -1243,6 +1080,174 @@ async function _NetworkController_refreshNetwork(networkClientId, options = {})
1243
1080
  __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_applyNetworkSelection).call(this, networkClientId, options);
1244
1081
  this.messagingSystem.publish('NetworkController:networkDidChange', this.state);
1245
1082
  await this.lookupNetwork();
1083
+ }, _NetworkController_determineNetworkMetadata =
1084
+ /**
1085
+ * Uses a request for the latest block to gather the following information on
1086
+ * the given network:
1087
+ *
1088
+ * - The connectivity status: whether it is available, geo-blocked (Infura
1089
+ * only), unavailable, or unknown
1090
+ * - The capabilities status: whether it supports EIP-1559, whether it does
1091
+ * not, or whether it is unknown
1092
+ *
1093
+ * @param networkClientId - The ID of the network client to inspect.
1094
+ * If no ID is provided, uses the currently selected network.
1095
+ * @returns The resulting metadata for the network.
1096
+ */
1097
+ async function _NetworkController_determineNetworkMetadata(networkClientId) {
1098
+ // Force TypeScript to use one of the two overloads explicitly
1099
+ const networkClient = isInfuraNetworkType(networkClientId)
1100
+ ? this.getNetworkClientById(networkClientId)
1101
+ : this.getNetworkClientById(networkClientId);
1102
+ const isInfura = networkClient.configuration.type === NetworkClientType.Infura;
1103
+ let networkStatus;
1104
+ let isEIP1559Compatible;
1105
+ try {
1106
+ isEIP1559Compatible =
1107
+ await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_determineEIP1559Compatibility).call(this, networkClientId);
1108
+ networkStatus = NetworkStatus.Available;
1109
+ }
1110
+ catch (error) {
1111
+ debugLog('NetworkController: lookupNetwork: ', error);
1112
+ if (isErrorWithCode(error)) {
1113
+ let responseBody;
1114
+ if (isInfura &&
1115
+ hasProperty(error, 'message') &&
1116
+ typeof error.message === 'string') {
1117
+ try {
1118
+ responseBody = JSON.parse(error.message);
1119
+ }
1120
+ catch {
1121
+ // error.message must not be JSON
1122
+ __classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: json parse error: ', error);
1123
+ }
1124
+ }
1125
+ if (isPlainObject(responseBody) &&
1126
+ responseBody.error === INFURA_BLOCKED_KEY) {
1127
+ networkStatus = NetworkStatus.Blocked;
1128
+ }
1129
+ else if (error.code === errorCodes.rpc.internal) {
1130
+ networkStatus = NetworkStatus.Unknown;
1131
+ __classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: rpc internal error: ', error);
1132
+ }
1133
+ else {
1134
+ networkStatus = NetworkStatus.Unavailable;
1135
+ __classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: ', error);
1136
+ }
1137
+ }
1138
+ else {
1139
+ debugLog('NetworkController - could not determine network status', error);
1140
+ networkStatus = NetworkStatus.Unknown;
1141
+ __classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: ', error);
1142
+ }
1143
+ }
1144
+ return { isInfura, networkStatus, isEIP1559Compatible };
1145
+ }, _NetworkController_lookupGivenNetwork =
1146
+ /**
1147
+ * Uses a request for the latest block to gather the following information on
1148
+ * the given network, persisting it to state:
1149
+ *
1150
+ * - The connectivity status: whether the network is available, geo-blocked
1151
+ * (Infura only), unavailable, or unknown
1152
+ * - The feature compatibility status: whether the network supports EIP-1559,
1153
+ * whether it does not, or whether it is unknown
1154
+ *
1155
+ * @param networkClientId - The ID of the network client to inspect.
1156
+ */
1157
+ async function _NetworkController_lookupGivenNetwork(networkClientId) {
1158
+ const { networkStatus, isEIP1559Compatible } = await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_determineNetworkMetadata).call(this, networkClientId);
1159
+ __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_updateMetadataForNetwork).call(this, networkClientId, networkStatus, isEIP1559Compatible);
1160
+ }, _NetworkController_lookupSelectedNetwork =
1161
+ /**
1162
+ * Uses a request for the latest block to gather the following information on
1163
+ * the currently selected network, persisting it to state:
1164
+ *
1165
+ * - The connectivity status: whether the network is available, geo-blocked
1166
+ * (Infura only), unavailable, or unknown
1167
+ * - The feature compatibility status: whether the network supports EIP-1559,
1168
+ * whether it does not, or whether it is unknown
1169
+ *
1170
+ * Note that it is possible for the current network to be switched while this
1171
+ * method is running. If that is the case, it will exit early (as this method
1172
+ * will also run for the new network).
1173
+ */
1174
+ async function _NetworkController_lookupSelectedNetwork() {
1175
+ if (!__classPrivateFieldGet(this, _NetworkController_ethQuery, "f")) {
1176
+ return;
1177
+ }
1178
+ let networkChanged = false;
1179
+ const listener = () => {
1180
+ networkChanged = true;
1181
+ try {
1182
+ this.messagingSystem.unsubscribe('NetworkController:networkDidChange', listener);
1183
+ }
1184
+ catch (error) {
1185
+ // In theory, this `catch` should not be necessary given that this error
1186
+ // would occur "inside" of the call to `#determineEIP1559Compatibility`
1187
+ // below and so it should be caught by the `try`/`catch` below (it is
1188
+ // impossible to reproduce in tests for that reason). However, somehow
1189
+ // it occurs within Mobile and so we have to add our own `try`/`catch`
1190
+ // here.
1191
+ /* istanbul ignore next */
1192
+ if (!(error instanceof Error) ||
1193
+ error.message !==
1194
+ 'Subscription not found for event: NetworkController:networkDidChange') {
1195
+ // Again, this error should not happen and is impossible to reproduce
1196
+ // in tests.
1197
+ /* istanbul ignore next */
1198
+ throw error;
1199
+ }
1200
+ }
1201
+ };
1202
+ this.messagingSystem.subscribe('NetworkController:networkDidChange', listener);
1203
+ const { isInfura, networkStatus, isEIP1559Compatible } = await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_determineNetworkMetadata).call(this, this.state.selectedNetworkClientId);
1204
+ if (networkChanged) {
1205
+ // If the network has changed, then `lookupNetwork` either has been or is
1206
+ // in the process of being called, so we don't need to go further.
1207
+ return;
1208
+ }
1209
+ try {
1210
+ this.messagingSystem.unsubscribe('NetworkController:networkDidChange', listener);
1211
+ }
1212
+ catch (error) {
1213
+ if (!(error instanceof Error) ||
1214
+ error.message !==
1215
+ 'Subscription not found for event: NetworkController:networkDidChange') {
1216
+ throw error;
1217
+ }
1218
+ }
1219
+ __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_updateMetadataForNetwork).call(this, this.state.selectedNetworkClientId, networkStatus, isEIP1559Compatible);
1220
+ if (isInfura) {
1221
+ if (networkStatus === NetworkStatus.Available) {
1222
+ this.messagingSystem.publish('NetworkController:infuraIsUnblocked');
1223
+ }
1224
+ else if (networkStatus === NetworkStatus.Blocked) {
1225
+ this.messagingSystem.publish('NetworkController:infuraIsBlocked');
1226
+ }
1227
+ }
1228
+ else {
1229
+ // Always publish infuraIsUnblocked regardless of network status to
1230
+ // prevent consumers from being stuck in a blocked state if they were
1231
+ // previously connected to an Infura network that was blocked
1232
+ this.messagingSystem.publish('NetworkController:infuraIsUnblocked');
1233
+ }
1234
+ }, _NetworkController_updateMetadataForNetwork = function _NetworkController_updateMetadataForNetwork(networkClientId, networkStatus, isEIP1559Compatible) {
1235
+ this.update((state) => {
1236
+ if (state.networksMetadata[networkClientId] === undefined) {
1237
+ state.networksMetadata[networkClientId] = {
1238
+ status: NetworkStatus.Unknown,
1239
+ EIPS: {},
1240
+ };
1241
+ }
1242
+ const meta = state.networksMetadata[networkClientId];
1243
+ meta.status = networkStatus;
1244
+ if (isEIP1559Compatible === undefined) {
1245
+ delete meta.EIPS[1559];
1246
+ }
1247
+ else {
1248
+ meta.EIPS[1559] = isEIP1559Compatible;
1249
+ }
1250
+ });
1246
1251
  }, _NetworkController_getLatestBlock = function _NetworkController_getLatestBlock(networkClientId) {
1247
1252
  if (networkClientId === undefined) {
1248
1253
  networkClientId = this.state.selectedNetworkClientId;
@@ -1441,6 +1446,7 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
1441
1446
  getBlockTrackerOptions: __classPrivateFieldGet(this, _NetworkController_getBlockTrackerOptions, "f"),
1442
1447
  messenger: this.messagingSystem,
1443
1448
  isRpcFailoverEnabled: __classPrivateFieldGet(this, _NetworkController_isRpcFailoverEnabled, "f"),
1449
+ logger: __classPrivateFieldGet(this, _NetworkController_log, "f"),
1444
1450
  });
1445
1451
  }
1446
1452
  else {
@@ -1456,6 +1462,7 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
1456
1462
  getBlockTrackerOptions: __classPrivateFieldGet(this, _NetworkController_getBlockTrackerOptions, "f"),
1457
1463
  messenger: this.messagingSystem,
1458
1464
  isRpcFailoverEnabled: __classPrivateFieldGet(this, _NetworkController_isRpcFailoverEnabled, "f"),
1465
+ logger: __classPrivateFieldGet(this, _NetworkController_log, "f"),
1459
1466
  });
1460
1467
  }
1461
1468
  }
@@ -1515,6 +1522,7 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
1515
1522
  getBlockTrackerOptions: __classPrivateFieldGet(this, _NetworkController_getBlockTrackerOptions, "f"),
1516
1523
  messenger: this.messagingSystem,
1517
1524
  isRpcFailoverEnabled: __classPrivateFieldGet(this, _NetworkController_isRpcFailoverEnabled, "f"),
1525
+ logger: __classPrivateFieldGet(this, _NetworkController_log, "f"),
1518
1526
  }),
1519
1527
  ];
1520
1528
  }
@@ -1532,6 +1540,7 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
1532
1540
  getBlockTrackerOptions: __classPrivateFieldGet(this, _NetworkController_getBlockTrackerOptions, "f"),
1533
1541
  messenger: this.messagingSystem,
1534
1542
  isRpcFailoverEnabled: __classPrivateFieldGet(this, _NetworkController_isRpcFailoverEnabled, "f"),
1543
+ logger: __classPrivateFieldGet(this, _NetworkController_log, "f"),
1535
1544
  }),
1536
1545
  ];
1537
1546
  });