Skip to content

fix: Prevent network request when useCurrencyRateCheck is false#24888

Merged
danjm merged 3 commits intodevelopfrom
disable-crypto-compare-requests
May 30, 2024
Merged

fix: Prevent network request when useCurrencyRateCheck is false#24888
danjm merged 3 commits intodevelopfrom
disable-crypto-compare-requests

Conversation

@danjm
Copy link
Copy Markdown
Contributor

@danjm danjm commented May 29, 2024

Description

With MetaMask/core#1805, polling in the CurrencyRateController happens when the controller is initialized. Once the extension received an update to use the version containing those changes, we started making cryptocompare network requests even when the "Show balance and token price checker" toggle is off.

This PR prevents those requests when that toggle is off by wrapping the fetchExchangeRates method of the CurrencyRateController with a function that will just return 0 values if that toggle is off.

Open in GitHub Codespaces

Manual testing steps

  1. Install and build and onboard
  2. See requests to cryptocompare in the background console
  3. Toggle off "Show balance and token price checker"
  4. Reload the extension, there should be no requests to cryptocompare
  5. Switch networks, there should be no requests to cryptocompare

1, Install and onboard
2. Toggle off "Show balance and token price checker" in advanced settings during onboarding
3. There should be not requests to cryptocompare after onboarding

For either of the above scenarios, toggle "Show balance and token price checker" back on. There should now be requests to cryptocompare

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've completed the PR template to the best of my ability
  • 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.

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.

@danjm danjm requested a review from a team as a code owner May 29, 2024 23:52
@github-actions
Copy link
Copy Markdown
Contributor

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.

@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label May 29, 2024
Comment on lines +821 to +822
conversionRate: 0,
usdConversionRate: 0,
Copy link
Copy Markdown
Contributor

@legobeat legobeat May 30, 2024

Choose a reason for hiding this comment

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

Suggested change
conversionRate: 0,
usdConversionRate: 0,
conversionRate: null,
usdConversionRate: null,

Can we handle non-numeric values? Anything to allow differentiating rates not being available from actual 0 would be useful? "Your tokens are worth 0" is different from "No price data for your tokens available"

null/undefined/NaN.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

addressed in 06a9a9c

Copy link
Copy Markdown
Contributor

@legobeat legobeat left a comment

Choose a reason for hiding this comment

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

Good catch and thanks for preparing a fix!

How involved would it be to couple this with a regression test?

@danjm danjm changed the title Prevent network request when useCurrencyRateCheck is false fix: Prevent network request when useCurrencyRateCheck is false May 30, 2024
@danjm danjm added the team-extension-platform Extension Platform team label May 30, 2024
@danjm danjm force-pushed the disable-crypto-compare-requests branch from 04ae9fd to 4ebb97d Compare May 30, 2024 15:48
@danjm
Copy link
Copy Markdown
Contributor Author

danjm commented May 30, 2024

@legobeat I added a regression test as well

@codecov
Copy link
Copy Markdown

codecov bot commented May 30, 2024

Codecov Report

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

Project coverage is 65.78%. Comparing base (7284160) to head (4ebb97d).
Report is 1 commits behind head on develop.

Files Patch % Lines
app/scripts/metamask-controller.js 50.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #24888      +/-   ##
===========================================
+ Coverage    65.74%   65.78%   +0.04%     
===========================================
  Files         1363     1363              
  Lines        54272    54244      -28     
  Branches     14109    14109              
===========================================
+ Hits         35676    35680       +4     
+ Misses       18596    18564      -32     

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

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [4ebb97d]
Page Load Metrics (875 ± 526 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint662071053718
domContentLoaded94317105
load5425748751095526
domInteractive94317105
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 262 Bytes (0.01%)
  • ui: 40 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Copy link
Copy Markdown
Contributor

@NiranjanaBinoy NiranjanaBinoy left a comment

Choose a reason for hiding this comment

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

LGTM

@danjm danjm merged commit 4882eb9 into develop May 30, 2024
@danjm danjm deleted the disable-crypto-compare-requests branch May 30, 2024 17:42
@github-actions github-actions bot locked and limited conversation to collaborators May 30, 2024
@metamaskbot metamaskbot added release-11.18.0 release-11.16.6 Issue or pull request that will be included in release 11.16.6 and removed release-11.18.0 labels May 30, 2024
@metamaskbot
Copy link
Copy Markdown
Collaborator

Missing release label release-11.16.6 on PR. Adding release label release-11.16.6 on PR and removing other release labels(release-11.18.0), as PR was cherry-picked in branch 11.16.6.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-privacy INVALID-PR-TEMPLATE PR's body doesn't match template release-11.16.6 Issue or pull request that will be included in release 11.16.6 team-extension-platform Extension Platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants