-
-
Notifications
You must be signed in to change notification settings - Fork 278
fix(assets-controller): hardened error handling #8294
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| parseCaipAssetType, | ||
| } from '@metamask/utils'; | ||
| import type { CaipAssetType } from '@metamask/utils'; | ||
| import pLimit from 'p-limit'; | ||
|
|
||
| import { isStakingContractAssetId } from './evm-rpc-services'; | ||
| import type { AssetsControllerMessenger } from '../AssetsController'; | ||
|
|
@@ -29,6 +30,14 @@ | |
|
|
||
| const CONTROLLER_NAME = 'TokenDataSource'; | ||
|
|
||
| /** Tokens API `/v3/assets` accepts at most this many `assetIds` per request. */ | ||
| const V3_ASSETS_MAX_IDS_PER_REQUEST = 120; | ||
|
|
||
| /** Max concurrent `/v3/assets` chunk requests (same default scale as balance middleware). */ | ||
| const V3_ASSETS_FETCH_CONCURRENCY = 3; | ||
|
|
||
| const MIN_TOKEN_OCCURRENCES = 3; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused
|
||
|
|
||
| const log = createModuleLogger(projectLogger, CONTROLLER_NAME); | ||
|
|
||
| /** Max tokens per PhishingController:bulkScanTokens request (see PhishingController). */ | ||
|
|
@@ -369,20 +378,38 @@ | |
| } | ||
|
|
||
| try { | ||
| // Use ApiPlatformClient for fetching asset metadata | ||
| // API returns an array with assetId as a property on each item | ||
| const metadataResponse = await this.#apiClient.tokens.fetchV3Assets( | ||
| supportedAssetIds, | ||
| { | ||
| includeIconUrl: true, | ||
| includeMarketData: true, | ||
| includeMetadata: true, | ||
| includeLabels: true, | ||
| includeRwaData: true, | ||
| includeAggregators: true, | ||
| includeOccurrences: true, | ||
| }, | ||
| const metadataQueryOptions = { | ||
| includeIconUrl: true, | ||
| includeMarketData: true, | ||
| includeMetadata: true, | ||
| includeLabels: true, | ||
| includeRwaData: true, | ||
| includeAggregators: true, | ||
| includeOccurrences: true, | ||
| }; | ||
|
|
||
| // API returns an array with assetId as a property on each item. | ||
| // Request in chunks to stay within the per-request asset ID limit. | ||
| const chunks: string[][] = []; | ||
| for ( | ||
| let i = 0; | ||
| i < supportedAssetIds.length; | ||
| i += V3_ASSETS_MAX_IDS_PER_REQUEST | ||
| ) { | ||
| chunks.push( | ||
| supportedAssetIds.slice(i, i + V3_ASSETS_MAX_IDS_PER_REQUEST), | ||
| ); | ||
| } | ||
|
|
||
| const limit = pLimit(V3_ASSETS_FETCH_CONCURRENCY); | ||
| const chunkResponses = await Promise.all( | ||
| chunks.map((chunk) => | ||
| limit(() => | ||
| this.#apiClient.tokens.fetchV3Assets(chunk, metadataQueryOptions), | ||
| ), | ||
| ), | ||
| ); | ||
| const metadataResponse = chunkResponses.flat(); | ||
|
|
||
| const assetIdsFromApi = metadataResponse.map((a) => a.assetId); | ||
| const allowedAssetIds = new Set( | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.