Skip to content
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

fix: Fix currentNetwork selector when current network config is missing (#26327) #26331

Merged
merged 3 commits into from
Aug 5, 2024

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Aug 2, 2024

This is a cherry-pick of #26327 for v12.0.1. Original description below:

Description

The providerConfig state is not guaranteed to match a built-in or custom network. It should in the vast majority of cases, but there are some edge cases where that would not hold true. For example:

  • If the wallet crashed partway through removing the current network
  • If the user has had the same network selected since before we introduced the networkConfigurations state

The currentNetwork selector has been updated to handle this case by returning a configuration object constructed from the providerConfig state directly.

Open in GitHub Codespaces

Related issues

Fixes #26320

Manual testing steps

  • Create a dev build and proceed through onboarding
  • Run this command in the background console to set providerConfig to a custom network that isn't present in the user's tracked network configurations:
    chrome.storage.local.get(
      null,
      (state) => {
        state.data.NetworkController.providerConfig = {
          rpcUrl: 'https://mainnet.optimism.io',
          chainId: '0xa',
          ticker: 'ETH',
          type: 'rpc',
        };
        chrome.storage.local.set(state, () => chrome.runtime.reload());
      }
    );
    
  • See that the UI can be opened and does not crash.

Screenshots/Recordings

N/A

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@Gudahtt Gudahtt force-pushed the v12-cherry-pick-fix-current-network-selector branch from 35ff1e4 to fdd517b Compare August 2, 2024 19:42
@Gudahtt Gudahtt marked this pull request as ready for review August 2, 2024 20:01
@Gudahtt Gudahtt requested review from a team as code owners August 2, 2024 20:01
Gudahtt added 3 commits August 5, 2024 12:23
…sing (#26327)

The `providerConfig` state is not guaranteed to match a built-in or
custom network. It should in the vast majority of cases, but there are
some edge cases where that would not hold true. For example:
* If the wallet crashed partway through removing the current network
* If the user has had the same network selected since before we
introduced the `networkConfigurations` state

The `currentNetwork` selector has been updated to handle this case by
returning a configuration object constructed from the `providerConfig`
state directly.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26327?quickstart=1)

Fixes #26320

* Create a dev build and proceed through onboarding
* Run this command in the background console to set `providerConfig` to
a custom network that isn't present in the user's tracked network
configurations:
  ```
  chrome.storage.local.get(
    null,
    (state) => {
      state.data.NetworkController.providerConfig = {
        rpcUrl: 'https://mainnet.optimism.io',
        chainId: '0xa',
        ticker: 'ETH',
        type: 'rpc',
      };
      chrome.storage.local.set(state, () => chrome.runtime.reload());
    }
  );
  ```
* See that the UI can be opened and does not crash.

N/A

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
@Gudahtt Gudahtt force-pushed the v12-cherry-pick-fix-current-network-selector branch from 4f7bcb2 to 0b62420 Compare August 5, 2024 14:53
Copy link

codecov bot commented Aug 5, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 5 lines in your changes missing coverage. Please review.

Project coverage is 65.66%. Comparing base (219dca5) to head (0b62420).

Files Patch % Lines
ui/selectors/selectors.js 37.50% 5 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff                @@
##           Version-v12.0.1   #26331   +/-   ##
================================================
  Coverage            65.66%   65.66%           
================================================
  Files                 1369     1369           
  Lines                54661    54663    +2     
  Branches             14223    14225    +2     
================================================
+ Hits                 35890    35893    +3     
+ Misses               18771    18770    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@danjm danjm merged commit ce1ed8d into Version-v12.0.1 Aug 5, 2024
72 of 73 checks passed
@danjm danjm deleted the v12-cherry-pick-fix-current-network-selector branch August 5, 2024 17:43
@github-actions github-actions bot locked and limited conversation to collaborators Aug 5, 2024
@metamaskbot
Copy link
Collaborator

Builds ready [0b62420]
Page Load Metrics (45 ± 5 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint6513579189
domContentLoaded8181021
load398545105
domInteractive8181021

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants