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(21895): stop polling token price request from coingecko #22123

Merged
merged 1 commit into from
Dec 4, 2023

Conversation

DDDDDanica
Copy link
Contributor

Description

There's a request to coingecko after extension is closed starting as https://api.coingecko.com/api/v3/simple/token_price/, and this is dispatched when

  • add a new token when auto token detection is enabled + have tokens in account
  • hard reload (reload from extensions management page) when auto token detection is enabled + have tokens in account

Tracing back to the request , it comes from const prices = await this.fetchExchangeRate(slug, nativeCurrency); inside TokenRatesController, which is called from updateExchangeRates, which will be polled with an interval of 3 mins. However, this polling request await safelyExecute(() => this.updateExchangeRates()); is not stopped when UI is closed as it is not found in stopNetworkRequests.

Hence the fix will be stopped the controller TokenRatesController which UI is closed, with the condition of useTokenDetection is enabled.

Related issues

Fixes: #21895

Manual testing steps

  1. Load MM and open backgound.html console
  2. Enable auto token detection
  3. Import 1 ~ many tokens
  4. See in the network there is a request to get token prices similar as
https://api.coingecko.com/api/v3/simple/token_price/ethereum?contract_addresses=0xC011a73ee8576Fb46F5E1c5751cA3B9Fe0af2a6F,0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9,0xfF20817765cB7f73d4bde2e66e067E58D11095C2&vs_currencies=eth
  1. Close MM extension
  2. Waited for at least 3 mins
  3. There is no request sent to coingecko any more

Screenshots/Recordings

Before

After

fetch-fix.mp4

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've clearly explained what problem this PR is solving and how it is solved.
  • I've linked related issues
  • I've included manual testing steps
  • I've included screenshots/recordings if applicable
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.
  • I’ve properly set the pull request status:
    • In case it's not yet "ready for review", I've set it to "draft".
    • In case it's "ready for review", I've changed it from "draft" to "non-draft".

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.

Copy link
Contributor

github-actions bot commented Dec 1, 2023

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.

Copy link

codecov bot commented Dec 1, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (f9e8054) 67.59% compared to head (413fd1b) 67.60%.
Report is 1 commits behind head on develop.

Files Patch % Lines
app/scripts/metamask-controller.js 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #22123      +/-   ##
===========================================
+ Coverage    67.59%   67.60%   +0.01%     
===========================================
  Files         1053     1053              
  Lines        40810    40804       -6     
  Branches     10941    10939       -2     
===========================================
  Hits         27584    27584              
+ Misses       13226    13220       -6     

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

@DDDDDanica DDDDDanica merged commit 0ea5e8b into develop Dec 4, 2023
72 checks passed
@DDDDDanica DDDDDanica deleted the fix/21895 branch December 4, 2023 14:25
@github-actions github-actions bot locked and limited conversation to collaborators Dec 4, 2023
@metamaskbot metamaskbot added the release-11.8.0 Issue or pull request that will be included in release 11.8.0 label Dec 4, 2023
DDDDDanica added a commit that referenced this pull request Dec 5, 2023
## **Description**

Cherry-pick features to stop pulling after UI is closed
#22123 and add
headers to request going to CoinGecko
#22151
See more info here:
https://consensys.slack.com/archives/C065W3877E3/p1701450197502839
<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

## **Related issues**

Fixes:

## **Manual testing steps**

Refer to #22123 and
#22151

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've clearly explained what problem this PR is solving and how it
is solved.
- [ ] I've linked related issues
- [ ] I've included manual testing steps
- [ ] I've included screenshots/recordings if applicable
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] 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 properly set the pull request status:
  - [ ] In case it's not yet "ready for review", I've set it to "draft".
- [ ] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

## **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.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-11.8.0 Issue or pull request that will be included in release 11.8.0 team-extension-platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

extension doesn't stop polling currency rates/token rates when the UI is closed
4 participants