diff --git a/packages/assets-controllers/CHANGELOG.md b/packages/assets-controllers/CHANGELOG.md index 53620ec7f9c..4bb92683351 100644 --- a/packages/assets-controllers/CHANGELOG.md +++ b/packages/assets-controllers/CHANGELOG.md @@ -43,6 +43,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **BREAKING:** Standardize names of `AccountTrackerController` messenger action types ([#8164](https://github.com/MetaMask/core/pull/8164)) - All existing types for messenger actions have been renamed so they include `Controller` (e.g. `AccountTrackerUpdateNativeBalancesAction` -> `AccountTrackerControllerUpdateNativeBalancesAction`). You will need to update imports appropriately. - This change only affects the types. The action type strings themselves have not changed, so you do not need to update the list of actions you pass when initializing `AccountTrackerController` messengers. +- Remove hardcoded `supportedNftDetectionNetworks` chain allowlist from `NftDetectionController`; the NFT API now returns an empty array for unsupported chains instead of an error, so chain gating is no longer needed in the client ([#8180](https://github.com/MetaMask/core/pull/8180)) +- `NftDetectionController` now skips the NFT API call entirely when all provided chain IDs are non-EVM (decimal `0`), returning an empty result immediately ([#8180](https://github.com/MetaMask/core/pull/8180)) +- Update `ReservoirResponse.continuation` type from `string` to `string | null` to match the NFT API response shape ([#8180](https://github.com/MetaMask/core/pull/8180)) ### Fixed diff --git a/packages/assets-controllers/src/NftDetectionController.ts b/packages/assets-controllers/src/NftDetectionController.ts index 24a4ae70b44..528d2f35546 100644 --- a/packages/assets-controllers/src/NftDetectionController.ts +++ b/packages/assets-controllers/src/NftDetectionController.ts @@ -63,20 +63,6 @@ export type NftDetectionControllerMessenger = Messenger< AllowedEvents >; -/** - * Set of supported networks for NFT detection. - */ -const supportedNftDetectionNetworks: Set = new Set([ - '0x1', // Mainnet - '0x38', // BSC - '0x89', // Polygon - '0xa86a', // Avalanche - '0xe708', // Linea Mainnet - '0x2105', // Base - '0x531', // Sei - '0x8f', // Monad -]); - /** * @type ApiNft * @@ -188,7 +174,7 @@ export type ApiNftCreator = { export type ReservoirResponse = { tokens: TokensResponse[]; - continuation?: string; + continuation?: string | null; }; export type TokensResponse = { @@ -540,8 +526,21 @@ export class NftDetectionController extends BaseController< const convertedChainIds = chainIds.map((chainId) => convertHexToDecimal(chainId).toString(), ); + + const filteredChainIds = convertedChainIds.filter( + (chainId) => chainId !== '0', + ); + + // Avoid making the API call for non-EVM chains + if (filteredChainIds.length === 0) { + return { + tokens: [], + continuation: null, + }; + } + const url = this.#getOwnerNftApi({ - chainIds: convertedChainIds, + chainIds: filteredChainIds, address, next: cursor, }); @@ -575,12 +574,8 @@ export class NftDetectionController extends BaseController< options?.userAddress ?? this.messenger.call('AccountsController:getSelectedAccount').address; - // filter out unsupported chainIds - const supportedChainIds = chainIds.filter((chainId) => - supportedNftDetectionNetworks.has(chainId), - ); /* istanbul ignore if */ - if (supportedChainIds.length === 0 || this.#disabled) { + if (chainIds.length === 0 || this.#disabled) { return; } /* istanbul ignore else */ @@ -611,11 +606,7 @@ export class NftDetectionController extends BaseController< let resultNftApi: ReservoirResponse; try { do { - resultNftApi = await this.#getOwnerNfts( - userAddress, - supportedChainIds, - next, - ); + resultNftApi = await this.#getOwnerNfts(userAddress, chainIds, next); apiNfts = resultNftApi.tokens.filter( (elm) => elm.token.isSpam === false &&