Correct invalid initial selectedNetworkClientId #15941
Draft
+162
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Currently, when NetworkController is instantiated with pre-existing state that contains an invalid
selectedNetworkClientId
— that is, no RPC endpoint exists which has the same network client ID — then it throws an error. This was intentionally done to bring attention to possible bugs in NetworkController, but this has the unfortunate side effect of bricking users' wallets.To fix this, we now correct an invalid
selectedNetworkClientId
to point to the default RPC endpoint of the first network sorted by chain ID (which in the vast majority of cases will be Mainnet). We still do want to know about this, though, so we log the error in Sentry.Related issues
See MetaMask/core#5851 for the equivalent changes to network-controller that were copied here.
Manual testing steps
yarn setup:expo
.Engine.ts
, scroll down to where NetworkController is initialized, and apply these changes:yarn watch:clean
.selectedNetworkClientId mainnet
. This proves that although the initialselectedNetworkClientId
was invalid, it was auto-corrected to "mainnet".Screenshots/Recordings
(N/A)
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist