@metamask-previews/network-controller 24.1.0-preview-aa8c4291 → 24.1.0-preview-8facad04
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 +5 -0
- package/dist/NetworkController.cjs +197 -196
- package/dist/NetworkController.cjs.map +1 -1
- package/dist/NetworkController.d.cts +20 -16
- package/dist/NetworkController.d.cts.map +1 -1
- package/dist/NetworkController.d.mts +20 -16
- package/dist/NetworkController.d.mts.map +1 -1
- package/dist/NetworkController.mjs +197 -196
- package/dist/NetworkController.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
11
11
|
|
|
12
12
|
- Bump `@metamask/base-controller` from `^8.1.0` to `^8.2.0` ([#6355](https://github.com/MetaMask/core/pull/6355))
|
|
13
13
|
|
|
14
|
+
### Deprecated
|
|
15
|
+
|
|
16
|
+
- Deprecate `lookupNetworkByClientId` ([#6308](https://github.com/MetaMask/core/pull/6308))
|
|
17
|
+
- `lookupNetwork` already supports passing in a network client ID; please use this going forward instead.
|
|
18
|
+
|
|
14
19
|
## [24.1.0]
|
|
15
20
|
|
|
16
21
|
### Added
|
|
@@ -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_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_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;
|
|
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");
|
|
@@ -569,211 +569,44 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
569
569
|
await this.lookupNetwork();
|
|
570
570
|
}
|
|
571
571
|
/**
|
|
572
|
-
*
|
|
573
|
-
*
|
|
572
|
+
* Uses a request for the latest block to gather the following information on
|
|
573
|
+
* the given or selected network, persisting it to state:
|
|
574
574
|
*
|
|
575
|
-
*
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
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;
|
|
585
|
-
}
|
|
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
|
-
}
|
|
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
|
-
});
|
|
644
|
-
}
|
|
645
|
-
/**
|
|
646
|
-
* Persists the following metadata about the given or selected network to
|
|
647
|
-
* state:
|
|
575
|
+
* - The connectivity status: whether it is available, geo-blocked (Infura
|
|
576
|
+
* only), unavailable, or unknown
|
|
577
|
+
* - The capabilities status: whether it supports EIP-1559, whether it does
|
|
578
|
+
* not, or whether it is unknown
|
|
648
579
|
*
|
|
649
|
-
* - The
|
|
650
|
-
* (Infura only), or unavailable, or whether the status is unknown
|
|
651
|
-
* - Whether the network supports EIP-1559, or whether it is unknown
|
|
652
|
-
*
|
|
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.
|
|
580
|
+
* @param networkClientId - The ID of the network client to inspect.
|
|
658
581
|
* If no ID is provided, uses the currently selected network.
|
|
659
582
|
*/
|
|
660
583
|
async lookupNetwork(networkClientId) {
|
|
661
584
|
if (networkClientId) {
|
|
662
|
-
await this.
|
|
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
|
-
}
|
|
585
|
+
await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_lookupGivenNetwork).call(this, networkClientId);
|
|
769
586
|
}
|
|
770
587
|
else {
|
|
771
|
-
|
|
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');
|
|
588
|
+
await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_lookupSelectedNetwork).call(this);
|
|
775
589
|
}
|
|
776
590
|
}
|
|
591
|
+
/**
|
|
592
|
+
* Uses a request for the latest block to gather the following information on
|
|
593
|
+
* the given network, persisting it to state:
|
|
594
|
+
*
|
|
595
|
+
* - The connectivity status: whether the network is available, geo-blocked
|
|
596
|
+
* (Infura only), unavailable, or unknown
|
|
597
|
+
* - The feature compatibility status: whether the network supports EIP-1559,
|
|
598
|
+
* whether it does not, or whether it is unknown
|
|
599
|
+
*
|
|
600
|
+
* @param networkClientId - The ID of the network client to inspect.
|
|
601
|
+
* @deprecated Please use `lookupNetwork` and pass a network client ID
|
|
602
|
+
* instead. This method will be removed in a future major version.
|
|
603
|
+
*/
|
|
604
|
+
// We are planning on removing this so we aren't interested in testing this
|
|
605
|
+
// right now.
|
|
606
|
+
/* istanbul ignore next */
|
|
607
|
+
async lookupNetworkByClientId(networkClientId) {
|
|
608
|
+
await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_lookupGivenNetwork).call(this, networkClientId);
|
|
609
|
+
}
|
|
777
610
|
/**
|
|
778
611
|
* Convenience method to update provider network type settings.
|
|
779
612
|
*
|
|
@@ -1268,6 +1101,174 @@ async function _NetworkController_refreshNetwork(networkClientId, options = {})
|
|
|
1268
1101
|
__classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_applyNetworkSelection).call(this, networkClientId, options);
|
|
1269
1102
|
this.messagingSystem.publish('NetworkController:networkDidChange', this.state);
|
|
1270
1103
|
await this.lookupNetwork();
|
|
1104
|
+
}, _NetworkController_determineNetworkMetadata =
|
|
1105
|
+
/**
|
|
1106
|
+
* Uses a request for the latest block to gather the following information on
|
|
1107
|
+
* the given network:
|
|
1108
|
+
*
|
|
1109
|
+
* - The connectivity status: whether it is available, geo-blocked (Infura
|
|
1110
|
+
* only), unavailable, or unknown
|
|
1111
|
+
* - The capabilities status: whether it supports EIP-1559, whether it does
|
|
1112
|
+
* not, or whether it is unknown
|
|
1113
|
+
*
|
|
1114
|
+
* @param networkClientId - The ID of the network client to inspect.
|
|
1115
|
+
* If no ID is provided, uses the currently selected network.
|
|
1116
|
+
* @returns The resulting metadata for the network.
|
|
1117
|
+
*/
|
|
1118
|
+
async function _NetworkController_determineNetworkMetadata(networkClientId) {
|
|
1119
|
+
// Force TypeScript to use one of the two overloads explicitly
|
|
1120
|
+
const networkClient = (0, controller_utils_1.isInfuraNetworkType)(networkClientId)
|
|
1121
|
+
? this.getNetworkClientById(networkClientId)
|
|
1122
|
+
: this.getNetworkClientById(networkClientId);
|
|
1123
|
+
const isInfura = networkClient.configuration.type === types_1.NetworkClientType.Infura;
|
|
1124
|
+
let networkStatus;
|
|
1125
|
+
let isEIP1559Compatible;
|
|
1126
|
+
try {
|
|
1127
|
+
isEIP1559Compatible =
|
|
1128
|
+
await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_determineEIP1559Compatibility).call(this, networkClientId);
|
|
1129
|
+
networkStatus = constants_1.NetworkStatus.Available;
|
|
1130
|
+
}
|
|
1131
|
+
catch (error) {
|
|
1132
|
+
debugLog('NetworkController: lookupNetwork: ', error);
|
|
1133
|
+
if (isErrorWithCode(error)) {
|
|
1134
|
+
let responseBody;
|
|
1135
|
+
if (isInfura &&
|
|
1136
|
+
(0, utils_1.hasProperty)(error, 'message') &&
|
|
1137
|
+
typeof error.message === 'string') {
|
|
1138
|
+
try {
|
|
1139
|
+
responseBody = JSON.parse(error.message);
|
|
1140
|
+
}
|
|
1141
|
+
catch {
|
|
1142
|
+
// error.message must not be JSON
|
|
1143
|
+
__classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: json parse error: ', error);
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
if ((0, utils_1.isPlainObject)(responseBody) &&
|
|
1147
|
+
responseBody.error === constants_1.INFURA_BLOCKED_KEY) {
|
|
1148
|
+
networkStatus = constants_1.NetworkStatus.Blocked;
|
|
1149
|
+
}
|
|
1150
|
+
else if (error.code === rpc_errors_1.errorCodes.rpc.internal) {
|
|
1151
|
+
networkStatus = constants_1.NetworkStatus.Unknown;
|
|
1152
|
+
__classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: rpc internal error: ', error);
|
|
1153
|
+
}
|
|
1154
|
+
else {
|
|
1155
|
+
networkStatus = constants_1.NetworkStatus.Unavailable;
|
|
1156
|
+
__classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: ', error);
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
else {
|
|
1160
|
+
debugLog('NetworkController - could not determine network status', error);
|
|
1161
|
+
networkStatus = constants_1.NetworkStatus.Unknown;
|
|
1162
|
+
__classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: ', error);
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
return { isInfura, networkStatus, isEIP1559Compatible };
|
|
1166
|
+
}, _NetworkController_lookupGivenNetwork =
|
|
1167
|
+
/**
|
|
1168
|
+
* Uses a request for the latest block to gather the following information on
|
|
1169
|
+
* the given network, persisting it to state:
|
|
1170
|
+
*
|
|
1171
|
+
* - The connectivity status: whether the network is available, geo-blocked
|
|
1172
|
+
* (Infura only), unavailable, or unknown
|
|
1173
|
+
* - The feature compatibility status: whether the network supports EIP-1559,
|
|
1174
|
+
* whether it does not, or whether it is unknown
|
|
1175
|
+
*
|
|
1176
|
+
* @param networkClientId - The ID of the network client to inspect.
|
|
1177
|
+
*/
|
|
1178
|
+
async function _NetworkController_lookupGivenNetwork(networkClientId) {
|
|
1179
|
+
const { networkStatus, isEIP1559Compatible } = await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_determineNetworkMetadata).call(this, networkClientId);
|
|
1180
|
+
__classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_updateMetadataForNetwork).call(this, networkClientId, networkStatus, isEIP1559Compatible);
|
|
1181
|
+
}, _NetworkController_lookupSelectedNetwork =
|
|
1182
|
+
/**
|
|
1183
|
+
* Uses a request for the latest block to gather the following information on
|
|
1184
|
+
* the currently selected network, persisting it to state:
|
|
1185
|
+
*
|
|
1186
|
+
* - The connectivity status: whether the network is available, geo-blocked
|
|
1187
|
+
* (Infura only), unavailable, or unknown
|
|
1188
|
+
* - The feature compatibility status: whether the network supports EIP-1559,
|
|
1189
|
+
* whether it does not, or whether it is unknown
|
|
1190
|
+
*
|
|
1191
|
+
* Note that it is possible for the current network to be switched while this
|
|
1192
|
+
* method is running. If that is the case, it will exit early (as this method
|
|
1193
|
+
* will also run for the new network).
|
|
1194
|
+
*/
|
|
1195
|
+
async function _NetworkController_lookupSelectedNetwork() {
|
|
1196
|
+
if (!__classPrivateFieldGet(this, _NetworkController_ethQuery, "f")) {
|
|
1197
|
+
return;
|
|
1198
|
+
}
|
|
1199
|
+
let networkChanged = false;
|
|
1200
|
+
const listener = () => {
|
|
1201
|
+
networkChanged = true;
|
|
1202
|
+
try {
|
|
1203
|
+
this.messagingSystem.unsubscribe('NetworkController:networkDidChange', listener);
|
|
1204
|
+
}
|
|
1205
|
+
catch (error) {
|
|
1206
|
+
// In theory, this `catch` should not be necessary given that this error
|
|
1207
|
+
// would occur "inside" of the call to `#determineEIP1559Compatibility`
|
|
1208
|
+
// below and so it should be caught by the `try`/`catch` below (it is
|
|
1209
|
+
// impossible to reproduce in tests for that reason). However, somehow
|
|
1210
|
+
// it occurs within Mobile and so we have to add our own `try`/`catch`
|
|
1211
|
+
// here.
|
|
1212
|
+
/* istanbul ignore next */
|
|
1213
|
+
if (!(error instanceof Error) ||
|
|
1214
|
+
error.message !==
|
|
1215
|
+
'Subscription not found for event: NetworkController:networkDidChange') {
|
|
1216
|
+
// Again, this error should not happen and is impossible to reproduce
|
|
1217
|
+
// in tests.
|
|
1218
|
+
/* istanbul ignore next */
|
|
1219
|
+
throw error;
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
};
|
|
1223
|
+
this.messagingSystem.subscribe('NetworkController:networkDidChange', listener);
|
|
1224
|
+
const { isInfura, networkStatus, isEIP1559Compatible } = await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_determineNetworkMetadata).call(this, this.state.selectedNetworkClientId);
|
|
1225
|
+
if (networkChanged) {
|
|
1226
|
+
// If the network has changed, then `lookupNetwork` either has been or is
|
|
1227
|
+
// in the process of being called, so we don't need to go further.
|
|
1228
|
+
return;
|
|
1229
|
+
}
|
|
1230
|
+
try {
|
|
1231
|
+
this.messagingSystem.unsubscribe('NetworkController:networkDidChange', listener);
|
|
1232
|
+
}
|
|
1233
|
+
catch (error) {
|
|
1234
|
+
if (!(error instanceof Error) ||
|
|
1235
|
+
error.message !==
|
|
1236
|
+
'Subscription not found for event: NetworkController:networkDidChange') {
|
|
1237
|
+
throw error;
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
__classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_updateMetadataForNetwork).call(this, this.state.selectedNetworkClientId, networkStatus, isEIP1559Compatible);
|
|
1241
|
+
if (isInfura) {
|
|
1242
|
+
if (networkStatus === constants_1.NetworkStatus.Available) {
|
|
1243
|
+
this.messagingSystem.publish('NetworkController:infuraIsUnblocked');
|
|
1244
|
+
}
|
|
1245
|
+
else if (networkStatus === constants_1.NetworkStatus.Blocked) {
|
|
1246
|
+
this.messagingSystem.publish('NetworkController:infuraIsBlocked');
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
else {
|
|
1250
|
+
// Always publish infuraIsUnblocked regardless of network status to
|
|
1251
|
+
// prevent consumers from being stuck in a blocked state if they were
|
|
1252
|
+
// previously connected to an Infura network that was blocked
|
|
1253
|
+
this.messagingSystem.publish('NetworkController:infuraIsUnblocked');
|
|
1254
|
+
}
|
|
1255
|
+
}, _NetworkController_updateMetadataForNetwork = function _NetworkController_updateMetadataForNetwork(networkClientId, networkStatus, isEIP1559Compatible) {
|
|
1256
|
+
this.update((state) => {
|
|
1257
|
+
if (state.networksMetadata[networkClientId] === undefined) {
|
|
1258
|
+
state.networksMetadata[networkClientId] = {
|
|
1259
|
+
status: constants_1.NetworkStatus.Unknown,
|
|
1260
|
+
EIPS: {},
|
|
1261
|
+
};
|
|
1262
|
+
}
|
|
1263
|
+
const meta = state.networksMetadata[networkClientId];
|
|
1264
|
+
meta.status = networkStatus;
|
|
1265
|
+
if (isEIP1559Compatible === undefined) {
|
|
1266
|
+
delete meta.EIPS[1559];
|
|
1267
|
+
}
|
|
1268
|
+
else {
|
|
1269
|
+
meta.EIPS[1559] = isEIP1559Compatible;
|
|
1270
|
+
}
|
|
1271
|
+
});
|
|
1271
1272
|
}, _NetworkController_getLatestBlock = function _NetworkController_getLatestBlock(networkClientId) {
|
|
1272
1273
|
if (networkClientId === undefined) {
|
|
1273
1274
|
networkClientId = this.state.selectedNetworkClientId;
|