-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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: disable polling when MM closed #24162
fix: disable polling when MM closed #24162
Conversation
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
E2E failures look legit |
Builds ready [78f47bc]
Page Load Metrics (1198 ± 600 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #24162 +/- ##
===========================================
- Coverage 67.47% 67.44% -0.02%
===========================================
Files 1257 1257
Lines 49232 49242 +10
Branches 12822 12816 -6
===========================================
- Hits 33216 33211 -5
- Misses 16016 16031 +15 ☔ View full report in Codecov by Sentry. |
Builds ready [f49cd66]
Page Load Metrics (858 ± 582 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
## Explanation This PR goes together with this extension PR MetaMask/metamask-extension#24162 We want to reduce third party calls for nft detection when a user has closed the MM popup/window. To do that we are leveraging `stopNetworkRequests` and `triggerNetworkrequests` functions inside extension to either `stop()` or `start()` the nft detection. While doing this fixed the following scenario: 1- User imports MM wallet 2- User enables nft detection toggle 3- User closes MM tab or popup 4- We are no longuer making calls to third party because we called stop() function on nftDetectionController. It does not fix this scenario: 1- User imports MM wallet 2- User enabled nft detection toggle 3- User closes chrome all together 4- User reopens chrome without opening MM, and we notice that it is making calls in the background to third party even though MM is not open. This behavior was happening because of a couple of reasons; the property `disabled` being set to `true` in `defaultConfig` ``` this.defaultConfig = { interval: DEFAULT_INTERVAL, chainId: initialChainId, selectedAddress: '', disabled: true, }; ``` made the check on this line pass https://github.com/MetaMask/core/blob/15518442513fbeaade83e4993851acdc1f038e4a/packages/assets-controllers/src/NftDetectionController.ts#L480 and triggered the `start()` function (because the useNftDetection is true). I fixed this by having extension pass the `disabled` in the contructor rather than having the `true` value hardcoded in the controller. I have also refactored the `onPreferencesStateChange` to have it make this check ``` if(selectedAddress !== previouslySelectedAddress){ this.configure({ selectedAddress }); } ``` Separately. When the user first opens the selectedAddress is '' because its also set in default config which, because of the `OR` statement triggered the code to also go into the `start()` ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? For example: * Related to [#67890](https://github.com/MetaMask/metamask-extension/pull/24026/files#diff-6fbff2cfe97ac01b77296ef2122c7e0a5b3ff6a84b584b4d1a87482f35eea3d6) --> ## Changelog <!-- If you're making any consumer-facing changes, list those changes here as if you were updating a changelog, using the template below as a guide. (CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or FIXED. For security-related issues, follow the Security Advisory process.) Please take care to name the exact pieces of the API you've added or changed (e.g. types, interfaces, functions, or methods). If there are any breaking changes, make sure to offer a solution for consumers to follow once they upgrade to the changes. Finally, if you're only making changes to development scripts or tests, you may replace the template below with "None". --> ### `@metamask/assets-controllers` - **ADDED**: Added disabled inside contructor of nftDetectionController - **CHANGED**: Pass new disabled value instead of true in the default config - **CHANGED**: Made the check for the selected address separate from the check of useNftDetection value ## Checklist - [ ] I've updated the test suite for new or updated code as appropriate - [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [ ] I've highlighted breaking changes using the "BREAKING" category above as appropriate
Description
Once nftDetection is enabled by the user, the nftDetection controller will start polling data in the background every 3 min even if the user closes the metamask popup or the tab.
We want to stop unnecessary polling when MM is closed in an attempt to reduce traffic.
Related issues
Related to: MetaMask/core#4178
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist