Skip to content

Commit

Permalink
Remove providerConfig from NetworkController (#4254)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mcmire authored Jun 12, 2024
1 parent bfe7fce commit 0f2a743
Show file tree
Hide file tree
Showing 7 changed files with 2,097 additions and 3,856 deletions.
12 changes: 0 additions & 12 deletions packages/assets-controllers/src/TokenRatesController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,11 +641,6 @@ describe('TokenRatesController', () => {
.mockResolvedValue();
triggerNetworkStateChange({
...defaultNetworkState,
providerConfig: {
...defaultNetworkState.providerConfig,
chainId: ChainId.mainnet,
ticker: 'NEW',
},
selectedNetworkClientId: defaultSelectedNetworkClientId,
});

Expand Down Expand Up @@ -1421,13 +1416,6 @@ describe('TokenRatesController', () => {
},
},
},
mockNetworkState: {
providerConfig: {
...defaultNetworkState.providerConfig,
chainId: toHex(2),
ticker: 'ticker',
},
},
},
async ({ controller }) => {
controller.startPollingByNetworkClientId('mainnet');
Expand Down
10 changes: 7 additions & 3 deletions packages/assets-controllers/src/TokenRatesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,16 @@ export class TokenRatesController extends StaticIntervalPollingController<
chainId: Hex;
ticker: string;
} {
const { providerConfig } = this.messagingSystem.call(
const { selectedNetworkClientId } = this.messagingSystem.call(
'NetworkController:getState',
);
const networkClient = this.messagingSystem.call(
'NetworkController:getNetworkClientById',
selectedNetworkClientId,
);
return {
chainId: providerConfig.chainId,
ticker: providerConfig.ticker,
chainId: networkClient.configuration.chainId,
ticker: networkClient.configuration.ticker,
};
}

Expand Down
10 changes: 10 additions & 0 deletions packages/network-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- **BREAKING:** Update `networksMetadata` state property so that the keys in the object will only ever be network client IDs and not RPC URLs ([#4254](https://github.com/MetaMask/core/pull/4254))
- Some keys could have been RPC URLs if the initial network controller state had a `providerConfig` with an empty `id`, but since `providerConfig` is being removed, that won't happen anymore.

### Removed

- **BREAKING:** Remove `providerConfig` property from state along with `ProviderConfig` type and `NetworkController:getProviderConfig` messenger action ([#4254](https://github.com/MetaMask/core/pull/4254))
- The best way to obtain the equivalent configuration object, e.g. to access the chain ID of the currently selected network, is to get `selectedNetworkClientId` from state, pass this to the `NetworkController:getNetworkClientId` messenger action, and then use the `configuration` property on the network client.

## [19.0.0]

### Changed
Expand Down
Loading

0 comments on commit 0f2a743

Please sign in to comment.