@metamask/network-controller 7.0.0 → 9.0.0

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
@@ -6,6 +6,109 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [9.0.0]
10
+ ### Added
11
+ - The events `networkWillChange` and `networkDidChange` are emitted during `setProviderType`, `setActiveNetwork`, `resetConnection`, and `rollbackToPreviousProvider` ([#1336](https://github.com/MetaMask/core/pull/1336))
12
+ - The `networkWillChange` event is emitted before the network is switched (before the network status is cleared),
13
+ - The `networkDidChange` event is emitted after the new provider is setup (but before it has finished initializing).
14
+ - Add `destroy` method ([#1330](https://github.com/MetaMask/core/pull/1330))
15
+ - Add events `infuraIsBlocked` and `infuraIsUnblocked` ([#1264](https://github.com/MetaMask/core/pull/1264))
16
+ - Add `NetworkController:getState` action constant ([#1329](https://github.com/MetaMask/core/pull/1329))
17
+
18
+ ### Changed
19
+ - **BREAKING:** Bump to Node 16 ([#1262](https://github.com/MetaMask/core/pull/1262))
20
+ - **BREAKING:** The `providerConfig` type and state property have changed. The `chainId` property is now `Hex` rather than a decimal `string` ([#1367](https://github.com/MetaMask/core/pull/1367))
21
+ - This requires a state migration
22
+ - This affects the return value of the `NetworkController:getProviderConfig` and `NetworkController:getState` actions.
23
+ - **BREAKING:** The `NetworkConfiguration` type and the `networkConfigurations` state property have changed. The `chainId` property on each configuration is now `Hex` rather than a decimal `string`. ([#1367](https://github.com/MetaMask/core/pull/1367))
24
+ - This requires a state migration
25
+ - This change affects the `upsertNetworkConfiguration` method, which takes a network configuration as the first parameter
26
+ - This affects the return value of the `NetworkController:getState` action
27
+ - Allow overlapping `lookupNetwork` calls ([#1375](https://github.com/MetaMask/core/pull/1375))
28
+ - `lookupNetwork` no longer uses a mutex, meaning that a lookup can be initiated before the previous one has finished. This allows for faster network switching
29
+ - When there is an overlap in `lookupNetwork` calls, the older one is aborted before events are emitted and before state changes
30
+ - **BREAKING:** Change `networkDetails` format ([#1326](https://github.com/MetaMask/core/pull/1326))
31
+ - Previously `networkDetails` was `{ isEIP1559Compatible: boolean }`, now it is `{ EIPS: { [eipNumber: number]: boolean } }`
32
+ - **BREAKING:** Update NetworkController to use a simpler middleware stack derived from pieces of `eth-json-rpc-middleware` instead of `web3-provider-engine` ([#1116](https://github.com/MetaMask/core/pull/1116))
33
+ - A call to `eth_chainId` on a custom network will now return the `chainId` in the provider config rather than the chain ID returned by the network.
34
+ - A call to `eth_chainId` on a built-in Infura network will now return a hard-coded chain ID rather than the chain ID returned by the network.
35
+ - A call to `net_version` on a built-in Infura network will now return a hard-coded network ID rather than the network ID returned by the network.
36
+ - Previously, RPC requests with an object as the first parameter (e.g. `eth_call`) were "sanitized" (i.e. unknown properties were removed from this first parameter, and any hex strings were normalized). This no longer happens. Instead these requests will pass through to the network unchanged.
37
+ - A call to `eth_getBalance`, `eth_getBlockByNumber`, `eth_getCode`, `eth_getTransactionCount`, or `eth_call` will now be intercepted such that a block tag parameter of `"latest"` will be replaced with the latest known block number before being passed to the network.
38
+ - This substitution makes it more likely that we can return a cached response to the request.
39
+ - Previously, a `eth_getTransactionCount` request with a block tag of `"pending"` would be intercepted and given a result from our nonce cache (if the cache was populated for the given address). This nonce cache was updated upon each call to `eth_sendRawTransaction` based on the nonce of the transaction being sent. The whole nonce cache was also cleared upon a call to `evm_revert`. This no longer happens, and these RPC methods will be passed to the network unchanged.
40
+ - If you were using this to get a suggested next nonce, you can instead use the `nonceTracker` that `@metamask/transaction-controller` exposes
41
+ - A call to `web3_clientVersion` is no longer intercepted to return a static result of `"ProviderEngine/v<version>/javascript"`
42
+ - A call to `net_listening` is no longer intercepted to return a static result of `true`
43
+ - A call to `eth_hashrate` is no longer intercepted to return a static result of `"0x00"`
44
+ - A call to `eth_mining` is no longer intercepted to return a static result of `false`
45
+ - Previously, `eth_subscribe` and `eth_unsubscribe` would never hit the network; instead, the behavior was polyfilled by polling the network for new blocks. Additionally, the `newPendingTransactions` parameter for `eth_subscribe` was unsupported. This polyfill is no longer present, and `eth_subscribe` and `eth_unsubscribe` are passed through to the network unchanged.
46
+ - Consumers wishing to recreate the prior behavior and use the block tracker to power subscriptions may employ the middleware provided by the `eth-json-rpc-filters` package.
47
+ - Previously, `eth_newFilter`, `eth_newBlockFilter`, `eth_newPendingTransactionFilter`, `eth_uninstallFilter`, `eth_getFilterChanges`, and `eth_getFilterLogs` would never hit the network; instead, the behavior was polyfilled by polling the network for new blocks and recording updates for registered filters. This polyfill is no longer present, and these RPC methods are passed through to the network unchanged.
48
+ - Consumers wishing to recreate the prior behavior and use the block tracker to power filters may employ the middleware provided by the `eth-json-rpc-filters` package.
49
+ - Interfacing with a network that exposes a websocket is no longer supported.
50
+ - **BREAKING:** The methods `initializeProvider`, `setActiveNetwork`, and `resetConnection` will now throw if the provider config is of type `rpc` but is missing an RPC URL or a chain ID. ([#1316](https://github.com/MetaMask/core/pull/1316))
51
+ - Previously the chain ID was not required to setup the provider.
52
+ - Previously if the RPC URL was omitted, no error would be thrown but the provider would not be setup.
53
+ - **BREAKING:** The method `setProviderType` will now throw when passed the type `rpc`. ([#1316](https://github.com/MetaMask/core/pull/1316))
54
+ - Previously no error would be thrown but the provider would not be setup.
55
+ - **BREAKING**: Update type of `blockTracker` property exposed by `getProviderAndBlockTracker` from `any` to `SwappableProxy<PollingBlockTracker>` ([#1303](https://github.com/MetaMask/core/pull/1303))
56
+ - **BREAKING:** Rename provider configuration property `rpcTarget` to `rpcUrl` ([#1292](https://github.com/MetaMask/core/pull/1292))
57
+ - **BREAKING:** The network status will now be "blocked" rather than "unavailable" when the user is blocked by Infura ([#1264](https://github.com/MetaMask/core/pull/1264))
58
+ - **BREAKING:** The `infuraProjectId` constructor parameter is now required ([#1276](https://github.com/MetaMask/core/pull/1276))
59
+ - **BREAKING:** The exported `Provider` type has been updated to better reflect the provider type returned by the network controller ([#1266](https://github.com/MetaMask/core/pull/1266))
60
+ - Previously this was set to `any`. Now it returns a type that _mostly_ matches the provider returned (some semi-internal properties are omitted)
61
+ - This affects the exported `ProviderProxy` type as well, which wraps the `Provider` type
62
+ - Support hex and number `net_version` responses ([#1380](https://github.com/MetaMask/core/pull/1380))
63
+ - Bump @metamask/utils from 5.0.1 to 5.0.2 ([#1271](https://github.com/MetaMask/core/pull/1271))
64
+ - Bump dependency `eth-json-rpc-infura` (now `@metamask/eth-json-rpc-infura`) from ^7.0.0 to ^8.0.0. ([#1116](https://github.com/MetaMask/core/pull/1116))
65
+ - Add dependency `eth-json-rpc-middleware` ^11.0.0 ([#1116](https://github.com/MetaMask/core/pull/1116))
66
+ - Add dependency `eth-json-rpc-provider` ^1.0.0 ([#1116](https://github.com/MetaMask/core/pull/1116))
67
+ - Add dependency `eth-block-tracker` ^7.0.0 ([#1116](https://github.com/MetaMask/core/pull/1116))
68
+ - Add dependency `json-rpc-engine` ^6.1.0 ([#1116](https://github.com/MetaMask/core/pull/1116))
69
+
70
+ ### Removed
71
+ - **BREAKING:** Remove `providerConfigChange` event ([#1329](https://github.com/MetaMask/core/pull/1329))
72
+ - Consumers are encouraged to subscribe to `NetworkController:stateChange` with a selector function that returns `providerConfig` if they want to perform an action when `providerConfig` changes.
73
+ - **BREAKING:** The built-in "localhost" network has been removed ([#1313](https://github.com/MetaMask/core/pull/1313))
74
+
75
+ ### Fixed
76
+ - Update network details in `lookupNetwork` even when network ID is unchanged ([#1379](https://github.com/MetaMask/core/pull/1379))
77
+ - Fix error when `rollbackToPreviousProvider` is called when the previous network is a custom network with a missing or invalid `id` ([#1223](https://github.com/MetaMask/core/pull/1223))
78
+ - In that situation, `rollbackToPreviousProvider` used to throw an error. Now it correctly rolls back instead.
79
+
80
+ ## [8.0.0]
81
+ ### Added
82
+ - Implement `resetConnection` method ([#1131](https://github.com/MetaMask/core/pull/1131), [#1235](https://github.com/MetaMask/core/pull/1235), [#1239](https://github.com/MetaMask/core/pull/1239))
83
+
84
+ ### Changed
85
+ - Update EIP-1559 compatibility during network lookup ([#1236](https://github.com/MetaMask/core/pull/1236))
86
+ - EIP-1559 compatibility check is still performed on initialization and after switching networks, like before. This change only impacts direct calls to `lookupNetwork`.
87
+ - `lookupNetwork` is now making two network calls instead of one, ensuring that the `networkDetails` state is up-to-date.
88
+ - **BREAKING:** Replace `network` state with `networkId` and `networkStatus` ([#1196](https://github.com/MetaMask/core/pull/1196))
89
+ - If you were using `network` to access the network ID, use `networkId` instead. It will be set to `null` rather than `loading` if the network is not currently available.
90
+ - If you were using `network` to see if the network was currently available, use `networkStatus` instead. It will be set to `NetworkStatus.Available` if the network is available.
91
+ - When the network is unavailable, we now have two different states to represent that: `unknown` and `unavailable`. `unavailable` means that the network was detected as not available, whereas `unknown` is used for unknown errors and cases where the network status is yet to be determined (e.g. before initialization, or while the network is loading).
92
+ - Use JavaScript private fields rather than `private` TypeScript keyword for internal methods/fields ([#1189](https://github.com/MetaMask/core/pull/1189))
93
+ - Export `BlockTrackerProxy` type ([#1147](https://github.com/MetaMask/core/pull/1147))
94
+ - This is the type of the block tracker returned from the `getProviderAndBlockTracker` method
95
+ - **BREAKING:** Async refactor
96
+ - Make `rollbackToPreviousProvider` async ([#1237](https://github.com/MetaMask/core/pull/1237))
97
+ - Make `upsertNetworkConfiguration` async ([#1192](https://github.com/MetaMask/core/pull/1192))
98
+ - Make `setActiveNetwork` async ([#1190](https://github.com/MetaMask/core/pull/1190))
99
+ - Make `setProviderType` async ([#1191](https://github.com/MetaMask/core/pull/1191))
100
+ - Make `refreshNetwork` async ([#1182](https://github.com/MetaMask/core/pull/1182))
101
+ - Make `initializeProvider` async ([#1180](https://github.com/MetaMask/core/pull/1180))
102
+ - Make `verifyNetwork` async ([#1181](https://github.com/MetaMask/core/pull/1181))
103
+ - Dependency updates
104
+ - deps: bump web3-provider-engine@16.0.3->16.0.5 ([#1212](https://github.com/MetaMask/core/pull/1212))
105
+ - deps: eth-rpc-errors@4.0.0->4.0.2 ([#1215](https://github.com/MetaMask/core/pull/1215))
106
+ - deps: bump @metamask/utils to 5.0.1 ([#1211](https://github.com/MetaMask/core/pull/1211))
107
+
108
+ ### Removed
109
+ - **BREAKING:** Remove `isCustomNetwork` state ([#1199](https://github.com/MetaMask/core/pull/1199))
110
+ - The `providerConfig.type` state will be set to `'rpc'` if the current network is a custom network. Replace all references to the `isCustomNetwork` state by checking the provider config state instead.
111
+
9
112
  ## [7.0.0]
10
113
  ### Changed
11
114
  - **BREAKING:** Replace `providerConfig` setter with a public `initializeProvider` method ([#1133](https://github.com/MetaMask/core/pull/1133))
@@ -50,7 +153,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
50
153
  - **BREAKING:** Make `lookupNetwork` block on completing the lookup ([#1063](https://github.com/MetaMask/controllers/pull/1063))
51
154
  - This function was always `async`, but it would return before completing any async work. Now it will not return until after the network lookup has been completed.
52
155
  - Rename this repository to `core` ([#1031](https://github.com/MetaMask/controllers/pull/1031))
53
- - Update `@metamask/controller-utils` package ([#1041](https://github.com/MetaMask/controllers/pull/1041))
156
+ - Update `@metamask/controller-utils` package ([#1041](https://github.com/MetaMask/controllers/pull/1041))
54
157
 
55
158
  ### Removed
56
159
  - **BREAKING:**: Drop support for Ropsten, Rinkeby, and Kovan as built-in Infura networks ([#1041](https://github.com/MetaMask/controllers/pull/1041))
@@ -70,7 +173,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
70
173
 
71
174
  All changes listed after this point were applied to this package following the monorepo conversion.
72
175
 
73
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/network-controller@7.0.0...HEAD
176
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/network-controller@9.0.0...HEAD
177
+ [9.0.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@8.0.0...@metamask/network-controller@9.0.0
178
+ [8.0.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@7.0.0...@metamask/network-controller@8.0.0
74
179
  [7.0.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@6.0.0...@metamask/network-controller@7.0.0
75
180
  [6.0.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@5.0.0...@metamask/network-controller@6.0.0
76
181
  [5.0.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@4.0.0...@metamask/network-controller@5.0.0
@@ -1,12 +1,16 @@
1
1
  import type { SwappableProxy } from '@metamask/swappable-obj-proxy';
2
- import type { Patch } from 'immer';
2
+ import EthQuery from 'eth-query';
3
3
  import { BaseControllerV2, RestrictedControllerMessenger } from '@metamask/base-controller';
4
- import { NetworkType } from '@metamask/controller-utils';
4
+ import type { Patch } from 'immer';
5
+ import { InfuraNetworkType, NetworkType } from '@metamask/controller-utils';
6
+ import { Hex } from '@metamask/utils';
7
+ import { NetworkStatus } from './constants';
8
+ import type { BlockTracker, Provider } from './types';
5
9
  /**
6
10
  * @type ProviderConfig
7
11
  *
8
12
  * Configuration passed to web3-provider-engine
9
- * @property rpcTarget - RPC target URL.
13
+ * @property rpcUrl - RPC target URL.
10
14
  * @property type - Human-readable network name.
11
15
  * @property chainId - Network ID as per EIP-155.
12
16
  * @property ticker - Currency ticker.
@@ -14,9 +18,9 @@ import { NetworkType } from '@metamask/controller-utils';
14
18
  * @property id - Network Configuration Id.
15
19
  */
16
20
  export declare type ProviderConfig = {
17
- rpcTarget?: string;
21
+ rpcUrl?: string;
18
22
  type: NetworkType;
19
- chainId: string;
23
+ chainId: Hex;
20
24
  ticker?: string;
21
25
  nickname?: string;
22
26
  rpcPrefs?: {
@@ -27,13 +31,22 @@ export declare type ProviderConfig = {
27
31
  export declare type Block = {
28
32
  baseFeePerGas?: string;
29
33
  };
34
+ /**
35
+ * Information about the network not held by any other part of state. Currently
36
+ * only used to capture whether a network supports EIP-1559.
37
+ */
30
38
  export declare type NetworkDetails = {
31
- isEIP1559Compatible?: boolean;
39
+ /**
40
+ * EIPs supported by the network.
41
+ */
42
+ EIPS: {
43
+ [eipNumber: number]: boolean;
44
+ };
32
45
  };
33
46
  /**
34
47
  * Custom RPC network information
35
48
  *
36
- * @property rpcTarget - RPC target URL.
49
+ * @property rpcUrl - RPC target URL.
37
50
  * @property chainId - Network ID as per EIP-155
38
51
  * @property nickname - Personalized network name.
39
52
  * @property ticker - Currency ticker.
@@ -41,26 +54,29 @@ export declare type NetworkDetails = {
41
54
  */
42
55
  export declare type NetworkConfiguration = {
43
56
  rpcUrl: string;
44
- chainId: string;
57
+ chainId: Hex;
45
58
  ticker: string;
46
59
  nickname?: string;
47
60
  rpcPrefs?: {
48
61
  blockExplorerUrl: string;
49
62
  };
50
63
  };
64
+ /**
65
+ * The network ID of a network.
66
+ */
67
+ export declare type NetworkId = `${number}`;
51
68
  /**
52
69
  * @type NetworkState
53
70
  *
54
71
  * Network controller state
55
72
  * @property network - Network ID as per net_version of the currently connected network
56
- * @property isCustomNetwork - Identifies if the currently connected network is a custom network
57
73
  * @property providerConfig - RPC URL and network name provider settings of the currently connected network
58
74
  * @property properties - an additional set of network properties for the currently connected network
59
75
  * @property networkConfigurations - the full list of configured networks either preloaded or added by the user.
60
76
  */
61
77
  export declare type NetworkState = {
62
- network: string;
63
- isCustomNetwork: boolean;
78
+ networkId: NetworkId | null;
79
+ networkStatus: NetworkStatus;
64
80
  providerConfig: ProviderConfig;
65
81
  networkDetails: NetworkDetails;
66
82
  networkConfigurations: Record<string, NetworkConfiguration & {
@@ -68,33 +84,66 @@ export declare type NetworkState = {
68
84
  }>;
69
85
  };
70
86
  declare const name = "NetworkController";
71
- export declare type EthQuery = any;
72
- declare type Provider = any;
87
+ export declare type BlockTrackerProxy = SwappableProxy<BlockTracker>;
73
88
  export declare type ProviderProxy = SwappableProxy<Provider>;
74
- declare type BlockTracker = any;
75
89
  export declare type NetworkControllerStateChangeEvent = {
76
90
  type: `NetworkController:stateChange`;
77
91
  payload: [NetworkState, Patch[]];
78
92
  };
79
- export declare type NetworkControllerProviderConfigChangeEvent = {
80
- type: `NetworkController:providerConfigChange`;
81
- payload: [ProviderConfig];
93
+ /**
94
+ * `networkWillChange` is published when the current network is about to be
95
+ * switched, but the new provider has not been created and no state changes have
96
+ * occurred yet.
97
+ */
98
+ export declare type NetworkControllerNetworkWillChangeEvent = {
99
+ type: 'NetworkController:networkWillChange';
100
+ payload: [];
101
+ };
102
+ /**
103
+ * `networkDidChange` is published after a provider has been created for a newly
104
+ * switched network (but before the network has been confirmed to be available).
105
+ */
106
+ export declare type NetworkControllerNetworkDidChangeEvent = {
107
+ type: 'NetworkController:networkDidChange';
108
+ payload: [];
109
+ };
110
+ /**
111
+ * `infuraIsBlocked` is published after the network is switched to an Infura
112
+ * network, but when Infura returns an error blocking the user based on their
113
+ * location.
114
+ */
115
+ export declare type NetworkControllerInfuraIsBlockedEvent = {
116
+ type: 'NetworkController:infuraIsBlocked';
117
+ payload: [];
118
+ };
119
+ /**
120
+ * `infuraIsBlocked` is published either after the network is switched to an
121
+ * Infura network and Infura does not return an error blocking the user based on
122
+ * their location, or the network is switched to a non-Infura network.
123
+ */
124
+ export declare type NetworkControllerInfuraIsUnblockedEvent = {
125
+ type: 'NetworkController:infuraIsUnblocked';
126
+ payload: [];
127
+ };
128
+ export declare type NetworkControllerEvents = NetworkControllerStateChangeEvent | NetworkControllerNetworkWillChangeEvent | NetworkControllerNetworkDidChangeEvent | NetworkControllerInfuraIsBlockedEvent | NetworkControllerInfuraIsUnblockedEvent;
129
+ export declare type NetworkControllerGetStateAction = {
130
+ type: `NetworkController:getState`;
131
+ handler: () => NetworkState;
82
132
  };
83
- export declare type NetworkControllerEvents = NetworkControllerStateChangeEvent | NetworkControllerProviderConfigChangeEvent;
84
133
  export declare type NetworkControllerGetProviderConfigAction = {
85
134
  type: `NetworkController:getProviderConfig`;
86
135
  handler: () => ProviderConfig;
87
136
  };
88
137
  export declare type NetworkControllerGetEthQueryAction = {
89
138
  type: `NetworkController:getEthQuery`;
90
- handler: () => EthQuery;
139
+ handler: () => EthQuery | undefined;
91
140
  };
92
- export declare type NetworkControllerActions = NetworkControllerGetProviderConfigAction | NetworkControllerGetEthQueryAction;
93
- export declare type NetworkControllerMessenger = RestrictedControllerMessenger<typeof name, NetworkControllerGetProviderConfigAction | NetworkControllerGetEthQueryAction, NetworkControllerStateChangeEvent | NetworkControllerProviderConfigChangeEvent, string, string>;
141
+ export declare type NetworkControllerActions = NetworkControllerGetStateAction | NetworkControllerGetProviderConfigAction | NetworkControllerGetEthQueryAction;
142
+ export declare type NetworkControllerMessenger = RestrictedControllerMessenger<typeof name, NetworkControllerActions, NetworkControllerEvents, string, string>;
94
143
  export declare type NetworkControllerOptions = {
95
144
  messenger: NetworkControllerMessenger;
96
145
  trackMetaMetricsEvent: () => void;
97
- infuraProjectId?: string;
146
+ infuraProjectId: string;
98
147
  state?: Partial<NetworkState>;
99
148
  };
100
149
  export declare const defaultState: NetworkState;
@@ -104,33 +153,28 @@ declare type NetworkConfigurationId = string;
104
153
  */
105
154
  export declare class NetworkController extends BaseControllerV2<typeof name, NetworkState, NetworkControllerMessenger> {
106
155
  #private;
107
- private ethQuery;
108
- private infuraProjectId;
109
- private trackMetaMetricsEvent;
110
- private mutex;
111
156
  constructor({ messenger, state, infuraProjectId, trackMetaMetricsEvent, }: NetworkControllerOptions);
112
- private configureProvider;
113
157
  getProviderAndBlockTracker(): {
114
158
  provider: SwappableProxy<Provider> | undefined;
115
159
  blockTracker: SwappableProxy<BlockTracker> | undefined;
116
160
  };
117
- private refreshNetwork;
118
- private registerProvider;
119
- private setupInfuraProvider;
120
- private getIsCustomNetwork;
121
- private setupStandardProvider;
122
- private updateProvider;
123
- private safelyStopProvider;
124
- private verifyNetwork;
125
161
  /**
126
162
  * Method to inilialize the provider,
127
163
  * Creates the provider and block tracker for the configured network,
128
164
  * using the provider to gather details about the network.
129
165
  *
130
166
  */
131
- initializeProvider(): void;
167
+ initializeProvider(): Promise<void>;
132
168
  /**
133
- * Refreshes the current network code.
169
+ * Performs side effects after switching to a network. If the network is
170
+ * available, updates the network state with the network ID of the network and
171
+ * stores whether the network supports EIP-1559; otherwise clears said
172
+ * information about the network that may have been previously stored.
173
+ *
174
+ * @fires infuraIsBlocked if the network is Infura-supported and is blocking
175
+ * requests.
176
+ * @fires infuraIsUnblocked if the network is Infura-supported and is not
177
+ * blocking requests, or if the network is not Infura-supported.
134
178
  */
135
179
  lookupNetwork(): Promise<void>;
136
180
  /**
@@ -138,14 +182,26 @@ export declare class NetworkController extends BaseControllerV2<typeof name, Net
138
182
  *
139
183
  * @param type - Human readable network name.
140
184
  */
141
- setProviderType(type: NetworkType): void;
185
+ setProviderType(type: InfuraNetworkType): Promise<void>;
142
186
  /**
143
187
  * Convenience method to update provider RPC settings.
144
188
  *
145
189
  * @param networkConfigurationId - The unique id for the network configuration to set as the active provider.
146
190
  */
147
- setActiveNetwork(networkConfigurationId: string): void;
191
+ setActiveNetwork(networkConfigurationId: string): Promise<void>;
192
+ /**
193
+ * Determines whether the network supports EIP-1559 by checking whether the
194
+ * latest block has a `baseFeePerGas` property, then updates state
195
+ * appropriately.
196
+ *
197
+ * @returns A promise that resolves to true if the network supports EIP-1559
198
+ * and false otherwise.
199
+ */
148
200
  getEIP1559Compatibility(): Promise<boolean>;
201
+ /**
202
+ * Re-initializes the provider and block tracker for the current network.
203
+ */
204
+ resetConnection(): Promise<void>;
149
205
  /**
150
206
  * Adds a network configuration if the rpcUrl is not already present on an
151
207
  * existing network configuration. Otherwise updates the entry with the matching rpcUrl.
@@ -166,7 +222,7 @@ export declare class NetworkController extends BaseControllerV2<typeof name, Net
166
222
  setActive?: boolean;
167
223
  referrer: string;
168
224
  source: string;
169
- }): string;
225
+ }): Promise<string>;
170
226
  /**
171
227
  * Removes network configuration from state.
172
228
  *
@@ -174,9 +230,17 @@ export declare class NetworkController extends BaseControllerV2<typeof name, Net
174
230
  */
175
231
  removeNetworkConfiguration(networkConfigurationId: string): void;
176
232
  /**
177
- * Rolls back provider config to the previous provider in case of errors or inability to connect during network switch.
233
+ * Switches to the previous network, assuming that the current network is
234
+ * different than the initial network (if it is, then this is equivalent to
235
+ * calling `resetConnection`).
236
+ */
237
+ rollbackToPreviousProvider(): Promise<void>;
238
+ /**
239
+ * Deactivates the controller, stopping any ongoing polling.
240
+ *
241
+ * In-progress requests will not be aborted.
178
242
  */
179
- rollbackToPreviousProvider(): void;
243
+ destroy(): Promise<void>;
180
244
  }
181
245
  export default NetworkController;
182
246
  //# sourceMappingURL=NetworkController.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"NetworkController.d.ts","sourceRoot":"","sources":["../src/NetworkController.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAGpE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EACL,gBAAgB,EAChB,6BAA6B,EAC9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAEL,WAAW,EAKZ,MAAM,4BAA4B,CAAC;AAIpC;;;;;;;;;;GAUG;AACH,oBAAY,cAAc,GAAG;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE;QAAE,gBAAgB,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACzC,EAAE,CAAC,EAAE,sBAAsB,CAAC;CAC7B,CAAC;AAEF,oBAAY,KAAK,GAAG;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,oBAAY,cAAc,GAAG;IAC3B,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B,CAAC;AAEF;;;;;;;;GAQG;AACH,oBAAY,oBAAoB,GAAG;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAA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