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

refactor: Use selectors for core network state access #7121

Merged
merged 2 commits into from
Sep 5, 2023

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Sep 4, 2023

Development & PR Process

  1. Follow MetaMask Mobile Coding Standards
  2. Add release-xx label to identify the PR slated for a upcoming release (will be used in release discussion)
  3. Add needs-dev-review label when work is completed
  4. Add the appropiate QA label when dev review is completed
    • needs-qa: PR requires manual QA.
    • No QA/E2E only: PR does not require any manual QA effort. Prior to merging, ensure that you have successful end-to-end test runs in Bitrise.
    • Spot check on release build: PR does not require feature QA but needs non-automated verification. In the description section, provide test scenarios. Add screenshots, and or recordings of what was tested.
  5. Add QA Passed label when QA has signed off (Only required if the PR was labeled with needs-qa)
  6. Add your team's label, i.e. label starting with team- (or external-contributor label if your not a MetaMask employee)

Description

Replace direct references to NetworkController state with selectors. Most of these examples were skipped in previous selector refactors because they were outside of a React context, so there was no established way to get the Redux state as input for the selector. We can now do that by importing the Redux store directly and calling getState.

Issue

This relates to https://github.com/MetaMask/mobile-planning/issues/1226

Checklist

  • There is a related GitHub issue
  • Tests are included if applicable
  • Any added code is fully documented

@codecov-commenter
Copy link

codecov-commenter commented Sep 4, 2023

Codecov Report

Patch coverage: 26.92% and project coverage change: -0.33% ⚠️

Comparison is base (02e4ed6) 32.84% compared to head (932f2d1) 32.52%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7121      +/-   ##
==========================================
- Coverage   32.84%   32.52%   -0.33%     
==========================================
  Files        1001     1001              
  Lines       26780    26776       -4     
  Branches     2118     2116       -2     
==========================================
- Hits         8797     8708      -89     
- Misses      17559    17649      +90     
+ Partials      424      419       -5     
Files Changed Coverage Δ
app/core/BackgroundBridge/BackgroundBridge.js 5.35% <0.00%> (ø)
app/core/BackgroundBridge/WalletConnectPort.ts 11.76% <0.00%> (ø)
app/core/NotificationManager.js 0.00% <0.00%> (ø)
app/core/RPCMethods/wallet_switchEthereumChain.js 35.71% <0.00%> (ø)
app/core/WalletConnect/WalletConnectV2.ts 2.27% <0.00%> (+0.03%) ⬆️
app/util/address/index.js 38.35% <0.00%> (+0.26%) ⬆️
app/core/RPCMethods/RPCMethodMiddleware.ts 40.23% <20.00%> (-3.13%) ⬇️
app/util/networks/handleNetworkSwitch.ts 31.81% <40.00%> (-63.19%) ⬇️
app/core/RPCMethods/wallet_addEthereumChain.js 28.15% <50.00%> (-51.46%) ⬇️
app/components/UI/PersonalSign/PersonalSign.tsx 75.51% <100.00%> (-0.49%) ⬇️
... and 2 more

... and 2 files with indirect coverage changes

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

@Gudahtt Gudahtt force-pushed the use-selectors-for-core-network-controller-state branch 4 times, most recently from 871e833 to 21c1980 Compare September 4, 2023 16:23
@Gudahtt
Copy link
Member Author

Gudahtt commented Sep 4, 2023

@Gudahtt Gudahtt marked this pull request as ready for review September 4, 2023 17:35
@Gudahtt Gudahtt requested a review from a team as a code owner September 4, 2023 17:35
@Gudahtt Gudahtt added the needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) label Sep 4, 2023
Replace direct references to NetworkController state with selectors.
Most of these examples were skipped in previous selector refactors
because they were outside of a React context, so there was no
established way to get the Redux state as input for the selector. We
can now do that by importing the Redux store directly and calling
`getState`.

This relates to MetaMask/mobile-planning#1226
@Gudahtt Gudahtt force-pushed the use-selectors-for-core-network-controller-state branch from 21c1980 to cfceb7f Compare September 5, 2023 17:22
Copy link
Contributor

@Cal-L Cal-L left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a comment

app/core/WalletConnect/WalletConnect.js Outdated Show resolved Hide resolved
The WalletConnect module has been updated to pass the full Redux state
to the `selectChainId` selector, rather than just the background state.
The background state was being passed in alone because it was left
behind accidentally from an earlier version of this branch, from before
the recent store refactors/TypeScript conversion.
@sonarcloud
Copy link

sonarcloud bot commented Sep 5, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

42.9% 42.9% Coverage
0.0% 0.0% Duplication

warning The version of Java (11.0.20) you have used to run this analysis is deprecated and we will stop accepting it soon. Please update to at least Java 17.
Read more here

Copy link
Contributor

@Cal-L Cal-L left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Cal-L Cal-L added No QA Needed/E2E Only Apply this label when your PR does not need any QA effort. and removed needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) labels Sep 5, 2023
@Gudahtt Gudahtt merged commit d8000e1 into main Sep 5, 2023
14 checks passed
@Gudahtt Gudahtt deleted the use-selectors-for-core-network-controller-state branch September 5, 2023 21:10
@github-actions github-actions bot locked and limited conversation to collaborators Sep 5, 2023
@metamaskbot metamaskbot added the release-7.8.0 Issue or pull request that will be included in release 7.8.0 label Sep 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
No QA Needed/E2E Only Apply this label when your PR does not need any QA effort. release-7.8.0 Issue or pull request that will be included in release 7.8.0 team-mobile-platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants