Skip to content

Commit 730b264

Browse files
committed
Remove providerConfig from NetworkController
Historically, the `providerConfig` property in NetworkController has been used to track the currently selected network as well as provide access to information about that network. The selected network is now tracked via `selectedNetworkClientId`, and information about that network can be retrieved by looking at the `networkConfigurations` property or the `configuration` property on the NetworkClient interface. This means that we no longer need `providerConfig` and we can remove this redundant state.
1 parent 9687bfc commit 730b264

20 files changed

+3090
-4443
lines changed

packages/assets-controllers/src/AccountTrackerController.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import type { Provider } from '@metamask/eth-query';
55
import type {
66
NetworkClientId,
77
NetworkController,
8-
NetworkState,
98
} from '@metamask/network-controller';
109
import { StaticIntervalPollingControllerV1 } from '@metamask/polling-controller';
1110
import type { PreferencesState } from '@metamask/preferences-controller';
11+
import type { Hex } from '@metamask/utils';
1212
import { assert } from '@metamask/utils';
1313
import { Mutex } from 'async-mutex';
1414
import { cloneDeep } from 'lodash';
@@ -120,7 +120,7 @@ export class AccountTrackerController extends StaticIntervalPollingControllerV1<
120120

121121
private readonly getMultiAccountBalancesEnabled: () => PreferencesState['isMultiAccountBalancesEnabled'];
122122

123-
private readonly getCurrentChainId: () => NetworkState['providerConfig']['chainId'];
123+
private readonly getCurrentChainId: () => Hex;
124124

125125
private readonly getNetworkClientById: NetworkController['getNetworkClientById'];
126126

@@ -152,7 +152,7 @@ export class AccountTrackerController extends StaticIntervalPollingControllerV1<
152152
getIdentities: () => PreferencesState['identities'];
153153
getSelectedAddress: () => PreferencesState['selectedAddress'];
154154
getMultiAccountBalancesEnabled: () => PreferencesState['isMultiAccountBalancesEnabled'];
155-
getCurrentChainId: () => NetworkState['providerConfig']['chainId'];
155+
getCurrentChainId: () => Hex;
156156
getNetworkClientById: NetworkController['getNetworkClientById'];
157157
},
158158
config?: Partial<AccountTrackerConfig>,

packages/assets-controllers/src/AssetsContractController.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,15 @@ export class AssetsContractController extends BaseControllerV1<
154154
this.configure({ ipfsGateway });
155155
});
156156

157-
onNetworkDidChange((networkState) => {
158-
if (this.config.chainId !== networkState.providerConfig.chainId) {
157+
onNetworkDidChange(({ selectedNetworkClientId }) => {
158+
const selectedNetworkClient = getNetworkClientById(
159+
selectedNetworkClientId,
160+
);
161+
const { chainId } = selectedNetworkClient.configuration;
162+
163+
if (this.config.chainId !== chainId) {
159164
this.configure({
160-
chainId: networkState.providerConfig.chainId,
165+
chainId: selectedNetworkClient.configuration.chainId,
161166
});
162167
}
163168
});

0 commit comments

Comments
 (0)