Skip to content

Commit 67fcea3

Browse files
sahar-fehribergarcesjuanmigdr
authored
chore: prioritize price-api for currencyRateController exchange rates… (#36986)
## **Description** PR to introduce fetching exchangeRates from price api and fallback to crypto compare. Do not merge until this goes in MetaMask/core#6863 [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/36986?quickstart=1) ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: null ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> https://github.com/user-attachments/assets/a8dc4ac7-9810-48a5-8fdd-19f0bc9f8b92 ### **After** <!-- [screenshots/recordings] --> https://github.com/user-attachments/assets/dcb1c517-5b9c-464d-aa27-853c7c99a781 ## **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/main/.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 - [X] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [X] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.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. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Integrates Codefi price API into `CurrencyRateController` and includes multichain asset state in balance calculations; wires `allIgnoredAssets` across state/Sentry and bumps key deps. > > - **Rates/Controller Init**: > - Inject `CodefiTokenPricesServiceV2` into `CurrencyRateController` via `tokenPricesService`; update init and tests/mocks. > - **Selectors/Balances**: > - Add `getAllIgnoredAssets` and include `{ accountsAssets, assetsMetadata, allIgnoredAssets }` in balance and balance-change selectors (`selectBalanceForAllWallets`, etc.). > - **State/Telemetry**: > - Add `metamask.allIgnoredAssets` to app state, Sentry background/UI masks, mock states, and snapshots. > - **Dependencies**: > - Bump `@metamask/assets-controllers` to `^85.0.0` and `@metamask/controller-utils` to `^11.15.0`; remove yarn patch for controller-utils and lockfile updates. > - **Misc**: > - Update storybook test data and integration/e2e fixtures to include `allIgnoredAssets`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 3ad4311. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Bernardo Garces Chapero <[email protected]> Co-authored-by: juanmigdr <[email protected]>
1 parent ca58ee1 commit 67fcea3

18 files changed

+116
-313
lines changed

.storybook/test-data.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ const state = {
690690
],
691691
accountsAssets: {},
692692
assetsMetadata: {},
693+
allIgnoredAssets: {},
693694
balances: {},
694695
conversionRates: {},
695696
networkConfigurationsByChainId: {},

.yarn/patches/@metamask-controller-utils-npm-11.14.1-15745fecdc.patch

Lines changed: 0 additions & 261 deletions
This file was deleted.

app/scripts/constants/sentry-state.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export const SENTRY_BACKGROUND_STATE = {
102102
MultichainAssetsController: {
103103
accountsAssets: false,
104104
assetsMetadata: false,
105+
allIgnoredAssets: false,
105106
},
106107
MultichainAssetsRatesController: {
107108
assetsRates: false,

app/scripts/controller-init/currency-rate-controller-init.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { CurrencyRateController } from '@metamask/assets-controllers';
1+
import {
2+
CodefiTokenPricesServiceV2,
3+
CurrencyRateController,
4+
} from '@metamask/assets-controllers';
25
import { getRootMessenger } from '../lib/messenger';
36
import { ControllerInitRequest } from './types';
47
import { buildControllerInitRequestMock } from './test/utils';
@@ -15,6 +18,15 @@ jest.mock('@metamask/assets-controllers', () => ({
1518
// This is needed since the controller init tries to override this function.
1619
fetchMultiExchangeRate = jest.fn();
1720
},
21+
CodefiTokenPricesServiceV2: class {
22+
fetchTokenPrices = jest.fn();
23+
24+
fetchExchangeRates = jest.fn();
25+
26+
validateChainIdSupported = jest.fn();
27+
28+
validateCurrencySupported = jest.fn();
29+
},
1830
}));
1931

2032
function getInitRequestMock(): jest.Mocked<
@@ -29,6 +41,7 @@ function getInitRequestMock(): jest.Mocked<
2941
...buildControllerInitRequestMock(),
3042
controllerMessenger: getCurrencyRateControllerMessenger(baseMessenger),
3143
initMessenger: getCurrencyRateControllerInitMessenger(baseMessenger),
44+
tokenPricesService: new CodefiTokenPricesServiceV2(),
3245
};
3346

3447
return requestMock;

app/scripts/controller-init/currency-rate-controller-init.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { CurrencyRateController } from '@metamask/assets-controllers';
1+
import {
2+
CodefiTokenPricesServiceV2,
3+
CurrencyRateController,
4+
} from '@metamask/assets-controllers';
25
import {
36
CurrencyRateControllerInitMessenger,
47
CurrencyRateControllerMessenger,
@@ -28,6 +31,7 @@ export const CurrencyRateControllerInit: ControllerInitFunction<
2831
includeUsdRate: true,
2932
useExternalServices: () =>
3033
initMessenger.call('PreferencesController:getState').useExternalServices,
34+
tokenPricesService: new CodefiTokenPricesServiceV2(),
3135
});
3236

3337
// TODO: This logic should be ported to `CurrencyRateController` directly.

