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

Use PollingController in CurrencyRateController and key by nativeCurrency #1805

Merged
merged 43 commits into from
Oct 31, 2023

Conversation

jiexi
Copy link
Contributor

@jiexi jiexi commented Oct 11, 2023

Explanation

Currently the CurrencyRateController only supports a single nativeCurrency (ticker) to be polled at a time. Additionally, it uses an odd notion of pendingNativeCurrency and pendingCurrentCurrency which are used as intermediary flags for the goal of ultimately fetching the new conversion rate for the NativeCurrency (fiat) to CurrentCurrency (ticker) pair.

We need to add support for multiple tickers being polled concurrently. This is achieved by using the PollingController and changing the conversion rates to be keyed by ticker. Additionally, changing the currentCurrency now clears the existing conversion rate state until it is refetched (which gets rid of the need for pendingCurrentCurrency).

References

See https://github.com/MetaMask/MetaMask-planning/issues/1025

Changelog

@metamask/assets-controllers

  • BREAKING: CurrencyRateController is now keyed by nativeCurrency (i.e. ticker) for conversionDate, conversionRate, and usdConversionRate in the currencyRates object. nativeCurrency, pendingNativeCurrency, and pendingCurrentCurrency have been removed.
    • export type CurrencyRateState = {
        currentCurrency: string;
        currencyRates: Record<
          string,
          {
            conversionDate: number | null;
            conversionRate: number | null;
            usdConversionRate: number | null;
          }
        >;
      };
      
  • BREAKING: CurrencyRateController now extends PollingController
    • start() and stop() methods replaced with startPollingByNetworkClientId(), stopPollingByPollingToken(), and stopAllPolling()
  • BREAKING: CurrencyRateController now sends the NetworkController:getNetworkClientById action via messaging controller

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

@jiexi
Copy link
Contributor Author

jiexi commented Oct 11, 2023

@metamaskbot publish-preview

@github-actions
Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "2.0.2-preview.7cc5454",
  "@metamask-previews/address-book-controller": "3.1.4-preview.7cc5454",
  "@metamask-previews/announcement-controller": "4.0.2-preview.7cc5454",
  "@metamask-previews/approval-controller": "4.0.0-preview.7cc5454",
  "@metamask-previews/assets-controllers": "15.0.0-preview.7cc5454",
  "@metamask-previews/base-controller": "3.2.3-preview.7cc5454",
  "@metamask-previews/composable-controller": "3.0.2-preview.7cc5454",
  "@metamask-previews/controller-utils": "5.0.2-preview.7cc5454",
  "@metamask-previews/ens-controller": "5.0.2-preview.7cc5454",
  "@metamask-previews/gas-fee-controller": "8.0.0-preview.7cc5454",
  "@metamask-previews/keyring-controller": "8.0.2-preview.7cc5454",
  "@metamask-previews/logging-controller": "1.0.3-preview.7cc5454",
  "@metamask-previews/message-manager": "7.3.5-preview.7cc5454",
  "@metamask-previews/name-controller": "3.0.1-preview.7cc5454",
  "@metamask-previews/network-controller": "14.0.0-preview.7cc5454",
  "@metamask-previews/notification-controller": "3.1.3-preview.7cc5454",
  "@metamask-previews/permission-controller": "5.0.0-preview.7cc5454",
  "@metamask-previews/phishing-controller": "7.0.0-preview.7cc5454",
  "@metamask-previews/polling-controller": "0.1.0-preview.7cc5454",
  "@metamask-previews/preferences-controller": "4.4.2-preview.7cc5454",
  "@metamask-previews/rate-limit-controller": "3.0.2-preview.7cc5454",
  "@metamask-previews/selected-network-controller": "2.0.1-preview.7cc5454",
  "@metamask-previews/signature-controller": "6.1.2-preview.7cc5454",
  "@metamask-previews/transaction-controller": "14.0.0-preview.7cc5454"
}

Base automatically changed from jl/network-controller-configurations-ticker to main October 13, 2023 18:11
@jiexi
Copy link
Contributor Author

