Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/assets-controllers/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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 ([#8176](https://github.com/MetaMask/core/pull/8176))
- `NftDetectionController` now skips the NFT API call entirely when all provided chain IDs are non-EVM (decimal `0`), returning an empty result immediately ([#8176](https://github.com/MetaMask/core/pull/8176))
- Update `ReservoirResponse.continuation` type from `string` to `string | null` to match the NFT API response shape ([#8176](https://github.com/MetaMask/core/pull/8176))

### Fixed

Expand Down
43 changes: 17 additions & 26 deletions packages/assets-controllers/src/NftDetectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,6 @@ export type NftDetectionControllerMessenger = Messenger<
AllowedEvents
>;

/**
* Set of supported networks for NFT detection.
*/
const supportedNftDetectionNetworks: Set<Hex> = new Set([
'0x1', // Mainnet
'0x38', // BSC
'0x89', // Polygon
'0xa86a', // Avalanche
'0xe708', // Linea Mainnet
'0x2105', // Base
'0x531', // Sei
'0x8f', // Monad
]);

/**
* @type ApiNft
*
Expand Down Expand Up @@ -188,7 +174,7 @@ export type ApiNftCreator = {

export type ReservoirResponse = {
tokens: TokensResponse[];
continuation?: string;
continuation?: string | null;
};

export type TokensResponse = {
Expand Down Expand Up @@ -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,
});
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 &&
Expand Down
Loading