package.json

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,7 @@
241241
"@endo/env-options@npm:^1.1.11": "patch:@endo/env-options@npm%3A1.1.11#~/.yarn/patches/@endo-env-options-npm-1.1.11-1b7fae374a.patch",
242242
"@endo/env-options@npm:^1.1.7": "patch:@endo/env-options@npm%3A1.1.11#~/.yarn/patches/@endo-env-options-npm-1.1.11-1b7fae374a.patch",
243243
"@endo/env-options@npm:^1.1.8": "patch:@endo/env-options@npm%3A1.1.11#~/.yarn/patches/@endo-env-options-npm-1.1.11-1b7fae374a.patch",
244-
"@metamask/jazzicon@npm:^2.0.0": "patch:@metamask/jazzicon@npm%3A2.0.0#~/.yarn/patches/@metamask-jazzicon-npm-2.0.0-36957be38d.patch",
245-
"@metamask/controller-utils@npm:^11.14.1": "patch:@metamask/controller-utils@npm%3A11.14.1#~/.yarn/patches/@metamask-controller-utils-npm-11.14.1-15745fecdc.patch",
246-
"@metamask/controller-utils@npm:^11.9.0": "patch:@metamask/controller-utils@npm%3A11.14.1#~/.yarn/patches/@metamask-controller-utils-npm-11.14.1-15745fecdc.patch",
247-
"@metamask/controller-utils@npm:^11.5.0": "patch:@metamask/controller-utils@npm%3A11.14.1#~/.yarn/patches/@metamask-controller-utils-npm-11.14.1-15745fecdc.patch",
248-
"@metamask/controller-utils@npm:^11.11.0": "patch:@metamask/controller-utils@npm%3A11.14.1#~/.yarn/patches/@metamask-controller-utils-npm-11.14.1-15745fecdc.patch",
249-
"@metamask/controller-utils@npm:^11.14.0": "patch:@metamask/controller-utils@npm%3A11.14.1#~/.yarn/patches/@metamask-controller-utils-npm-11.14.1-15745fecdc.patch",
250-
"@metamask/controller-utils@npm:^11.12.0": "patch:@metamask/controller-utils@npm%3A11.14.1#~/.yarn/patches/@metamask-controller-utils-npm-11.14.1-15745fecdc.patch",
251-
"@metamask/controller-utils@npm:^11.3.0": "patch:@metamask/controller-utils@npm%3A11.14.1#~/.yarn/patches/@metamask-controller-utils-npm-11.14.1-15745fecdc.patch",
252-
"@metamask/controller-utils@npm:^11.0.0": "patch:@metamask/controller-utils@npm%3A11.14.1#~/.yarn/patches/@metamask-controller-utils-npm-11.14.1-15745fecdc.patch"
244+
"@metamask/jazzicon@npm:^2.0.0": "patch:@metamask/jazzicon@npm%3A2.0.0#~/.yarn/patches/@metamask-jazzicon-npm-2.0.0-36957be38d.patch"
253245
},
254246
"dependencies": {
255247
"@babel/runtime": "patch:@babel/runtime@npm%3A7.25.9#~/.yarn/patches/@babel-runtime-npm-7.25.9-fe8c62510a.patch",
@@ -277,15 +269,15 @@
277269
"@metamask/address-book-controller": "^7.0.0",
278270
"@metamask/announcement-controller": "^8.0.0",
279271
"@metamask/approval-controller": "^8.0.0",
280-
"@metamask/assets-controllers": "^84.0.0",
272+
"@metamask/assets-controllers": "^85.0.0",
281273
"@metamask/base-controller": "^9.0.0",
282274
"@metamask/bitcoin-wallet-snap": "^1.3.0",
283275
"@metamask/bridge-controller": "^56.0.0",
284276
"@metamask/bridge-status-controller": "^56.0.0",
285277
"@metamask/browser-passworder": "^4.3.0",
286278
"@metamask/chain-agnostic-permission": "^1.2.2",
287279
"@metamask/contract-metadata": "^2.5.0",
288-
"@metamask/controller-utils": "patch:@metamask/controller-utils@npm%3A11.14.1#~/.yarn/patches/@metamask-controller-utils-npm-11.14.1-15745fecdc.patch",
280+
"@metamask/controller-utils": "^11.15.0",
289281
"@metamask/core-backend": "^4.0.0",
290282
"@metamask/delegation-controller": "^1.0.0",
291283
"@metamask/delegation-core": "^0.2.0-rc.1",

shared/types/background.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ export type ControllerStatePropertiesEnumerated = {
196196
historicalPrices: MultichainAssetsRatesControllerState['historicalPrices'];
197197
assetsMetadata: MultichainAssetsControllerState['assetsMetadata'];
198198
accountsAssets: MultichainAssetsControllerState['accountsAssets'];
199+
allIgnoredAssets: MultichainAssetsControllerState['allIgnoredAssets'];
199200
multichainNetworkConfigurationsByChainId: MultichainNetworkControllerState['multichainNetworkConfigurationsByChainId'];
200201
selectedMultichainNetworkChainId: MultichainNetworkControllerState['selectedMultichainNetworkChainId'];
201202
isEvmSelected: MultichainNetworkControllerState['isEvmSelected'];

test/data/mock-state.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,6 +2340,8 @@
23402340
"throttledOrigins": {},
23412341
"delegations": {},
23422342
"accountsAssets": {},
2343+
"assetsMetadata": {},
2344+
"allIgnoredAssets": {},
23432345
"gatorPermissionsMapSerialized": "{\"native-token-stream\":{},\"native-token-periodic\":{},\"erc20-token-stream\":{},\"erc20-token-periodic\":{},\"other\":{}}",
23442346
"isGatorPermissionsEnabled": false,
23452347
"isFetchingGatorPermissions": false,

test/e2e/fixtures/onboarding-fixture.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@
201201
},
202202
"MultichainAssetsController": {
203203
"accountsAssets": {},
204-
"assetsMetadata": {}
204+
"assetsMetadata": {},
205+
"allIgnoredAssets": {}
205206
},
206207
"MultichainAssetsRatesController": {
207208
"conversionRates": {}

test/e2e/tests/metrics/errors.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,7 @@ describe('Sentry errors', function () {
904904
balances: false,
905905
accountsAssets: false,
906906
assetsMetadata: false,
907+
allIgnoredAssets: false,
907908
assetsRates: false,
908909
smartTransactionsState: {
909910
fees: {

0 commit comments

Comments
 (0)