jiexi commented Oct 13, 2023

@metamaskbot publish-preview

@jiexi
Copy link
Contributor Author

jiexi commented Oct 13, 2023

@metamaskbot publish-preview

@jiexi
Copy link
Contributor Author

jiexi commented Oct 13, 2023

@metamaskbot publish-preview

jiexi added a commit that referenced this pull request Oct 24, 2023
…olling is currently active for the key on start (#1874)

## Explanation

Currently when PollingController polling is started via
`startPollingByNetworkClientId()`, the first poll execution doesn't
occur until `intervalLength` time has passed. Some controllers such as
the `CurrencyRateController` want to execute their polling logic
immediately on polling start that way it is available to the UI as soon
as possible. ~~This PR adds a `executeImmediately` flag to the
`PollingController`. When set to `true`, it causes `_executePoll()` to
immediately be called when `startPollingByNetworkClientId()` is called,
subsequently on each `intervalLength` time period. This value defaults
to false.~~ This PR updates `#poll()` to call `_executePoll()` if no
polling is currently active for the key

## References

* Related #1805

## Changelog

### `@metamask/polling-controller`

- **BREAKING**: `_executePoll()` is called immediately on start if no
polling interval is already active for the networkClientId + options
combination

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've highlighted breaking changes using the "BREAKING" category
above as appropriate

---------

Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
Co-authored-by: Alex <adonesky@gmail.com>
Copy link
Contributor

@adonesky1 adonesky1 left a comment

Choose a reason for hiding this comment

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

Looks right to me!

pendingNativeCurrency: string | null;
usdConversionRate: number | null;
currencyRates: Record<
string,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use an alias for the string, so that the type is self describing? Maybe something like the following:

// docs about what is native currency
type NativeCurrency = string;

...

    Record<
      NativeCurrency,
      {
         ...

*
* This stops any active polling.
*/
override destroy() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this is something that should be in the PollingController

}
nativeCurrencies.forEach(this.updateExchangeRate.bind(this));
Copy link
Contributor

Choose a reason for hiding this comment

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

This ends up being a lot of state updates right? Would it be be better to have updateExchangeRate return the updated rates, and we roll all the this.update into 1?

Also, What is the lock for? I presume its to prevent you from updating the current currency before the first update is complete, but then shouldnt the nativeCurrencies.forEach(this.updateExchangeRate.bind(this)); be inside the lock? (and awaited / promise.all'd)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be be better to have updateExchangeRate return the updated rates, and we roll all the this.update into 1

Do you mean replacing the updateExchangeRate calls with a fetchExchangeRate call here in the loop and then updating manually... We might want to refactor these methods a bit if we wanted to take this approach. Not sure how much performance it buys us.

Copy link
Contributor

@BelfordZ BelfordZ left a comment

Choose a reason for hiding this comment

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

send it

@adonesky1 adonesky1 merged commit 93770f1 into main Oct 31, 2023
115 checks passed
@adonesky1 adonesky1 deleted the jl/mmp-1025/multichain-v1-currency-rate-controller branch October 31, 2023 20:58
mcmire pushed a commit that referenced this pull request Nov 2, 2023
…Currency (#1805)

## Explanation

Currently the CurrencyRateController only supports a single
nativeCurrency (ticker) to be polled at a time. Additionally, it uses an
odd notion of `pendingNativeCurrency` and `pendingCurrentCurrency` which
are used as intermediary flags for the goal of ultimately fetching the
new conversion rate for the NativeCurrency (fiat) to CurrentCurrency
(ticker) pair.

We need to add support for multiple tickers being polled concurrently.
This is achieved by using the PollingController and changing the
conversion rates to be keyed by ticker. Additionally, changing the
currentCurrency now clears the existing conversion rate state until it
is refetched (which gets rid of the need for pendingCurrentCurrency).

 
## References

See MetaMask/MetaMask-planning#1025

## 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`

- **BREAKING**: `CurrencyRateController` is now keyed by
`nativeCurrency` (i.e. ticker) for `conversionDate`, `conversionRate`,
and `usdConversionRate` in the `currencyRates` object. `nativeCurrency`,
`pendingNativeCurrency`, and `pendingCurrentCurrency` have been removed.
  - ```
    export type CurrencyRateState = {
      currentCurrency: string;
      currencyRates: Record<
        string,
        {
          conversionDate: number | null;
          conversionRate: number | null;
          usdConversionRate: number | null;
        }
      >;
    };
    ```
- **BREAKING**: `CurrencyRateController` now extends `PollingController`
- `start()` and `stop()` methods replaced with
`startPollingByNetworkClientId()`, `stopPollingByPollingToken()`, and
`stopAllPolling()`
- **BREAKING**: `CurrencyRateController` now sends the
`NetworkController:getNetworkClientById` action via messaging controller


## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've highlighted breaking changes using the "BREAKING" category
above as appropriate

---------

Co-authored-by: Alex Donesky <adonesky@gmail.com>
danjm added a commit to MetaMask/metamask-extension that referenced this pull request May 30, 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](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/24888?quickstart=1)

## **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](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] 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](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.

## **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 added a commit to MetaMask/metamask-extension that referenced this pull request May 31, 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](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/24888?quickstart=1)

## **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](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] 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](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.

## **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 added a commit to MetaMask/metamask-extension that referenced this pull request May 31, 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](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/24888?quickstart=1)

## **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](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] 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](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.

## **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 added a commit to MetaMask/metamask-extension that referenced this pull request May 31, 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](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/24888?quickstart=1)

## **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](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] 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](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.

## **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 added a commit to MetaMask/metamask-extension that referenced this pull request May 31, 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](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/24888?quickstart=1)

## **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](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] 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](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.

## **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 added a commit to MetaMask/metamask-extension that referenced this pull request May 31, 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](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/24888?quickstart=1)

## **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](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] 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](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.

## **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 added a commit to MetaMask/metamask-extension that referenced this pull request Jun 4, 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](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/24888?quickstart=1)

## **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](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] 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](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.

## **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 added a commit to MetaMask/metamask-extension that referenced this pull request Jun 4, 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](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/24888?quickstart=1)

## **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](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] 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](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.

## **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 added a commit to MetaMask/metamask-extension that referenced this pull request Aug 13, 2024
…#26383)

## **Description**

We are seeing the following sorts of errors in production, as reported
by sentry, in v12.0.2:
`No metadata found for 'conversionDate'`
`No metadata found for 'usdConversionRate'`
`No metadata found for 'nativeCurrency'`
`No metadata found for 'conversionRate'`

Example issue:
https://metamask.sentry.io/issues/5682684113/events/b8006eebb65749f883e907242e52215b/?project=273505&query=is%3Aunresolved+issue.priority%3A%5Bhigh%2C+medium%5D+No+metadata+release%3A12.0.1&referrer=previous-event&statsPeriod=14d&stream_index=1

The `CurrencyRateController` stopped using six such properties with
MetaMask/core#1805, which was brought into the
extension with #21549, however, there was not a state migration to
delete those properties at the time

This PR adds migrations to delete those obsolete properties

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

## **Related issues**

Fixes: #26356

## **Manual testing steps**

To observe the error using steps that mimic users in production
1. Install v11.6.0 and onboard
2. Create a local dev build from the `master` branch
3. Update the v11.6.0 install to the local dev build
4. See the errors in the service worker console

If you repeat those steps, but in step two build from this branch
instead of the `master` branch, the errors will not occur

For a faster manual test of this PR, create a local development build of
this branch and then run this script in the service worker console:
```
window.chrome.storage.local.get(({ data, meta }) => chrome.storage.local.set({ data: { ...data, CurrencyController: { ...data.CurrencyController, conversionDate: 'Jan 1', conversionRate: '2', nativeCurrency: 'test' } }, meta: {...meta, version: 120 } }, () => { chrome.runtime.reload() }))
```
There should be no errors like `No metadata found for 'conversionRate'`
(but if you do the same on develop or master, those errors should be
present)

## **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**

- [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
- [ ] 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.

## **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.

---------

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
danjm added a commit to MetaMask/metamask-extension that referenced this pull request Aug 13, 2024
…#26383)

We are seeing the following sorts of errors in production, as reported
by sentry, in v12.0.2:
`No metadata found for 'conversionDate'`
`No metadata found for 'usdConversionRate'`
`No metadata found for 'nativeCurrency'`
`No metadata found for 'conversionRate'`

Example issue:
https://metamask.sentry.io/issues/5682684113/events/b8006eebb65749f883e907242e52215b/?project=273505&query=is%3Aunresolved+issue.priority%3A%5Bhigh%2C+medium%5D+No+metadata+release%3A12.0.1&referrer=previous-event&statsPeriod=14d&stream_index=1

The `CurrencyRateController` stopped using six such properties with
MetaMask/core#1805, which was brought into the
extension with #21549, however, there was not a state migration to
delete those properties at the time

This PR adds migrations to delete those obsolete properties

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

Fixes: #26356

To observe the error using steps that mimic users in production
1. Install v11.6.0 and onboard
2. Create a local dev build from the `master` branch
3. Update the v11.6.0 install to the local dev build
4. See the errors in the service worker console

If you repeat those steps, but in step two build from this branch
instead of the `master` branch, the errors will not occur

For a faster manual test of this PR, create a local development build of
this branch and then run this script in the service worker console:
```
window.chrome.storage.local.get(({ data, meta }) => chrome.storage.local.set({ data: { ...data, CurrencyController: { ...data.CurrencyController, conversionDate: 'Jan 1', conversionRate: '2', nativeCurrency: 'test' } }, meta: {...meta, version: 120 } }, () => { chrome.runtime.reload() }))
```
There should be no errors like `No metadata found for 'conversionRate'`
(but if you do the same on develop or master, those errors should be
present)

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

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

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

- [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
- [ ] 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 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.

---------

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
Gudahtt added a commit to MetaMask/metamask-extension that referenced this pull request Aug 13, 2024
…#26383)

We are seeing the following sorts of errors in production, as reported
by sentry, in v12.0.2:
`No metadata found for 'conversionDate'`
`No metadata found for 'usdConversionRate'`
`No metadata found for 'nativeCurrency'`
`No metadata found for 'conversionRate'`

Example issue:
https://metamask.sentry.io/issues/5682684113/events/b8006eebb65749f883e907242e52215b/?project=273505&query=is%3Aunresolved+issue.priority%3A%5Bhigh%2C+medium%5D+No+metadata+release%3A12.0.1&referrer=previous-event&statsPeriod=14d&stream_index=1

The `CurrencyRateController` stopped using six such properties with
MetaMask/core#1805, which was brought into the
extension with #21549, however, there was not a state migration to
delete those properties at the time

This PR adds migrations to delete those obsolete properties

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

Fixes: #26356

To observe the error using steps that mimic users in production
1. Install v11.6.0 and onboard
2. Create a local dev build from the `master` branch
3. Update the v11.6.0 install to the local dev build
4. See the errors in the service worker console

If you repeat those steps, but in step two build from this branch
instead of the `master` branch, the errors will not occur

For a faster manual test of this PR, create a local development build of
this branch and then run this script in the service worker console:
```
window.chrome.storage.local.get(({ data, meta }) => chrome.storage.local.set({ data: { ...data, CurrencyController: { ...data.CurrencyController, conversionDate: 'Jan 1', conversionRate: '2', nativeCurrency: 'test' } }, meta: {...meta, version: 120 } }, () => { chrome.runtime.reload() }))
```
There should be no errors like `No metadata found for 'conversionRate'`
(but if you do the same on develop or master, those errors should be
present)

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

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

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

- [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
- [ ] 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 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.

---------

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants