-
-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove providerConfig from NetworkController #4254
Conversation
9b3cc0a
to
730b264
Compare
ca0fc05
to
310a6b3
Compare
310a6b3
to
cd8a065
Compare
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.
cd8a065
to
65fa9a8
Compare
Conflicts resolved. |
packages/selected-network-controller/tests/SelectedNetworkController.test.ts
Show resolved
Hide resolved
Okay! Tests should pass again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM.
autoManagedNetworkClient = | ||
builtInNetworkClientRegistry[networkClientId as BuiltInNetworkClientId]; | ||
if (!autoManagedNetworkClient) { | ||
// This is impossible to reach |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about mocking isInfuraNetworkType
to return true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test we'd need to write here is not what happens when isInfuraNetworkType
returns true or false, but what happens when isInfuraNetworkType
returns true and yet possibleAutoManagedNetworkClient
is undefined
. If that happens, it would mean that there is no network client registered for the networkClientId
when it refers to an Infura network.
The reason why this is impossible is that autoManagedNetworkClientRegistry[NetworkClientType.Infura]
is automatically populated with all of the Infura networks that we know about, and there is no way to stop that from happening. So if networkClientId
refers to an Infura network, we know that it matches a network client in autoManagedNetworkClientRegistry[NetworkClientType.Infura]
.
However, this will no longer be true in #4286, because that integrates Infura networks into the networkConfigurationsByChainId
state property, and so we will now be able to control whether a network client gets created for an Infura network or not, making this scenario testable.
All this to say... this istanbul ignore
will go away in #4286.
import { | ||
buildCustomNetworkClientConfiguration, | ||
buildInfuraNetworkClientConfiguration, | ||
} from './helpers'; | ||
|
||
jest.mock('../src/create-network-client'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious to know, why we have a separate test folder which is uncommon when we compared with other controllers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. This change was made by another team mistakenly and wasn't caught, and has now persisted. I agree that we should move this to src/
however.
const fakeNetworkClient = buildFakeClient(fakeProvider); | ||
createNetworkClientMock.mockReturnValue(fakeNetworkClient); | ||
}, | ||
infuraProjectId: 'some-infura-project-id', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to understand, even the custom network client will have a infura project id?
Explanation
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 viaselectedNetworkClientId
, and information about that network can be retrieved by looking at thenetworkConfigurations
property or theconfiguration
property on the NetworkClient interface. This means that we no longer needproviderConfig
and we can remove this redundant state.References
Fixes #4185.
Changelog
(Updated in PR)
Checklist