-
-
Notifications
You must be signed in to change notification settings - Fork 188
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
Use PollingController
in CurrencyRateController
and key by nativeCurrency
#1805
Conversation
…p-1025/multichain-v1-currency-rate-controller # Conflicts: # packages/network-controller/src/NetworkController.ts # packages/network-controller/tests/NetworkController.test.ts
…p-1025/multichain-v1-currency-rate-controller
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
@metamaskbot publish-preview |
@metamaskbot publish-preview |
@metamaskbot publish-preview |
…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>
There was a problem hiding this 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, |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
send it
…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>
## **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.
## **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.
## **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.
## **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.
## **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.
## **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.
## **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.
## **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.
…#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>
…#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>
…#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>
Explanation
Currently the CurrencyRateController only supports a single nativeCurrency (ticker) to be polled at a time. Additionally, it uses an odd notion of
pendingNativeCurrency
andpendingCurrentCurrency
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
CurrencyRateController
is now keyed bynativeCurrency
(i.e. ticker) forconversionDate
,conversionRate
, andusdConversionRate
in thecurrencyRates
object.nativeCurrency
,pendingNativeCurrency
, andpendingCurrentCurrency
have been removed.CurrencyRateController
now extendsPollingController
start()
andstop()
methods replaced withstartPollingByNetworkClientId()
,stopPollingByPollingToken()
, andstopAllPolling()
CurrencyRateController
now sends theNetworkController:getNetworkClientById
action via messaging controllerChecklist