@metamask-previews/assets-controllers 112.2.0-preview-4a8d4a2 → 112.2.0-preview-5669a8ae0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
16
16
 
17
17
  ### Changed
18
18
 
19
+ - **BREAKING:** `NftDetectionController` constructor now requires a `removeNft` option (type `NftController['removeNft']`); during detection, any NFT already in state that the API now returns as spam (`isSpam: true`) is automatically removed ([#8237](https://github.com/MetaMask/core/pull/8237))
20
+ - Callers must pass `removeNft: nftController.removeNft.bind(nftController)` (or equivalent) when constructing `NftDetectionController`
21
+ - NFTs whose stored `source` is `custom` (manual import) or `dapp` (approved dapp suggestion) are never auto-removed. Detected NFTs, and NFTs added before `source` was recorded, can be removed.
19
22
  - Bump `@metamask/utils` from `^12.0.0` to `^12.0.1` ([#11107](https://github.com/MetaMask/core/pull/11107))
20
23
 
21
24
  ## [112.2.0]
@@ -343,12 +343,14 @@ export declare class NftDetectionController extends BaseController<typeof contro
343
343
  * @param options.messenger - A reference to the messaging system.
344
344
  * @param options.disabled - Represents previous value of useNftDetection. Used to detect changes of useNftDetection. Default value is true.
345
345
  * @param options.addNfts - Add multiple NFTs.
346
+ * @param options.removeNft - Remove a single NFT.
346
347
  * @param options.getNftState - Gets the current state of the Assets controller.
347
348
  */
348
- constructor({ messenger, disabled, addNfts, getNftState, }: {
349
+ constructor({ messenger, disabled, addNfts, removeNft, getNftState, }: {
349
350
  messenger: NftDetectionControllerMessenger;
350
351
  disabled: boolean;
351
352
  addNfts: NftController['addNfts'];
353
+ removeNft: NftController['removeNft'];
352
354
  getNftState: () => NftControllerState;
353
355
  });
354
356
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"NftDetectionController.d.ts","sourceRoot":"","sources":["../src/NftDetectionController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0CA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B,EAChB,OAAO,EACP,WAAW,GACZ,EAAE;QACD,SAAS,EAAE,+BAA+B,CAAC;QAC3C,QAAQ,EAAE,OAAO,CAAC;QAClB,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;QAClC,WAAW,EAAE,MAAM,kBAAkB,CAAC;KACvC,EAiBA;IAED;;;;OAIG;IACH,SAAS,IAAI,OAAO,CAWnB;IAED,0BAA0B,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CAEhE;IAmED;;;;;;;;;OASG;IACG,UAAU,CACd,QAAQ,EAAE,GAAG,EAAE,EACf,OAAO,CAAC,EAAE;QACR,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,aAAa,CAAC,EAAE,OAAO,CAAC;QACxB,MAAM,CAAC,EAAE,WAAW,CAAC;KACtB,GACA,OAAO,CAAC,IAAI,CAAC,CA+Hf;CACF;eAEc,sBAAsB"}
1
+ {"version":3,"file":"NftDetectionController.d.ts","sourceRoot":"","sources":["../src/NftDetectionController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0CAA0C,EAAE,MAAM,+BAA+B,CAAC;AAChG,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,+BAA+B,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,MAAM,2BAA2B,CAAC;AAUnC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EACV,aAAa,EACb,mDAAmD,EACnD,2CAA2C,EAC3C,+BAA+B,EAC/B,iCAAiC,EAClC,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EACV,mCAAmC,EACnC,qCAAqC,EAEtC,MAAM,kCAAkC,CAAC;AAE1C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CA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AAO,CAAC,IAAI,CAAC,CAsKf;CACF;eAEc,sBAAsB"}
@@ -1,5 +1,5 @@
1
1
  import { BaseController } from '@metamask/base-controller';
2
- import { toChecksumHexAddress, ChainId, NFT_API_BASE_URL, NFT_API_VERSION, convertHexToDecimal, handleFetch, } from '@metamask/controller-utils';
2
+ import { toChecksumHexAddress, ChainId, NFT_API_BASE_URL, NFT_API_VERSION, convertHexToDecimal, handleFetch, toHex, } from '@metamask/controller-utils';
3
3
  import { createDeferredPromise } from '@metamask/utils';
4
4
  import { Source } from './constants.js';
5
5
  const controllerName = 'NftDetectionController';
@@ -16,6 +16,7 @@ export var BlockaidResultType;
16
16
  export class NftDetectionController extends BaseController {
17
17
  #disabled;
18
18
  #addNfts;
19
+ #removeNft;
19
20
  #getNftState;
20
21
  #inProcessNftFetchingUpdates;
21
22
  /**
@@ -25,9 +26,10 @@ export class NftDetectionController extends BaseController {
25
26
  * @param options.messenger - A reference to the messaging system.
26
27
  * @param options.disabled - Represents previous value of useNftDetection. Used to detect changes of useNftDetection. Default value is true.
27
28
  * @param options.addNfts - Add multiple NFTs.
29
+ * @param options.removeNft - Remove a single NFT.
28
30
  * @param options.getNftState - Gets the current state of the Assets controller.
29
31
  */
30
- constructor({ messenger, disabled = false, addNfts, getNftState, }) {
32
+ constructor({ messenger, disabled = false, addNfts, removeNft, getNftState, }) {
31
33
  super({
32
34
  name: controllerName,
33
35
  messenger,
@@ -38,6 +40,7 @@ export class NftDetectionController extends BaseController {
38
40
  this.#inProcessNftFetchingUpdates = {};
39
41
  this.#getNftState = getNftState;
40
42
  this.#addNfts = addNfts;
43
+ this.#removeNft = removeNft;
41
44
  this.messenger.subscribe('PreferencesController:stateChange', this.#onPreferencesControllerStateChange.bind(this));
42
45
  }
43
46
  /**
@@ -135,6 +138,35 @@ export class NftDetectionController extends BaseController {
135
138
  (elm.blockaidResult?.result_type
136
139
  ? elm.blockaidResult?.result_type === BlockaidResultType.Benign
137
140
  : true));
141
+ // Remove NFTs that the API now marks as spam but are still in state
142
+ const spamNfts = resultNftApi.tokens.filter((elm) => elm.token.isSpam === true);
143
+ for (const { token } of spamNfts) {
144
+ const { contract, tokenId, chainId } = token;
145
+ if (!chainId) {
146
+ continue;
147
+ }
148
+ const hexChainId = toHex(chainId);
149
+ const { allNfts } = this.#getNftState();
150
+ const nftsForChain = allNfts[userAddress]?.[hexChainId] ?? [];
151
+ const checksumAddress = toChecksumHexAddress(contract);
152
+ const existingNft = nftsForChain.find((nft) => nft.address.toLowerCase() === checksumAddress.toLowerCase() &&
153
+ nft.tokenId === tokenId);
154
+ // NFTs the user added (manually or by approving a dapp suggestion)
155
+ // are never auto-removed. NFTs without a stored source were added
156
+ // before sources were recorded and can still be removed.
157
+ if (existingNft &&
158
+ (!existingNft.source || existingNft.source === Source.Detected)) {
159
+ try {
160
+ const networkClientId = this.messenger.call('NetworkController:findNetworkClientIdByChainId', hexChainId);
161
+ this.#removeNft(contract, tokenId, networkClientId, {
162
+ userAddress,
163
+ });
164
+ }
165
+ catch {
166
+ // Network may not be configured; skip this NFT
167
+ }
168
+ }
169
+ }
138
170
  // Proceed to add NFTs
139
171
  const nftsToAdd = apiNfts
140
172
  .map((nft) => {
@@ -1 +1 @@
1
- {"version":3,"file":"NftDetectionController.js","sourceRoot":"","sources":["../src/NftDetectionController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAK3D,OAAO,EACL,oBAAoB,EACpB,OAAO,EACP,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,WAAW,GACZ,MAAM,4BAA4B,CAAC;AAcpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAGxD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAOxC,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAoJhD,MAAM,CAAN,IAAY,kBAKX;AALD,WAAY,kBAAkB;IAC5B,uCAAiB,CAAA;IACjB,mCAAa,CAA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AE,gBAAgB,EAAE,EACvD,IAAI,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,WAAW,EAAE,EAAE,EACxC,QAAQ,IAAI,EAAE,QAAQ,EAAE,EACxB,UAAU,IAAI,EAAE,UAAU,EAAE,EAC5B,MAAM,IAAI,EAAE,MAAM,EAAE,EACpB,UAAU,IAAI,EAAE,UAAU,EAAE,EAC5B,WAAW,IAAI,EAAE,WAAW,EAAE,EAC9B,UAAU,IAAI,EAAE,UAAU,EAAE,EAC5B,OAAO,IAAI,EAAE,OAAO,EAAE,CACvB,CAAC;wBAEJ,OAAO;4BACL,YAAY,EAAE,QAAQ;4BACtB,OAAO;4BACP,WAAW;yBACZ,CAAC;oBACJ,CAAC;oBACD,OAAO;gBACT,CAAC,CAAC;qBACD,MAAM,CAAC,CAAC,GAAG,EAAkC,EAAE,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC;gBAEtE,MAAM,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,WAAW,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC/D,CAAC,QACC,CAAC,IAAI,GAAG,YAAY,CAAC,YAAY,CAAC;gBAClC,CAAC,OAAO,EAAE,aAAa;gBACvB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EACzB;YACF,eAAe,EAAE,CAAC;QACpB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,KAAK,CAAC;QACd,CAAC;gBAAS,CAAC;YACT,OAAO,IAAI,CAAC,4BAA4B,CAAC,SAAS,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;CACF;AAED,eAAe,sBAAsB,CAAC","sourcesContent":["import type { AccountsControllerGetSelectedAccountAction } from '@metamask/accounts-controller';\nimport type { ApprovalControllerAddRequestAction } from '@metamask/approval-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport {\n toChecksumHexAddress,\n ChainId,\n NFT_API_BASE_URL,\n NFT_API_VERSION,\n convertHexToDecimal,\n handleFetch,\n} from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkClient,\n NetworkControllerFindNetworkClientIdByChainIdAction,\n NetworkControllerGetNetworkClientByIdAction,\n NetworkControllerGetStateAction,\n NetworkControllerStateChangeEvent,\n} from '@metamask/network-controller';\nimport type {\n PreferencesControllerGetStateAction,\n PreferencesControllerStateChangeEvent,\n PreferencesState,\n} from '@metamask/preferences-controller';\nimport { createDeferredPromise } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { Source } from './constants.js';\nimport type {\n NftController,\n NftControllerState,\n NftMetadata,\n} from './NftController.js';\n\nconst controllerName = 'NftDetectionController';\n\nexport type NFTDetectionControllerState = Record<never, never>;\n\nexport type AllowedActions =\n | ControllerGetStateAction<typeof controllerName, NFTDetectionControllerState>\n | ApprovalControllerAddRequestAction\n | NetworkControllerGetStateAction\n | NetworkControllerGetNetworkClientByIdAction\n | PreferencesControllerGetStateAction\n | AccountsControllerGetSelectedAccountAction\n | NetworkControllerFindNetworkClientIdByChainIdAction;\n\nexport type AllowedEvents =\n | ControllerStateChangeEvent<\n typeof controllerName,\n NFTDetectionControllerState\n >\n | PreferencesControllerStateChangeEvent\n | NetworkControllerStateChangeEvent;\n\nexport type NftDetectionControllerMessenger = Messenger<\n typeof controllerName,\n AllowedActions,\n AllowedEvents\n>;\n\n/**\n * @type ApiNft\n *\n * NFT object coming from OpenSea api\n *\n * @property token_id - The NFT identifier\n * @property num_sales - Number of sales\n * @property background_color - The background color to be displayed with the item\n * @property image_url - URI of an image associated with this NFT\n *\n * @property image_preview_url - URI of a smaller image associated with this NFT\n * @property image_thumbnail_url - URI of a thumbnail image associated with this NFT\n * @property image_original_url - URI of the original image associated with this NFT\n * @property animation_url - URI of a animation associated with this NFT\n * @property animation_original_url - URI of the original animation associated with this NFT\n * @property name - The NFT name\n * @property description - The NFT description\n * @property external_link - External link containing additional information\n * @property assetContract - The NFT contract information object\n * @property creator - The NFT owner information object\n * @property lastSale - When this item was last sold\n */\n/* eslint-disable @typescript-eslint/naming-convention */\nexport type ApiNft = {\n token_id: string;\n num_sales: number | null;\n background_color: string | null;\n image_url: string | null;\n image_preview_url: string | null;\n image_thumbnail_url: string | null;\n image_original_url: string | null;\n animation_url: string | null;\n animation_original_url: string | null;\n name: string | null;\n description: string | null;\n external_link: string | null;\n asset_contract: ApiNftContract;\n creator: ApiNftCreator;\n last_sale: ApiNftLastSale | null;\n};\n/* eslint-enable @typescript-eslint/naming-convention */\n\n/**\n * @type ApiNftContract\n *\n * NFT contract object coming from OpenSea api\n *\n * @property address - Address of the NFT contract\n * @property asset_contract_type - The NFT type, it could be `semi-fungible` or `non-fungible`\n * @property created_date - Creation date\n * @property collection - Object containing the contract name and URI of an image associated\n * @property schema_name - The schema followed by the contract, it could be `ERC721` or `ERC1155`\n * @property symbol - The NFT contract symbol\n * @property total_supply - Total supply of NFTs\n * @property description - The NFT contract description\n * @property external_link - External link containing additional information\n */\n/* eslint-disable @typescript-eslint/naming-convention */\nexport type ApiNftContract = {\n address: string;\n asset_contract_type: string | null;\n created_date: string | null;\n schema_name: string | null;\n symbol: string | null;\n total_supply: string | null;\n description: string | null;\n external_link: string | null;\n collection: {\n name: string | null;\n image_url?: string | null;\n tokenCount?: string | null;\n };\n};\n/* eslint-enable @typescript-eslint/naming-convention */\n\n/**\n * @type ApiNftLastSale\n *\n * NFT sale object coming from OpenSea api\n *\n * @property event_timestamp - Object containing a `username`\n * @property total_price - URI of NFT image associated with this owner\n * @property transaction - Object containing transaction_hash and block_hash\n */\n/* eslint-disable @typescript-eslint/naming-convention */\nexport type ApiNftLastSale = {\n event_timestamp: string;\n total_price: string;\n transaction: { transaction_hash: string; block_hash: string };\n};\n/* eslint-enable @typescript-eslint/naming-convention */\n\n/**\n * @type ApiNftCreator\n *\n * NFT creator object coming from OpenSea api\n *\n * @property user - Object containing a `username`\n * @property profile_img_url - URI of NFT image associated with this owner\n * @property address - The owner address\n */\n/* eslint-disable @typescript-eslint/naming-convention */\nexport type ApiNftCreator = {\n user: { username: string };\n profile_img_url: string;\n address: string;\n};\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport type ReservoirResponse = {\n tokens: TokensResponse[];\n continuation?: string | null;\n};\n\nexport type TokensResponse = {\n token: TokenResponse;\n ownership: Ownership;\n market?: Market;\n blockaidResult?: Blockaid;\n};\n\nexport enum BlockaidResultType {\n Benign = 'Benign',\n Spam = 'Spam',\n Warning = 'Warning',\n Malicious = 'Malicious',\n}\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport type Blockaid = {\n contract: string;\n chainId: number;\n result_type: BlockaidResultType;\n malicious_score: string;\n attack_types: object;\n};\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport type Market = {\n floorAsk?: FloorAsk;\n topBid?: TopBid;\n};\n\nexport type TokenResponse = {\n chainId: number;\n contract: string;\n tokenId: string;\n kind?: string;\n name?: string;\n image?: string;\n imageSmall?: string;\n imageLarge?: string;\n metadata?: Metadata;\n description?: string;\n supply?: number;\n remainingSupply?: number;\n rarityScore?: number;\n rarity?: number;\n rarityRank?: number;\n media?: string;\n isFlagged?: boolean;\n isSpam?: boolean;\n isNsfw?: boolean;\n metadataDisabled?: boolean;\n lastFlagUpdate?: string;\n lastFlagChange?: string;\n collection?: Collection;\n lastSale?: LastSale;\n topBid?: TopBid;\n lastAppraisalValue?: number;\n attributes?: Attributes[];\n};\n\nexport type TopBid = {\n id?: string;\n price?: Price;\n source?: {\n id?: string;\n domain?: string;\n name?: string;\n icon?: string;\n url?: string;\n };\n};\n\nexport type LastSale = {\n saleId?: string;\n token?: {\n contract?: string;\n tokenId?: string;\n name?: string;\n image?: string;\n collection?: {\n id?: string;\n name?: string;\n };\n };\n orderSource?: string;\n orderSide?: 'ask' | 'bid';\n orderKind?: string;\n orderId?: string;\n from?: string;\n to?: string;\n amount?: string;\n fillSource?: string;\n block?: number;\n txHash?: string;\n logIndex?: number;\n batchIndex?: number;\n timestamp?: number;\n price?: Price;\n washTradingScore?: number;\n royaltyFeeBps?: number;\n marketplaceFeeBps?: number;\n paidFullRoyalty?: boolean;\n feeBreakdown?: FeeBreakdown[];\n isDeleted?: boolean;\n createdAt?: string;\n updatedAt?: string;\n};\n\nexport type FeeBreakdown = {\n kind?: string;\n bps?: number;\n recipient?: string;\n source?: string;\n rawAmount?: string;\n};\n\nexport type Attributes = {\n key?: string;\n kind?: string;\n value: string;\n tokenCount?: number;\n onSaleCount?: number;\n floorAskPrice?: Price | null;\n topBidValue?: number | null;\n createdAt?: string;\n};\n\nexport type GetCollectionsResponse = {\n collections: CollectionResponse[];\n};\n\nexport type CollectionResponse = {\n id?: string;\n chainId?: number;\n openseaVerificationStatus?: string;\n contractDeployedAt?: string;\n creator?: string;\n ownerCount?: string;\n topBid?: TopBid & {\n sourceDomain?: string;\n };\n};\n\nexport type FloorAskCollection = {\n id?: string;\n price?: Price;\n maker?: string;\n kind?: string;\n validFrom?: number;\n validUntil?: number;\n source?: SourceCollection;\n rawData?: Metadata;\n isNativeOffChainCancellable?: boolean;\n};\n\nexport type SourceCollection = {\n id: string;\n domain: string;\n name: string;\n icon: string;\n url: string;\n};\n\nexport type TokenCollection = {\n id?: string;\n name?: string;\n slug?: string;\n symbol?: string;\n imageUrl?: string;\n image?: string;\n isSpam?: boolean;\n isNsfw?: boolean;\n creator?: string;\n tokenCount?: string;\n metadataDisabled?: boolean;\n openseaVerificationStatus?: string;\n floorAskPrice?: Price;\n royaltiesBps?: number;\n royalties?: Royalties[];\n floorAsk?: FloorAskCollection;\n};\n\nexport type Collection = TokenCollection & CollectionResponse;\n\nexport type Royalties = {\n bps?: number;\n recipient?: string;\n};\n\nexport type Ownership = {\n tokenCount?: string;\n onSaleCount?: string;\n floorAsk?: FloorAsk;\n acquiredAt?: string;\n};\n\nexport type FloorAsk = {\n id?: string;\n price?: Price;\n maker?: string;\n kind?: string;\n validFrom?: number;\n validUntil?: number;\n source?: Source;\n rawData?: Metadata;\n isNativeOffChainCancellable?: boolean;\n};\n\nexport type Price = {\n currency?: {\n contract?: string;\n name?: string;\n symbol?: string;\n decimals?: number;\n chainId?: number;\n };\n amount?: {\n raw?: string;\n decimal?: number;\n usd?: number;\n native?: number;\n };\n netAmount?: {\n raw?: string;\n decimal?: number;\n usd?: number;\n native?: number;\n };\n};\n\nexport type Metadata = {\n imageOriginal?: string;\n tokenURI?: string;\n};\n\n/**\n * Controller that passively detects nfts for a user address\n */\nexport class NftDetectionController extends BaseController<\n typeof controllerName,\n NFTDetectionControllerState,\n NftDetectionControllerMessenger\n> {\n #disabled: boolean;\n\n readonly #addNfts: NftController['addNfts'];\n\n readonly #getNftState: () => NftControllerState;\n\n #inProcessNftFetchingUpdates: Record<`${string}:${string}`, Promise<void>>;\n\n /**\n * The controller options\n *\n * @param options - The controller options.\n * @param options.messenger - A reference to the messaging system.\n * @param options.disabled - Represents previous value of useNftDetection. Used to detect changes of useNftDetection. Default value is true.\n * @param options.addNfts - Add multiple NFTs.\n * @param options.getNftState - Gets the current state of the Assets controller.\n */\n constructor({\n messenger,\n disabled = false,\n addNfts,\n getNftState,\n }: {\n messenger: NftDetectionControllerMessenger;\n disabled: boolean;\n addNfts: NftController['addNfts'];\n getNftState: () => NftControllerState;\n }) {\n super({\n name: controllerName,\n messenger,\n metadata: {},\n state: {},\n });\n this.#disabled = disabled;\n this.#inProcessNftFetchingUpdates = {};\n\n this.#getNftState = getNftState;\n this.#addNfts = addNfts;\n\n this.messenger.subscribe(\n 'PreferencesController:stateChange',\n this.#onPreferencesControllerStateChange.bind(this),\n );\n }\n\n /**\n * Checks whether network is mainnet or not.\n *\n * @returns Whether current network is mainnet.\n */\n isMainnet(): boolean {\n const { selectedNetworkClientId } = this.messenger.call(\n 'NetworkController:getState',\n );\n const {\n configuration: { chainId },\n } = this.messenger.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n );\n return chainId === ChainId.mainnet;\n }\n\n isMainnetByNetworkClientId(networkClient: NetworkClient): boolean {\n return networkClient.configuration.chainId === ChainId.mainnet;\n }\n\n /**\n * Handles the state change of the preference controller.\n *\n * @param preferencesState - The new state of the preference controller.\n * @param preferencesState.useNftDetection - Boolean indicating user preference on NFT detection.\n */\n #onPreferencesControllerStateChange({\n useNftDetection,\n }: PreferencesState): void {\n if (!useNftDetection !== this.#disabled) {\n this.#disabled = !useNftDetection;\n }\n }\n\n #getOwnerNftApi({\n chainIds,\n address,\n next,\n }: {\n chainIds: string[];\n address: string;\n next?: string;\n }): string {\n // from chainIds construct a string of chainIds that can be used like chainIds=1&chainIds=56\n const chainIdsString = chainIds.join('&chainIds=');\n return `${\n NFT_API_BASE_URL as string\n }/users/${address}/tokens?chainIds=${chainIdsString}&limit=50&includeTopBid=true&continuation=${next ?? ''}`;\n }\n\n async #getOwnerNfts(\n address: string,\n chainIds: Hex[],\n cursor: string | undefined,\n ): Promise<ReservoirResponse> {\n // Convert hex chainId to number\n const convertedChainIds = chainIds.map((chainId) =>\n convertHexToDecimal(chainId).toString(),\n );\n\n const filteredChainIds = convertedChainIds.filter(\n (chainId) => chainId !== '0',\n );\n\n // Avoid making the API call for non-EVM chains\n if (filteredChainIds.length === 0) {\n return {\n tokens: [],\n continuation: null,\n };\n }\n\n const url = this.#getOwnerNftApi({\n chainIds: filteredChainIds,\n address,\n next: cursor,\n });\n const nftApiResponse: ReservoirResponse = await handleFetch(url, {\n headers: {\n Version: NFT_API_VERSION,\n },\n });\n return nftApiResponse;\n }\n\n /**\n * Triggers asset ERC721 token auto detection on mainnet. Any newly detected NFTs are\n * added.\n *\n * @param chainIds - The chain IDs to detect NFTs on.\n * @param options - Options bag.\n * @param options.userAddress - The address to detect NFTs for.\n * @param options.firstPageOnly - Whether to only detect the first page of NFTs.\n * @param options.signal - An optional abort signal to cancel the operation.\n */\n async detectNfts(\n chainIds: Hex[],\n options?: {\n userAddress?: string;\n firstPageOnly?: boolean;\n signal?: AbortSignal;\n },\n ): Promise<void> {\n const userAddress =\n options?.userAddress ??\n this.messenger.call('AccountsController:getSelectedAccount').address;\n\n /* istanbul ignore if */\n if (chainIds.length === 0 || this.#disabled) {\n return;\n }\n /* istanbul ignore else */\n if (!userAddress) {\n return;\n }\n // create a string of all chainIds\n const chainIdsString = chainIds.join(',');\n\n const updateKey: `${string}:${string}` = `${chainIdsString}:${userAddress}`;\n if (updateKey in this.#inProcessNftFetchingUpdates) {\n // This prevents redundant updates\n // This promise is resolved after the in-progress update has finished,\n // and state has been updated.\n await this.#inProcessNftFetchingUpdates[updateKey];\n return;\n }\n\n const {\n promise: inProgressUpdate,\n resolve: updateSucceeded,\n reject: updateFailed,\n } = createDeferredPromise({ suppressUnhandledRejection: true });\n this.#inProcessNftFetchingUpdates[updateKey] = inProgressUpdate;\n\n let next;\n let apiNfts: TokensResponse[] = [];\n let resultNftApi: ReservoirResponse;\n try {\n do {\n resultNftApi = await this.#getOwnerNfts(userAddress, chainIds, next);\n apiNfts = resultNftApi.tokens.filter(\n (elm) =>\n elm.token.isSpam === false &&\n (elm.blockaidResult?.result_type\n ? elm.blockaidResult?.result_type === BlockaidResultType.Benign\n : true),\n );\n\n // Proceed to add NFTs\n const nftsToAdd = apiNfts\n .map((nft) => {\n const {\n tokenId,\n contract,\n kind,\n image: imageUrl,\n imageSmall: imageThumbnailUrl,\n metadata,\n name,\n description,\n attributes,\n topBid,\n lastSale,\n rarityRank,\n rarityScore,\n collection,\n chainId,\n } = nft.token;\n\n // Use a fallback if metadata is null\n const { imageOriginal: imageOriginalUrl } = metadata ?? {};\n\n let ignored;\n /* istanbul ignore else */\n const { ignoredNfts } = this.#getNftState();\n if (ignoredNfts.length) {\n ignored = ignoredNfts.find((ignoredNft) => {\n /* istanbul ignore next */\n return (\n ignoredNft.address === toChecksumHexAddress(contract) &&\n ignoredNft.tokenId === tokenId\n );\n });\n }\n\n /* istanbul ignore else */\n if (!ignored) {\n /* istanbul ignore next */\n const nftMetadata: NftMetadata & { chainId: number } =\n Object.assign(\n {},\n { name },\n description && { description },\n imageUrl && { image: imageUrl },\n imageThumbnailUrl && { imageThumbnail: imageThumbnailUrl },\n imageOriginalUrl && { imageOriginal: imageOriginalUrl },\n kind && { standard: kind.toUpperCase() },\n lastSale && { lastSale },\n attributes && { attributes },\n topBid && { topBid },\n rarityRank && { rarityRank },\n rarityScore && { rarityScore },\n collection && { collection },\n chainId && { chainId },\n );\n\n return {\n tokenAddress: contract,\n tokenId,\n nftMetadata,\n };\n }\n return;\n })\n .filter((nft): nft is NonNullable<typeof nft> => nft !== undefined);\n\n await this.#addNfts(nftsToAdd, userAddress, Source.Detected);\n } while (\n (next = resultNftApi.continuation) &&\n !options?.firstPageOnly &&\n !options?.signal?.aborted\n );\n updateSucceeded();\n } catch (error) {\n updateFailed(error);\n throw error;\n } finally {\n delete this.#inProcessNftFetchingUpdates[updateKey];\n }\n }\n}\n\nexport default NftDetectionController;\n"]}
1
+ {"version":3,"file":"NftDetectionController.js","sourceRoot":"","sources":["../src/NftDetectionController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAK3D,OAAO,EACL,oBAAoB,EACpB,OAAO,EACP,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,WAAW,EACX,KAAK,GACN,MAAM,4BAA4B,CAAC;AAcpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAGxD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAOxC,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAoJhD,MAAM,CAAN,IAAY,kBAKX;AALD,WAAY,kBAAkB;IAC5B,uCAAiB,CAAA;IACjB,mCAAa,CAAA;IACb,yCAAmB,CAAA;IACnB,6CAAuB,CAAA;AACzB,CAAC,EALW,kBAAkB,KAAlB,kBAAkB,QAK7B;AA8ND;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,cAI3C;I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AAE,EACvD,IAAI,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,WAAW,EAAE,EAAE,EACxC,QAAQ,IAAI,EAAE,QAAQ,EAAE,EACxB,UAAU,IAAI,EAAE,UAAU,EAAE,EAC5B,MAAM,IAAI,EAAE,MAAM,EAAE,EACpB,UAAU,IAAI,EAAE,UAAU,EAAE,EAC5B,WAAW,IAAI,EAAE,WAAW,EAAE,EAC9B,UAAU,IAAI,EAAE,UAAU,EAAE,EAC5B,OAAO,IAAI,EAAE,OAAO,EAAE,CACvB,CAAC;wBAEJ,OAAO;4BACL,YAAY,EAAE,QAAQ;4BACtB,OAAO;4BACP,WAAW;yBACZ,CAAC;oBACJ,CAAC;oBACD,OAAO;gBACT,CAAC,CAAC;qBACD,MAAM,CAAC,CAAC,GAAG,EAAkC,EAAE,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC;gBAEtE,MAAM,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,WAAW,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC/D,CAAC,QACC,CAAC,IAAI,GAAG,YAAY,CAAC,YAAY,CAAC;gBAClC,CAAC,OAAO,EAAE,aAAa;gBACvB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EACzB;YACF,eAAe,EAAE,CAAC;QACpB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,KAAK,CAAC;QACd,CAAC;gBAAS,CAAC;YACT,OAAO,IAAI,CAAC,4BAA4B,CAAC,SAAS,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;CACF;AAED,eAAe,sBAAsB,CAAC","sourcesContent":["import type { AccountsControllerGetSelectedAccountAction } from '@metamask/accounts-controller';\nimport type { ApprovalControllerAddRequestAction } from '@metamask/approval-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport {\n toChecksumHexAddress,\n ChainId,\n NFT_API_BASE_URL,\n NFT_API_VERSION,\n convertHexToDecimal,\n handleFetch,\n toHex,\n} from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkClient,\n NetworkControllerFindNetworkClientIdByChainIdAction,\n NetworkControllerGetNetworkClientByIdAction,\n NetworkControllerGetStateAction,\n NetworkControllerStateChangeEvent,\n} from '@metamask/network-controller';\nimport type {\n PreferencesControllerGetStateAction,\n PreferencesControllerStateChangeEvent,\n PreferencesState,\n} from '@metamask/preferences-controller';\nimport { createDeferredPromise } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { Source } from './constants.js';\nimport type {\n NftController,\n NftControllerState,\n NftMetadata,\n} from './NftController.js';\n\nconst controllerName = 'NftDetectionController';\n\nexport type NFTDetectionControllerState = Record<never, never>;\n\nexport type AllowedActions =\n | ControllerGetStateAction<typeof controllerName, NFTDetectionControllerState>\n | ApprovalControllerAddRequestAction\n | NetworkControllerGetStateAction\n | NetworkControllerGetNetworkClientByIdAction\n | PreferencesControllerGetStateAction\n | AccountsControllerGetSelectedAccountAction\n | NetworkControllerFindNetworkClientIdByChainIdAction;\n\nexport type AllowedEvents =\n | ControllerStateChangeEvent<\n typeof controllerName,\n NFTDetectionControllerState\n >\n | PreferencesControllerStateChangeEvent\n | NetworkControllerStateChangeEvent;\n\nexport type NftDetectionControllerMessenger = Messenger<\n typeof controllerName,\n AllowedActions,\n AllowedEvents\n>;\n\n/**\n * @type ApiNft\n *\n * NFT object coming from OpenSea api\n *\n * @property token_id - The NFT identifier\n * @property num_sales - Number of sales\n * @property background_color - The background color to be displayed with the item\n * @property image_url - URI of an image associated with this NFT\n *\n * @property image_preview_url - URI of a smaller image associated with this NFT\n * @property image_thumbnail_url - URI of a thumbnail image associated with this NFT\n * @property image_original_url - URI of the original image associated with this NFT\n * @property animation_url - URI of a animation associated with this NFT\n * @property animation_original_url - URI of the original animation associated with this NFT\n * @property name - The NFT name\n * @property description - The NFT description\n * @property external_link - External link containing additional information\n * @property assetContract - The NFT contract information object\n * @property creator - The NFT owner information object\n * @property lastSale - When this item was last sold\n */\n/* eslint-disable @typescript-eslint/naming-convention */\nexport type ApiNft = {\n token_id: string;\n num_sales: number | null;\n background_color: string | null;\n image_url: string | null;\n image_preview_url: string | null;\n image_thumbnail_url: string | null;\n image_original_url: string | null;\n animation_url: string | null;\n animation_original_url: string | null;\n name: string | null;\n description: string | null;\n external_link: string | null;\n asset_contract: ApiNftContract;\n creator: ApiNftCreator;\n last_sale: ApiNftLastSale | null;\n};\n/* eslint-enable @typescript-eslint/naming-convention */\n\n/**\n * @type ApiNftContract\n *\n * NFT contract object coming from OpenSea api\n *\n * @property address - Address of the NFT contract\n * @property asset_contract_type - The NFT type, it could be `semi-fungible` or `non-fungible`\n * @property created_date - Creation date\n * @property collection - Object containing the contract name and URI of an image associated\n * @property schema_name - The schema followed by the contract, it could be `ERC721` or `ERC1155`\n * @property symbol - The NFT contract symbol\n * @property total_supply - Total supply of NFTs\n * @property description - The NFT contract description\n * @property external_link - External link containing additional information\n */\n/* eslint-disable @typescript-eslint/naming-convention */\nexport type ApiNftContract = {\n address: string;\n asset_contract_type: string | null;\n created_date: string | null;\n schema_name: string | null;\n symbol: string | null;\n total_supply: string | null;\n description: string | null;\n external_link: string | null;\n collection: {\n name: string | null;\n image_url?: string | null;\n tokenCount?: string | null;\n };\n};\n/* eslint-enable @typescript-eslint/naming-convention */\n\n/**\n * @type ApiNftLastSale\n *\n * NFT sale object coming from OpenSea api\n *\n * @property event_timestamp - Object containing a `username`\n * @property total_price - URI of NFT image associated with this owner\n * @property transaction - Object containing transaction_hash and block_hash\n */\n/* eslint-disable @typescript-eslint/naming-convention */\nexport type ApiNftLastSale = {\n event_timestamp: string;\n total_price: string;\n transaction: { transaction_hash: string; block_hash: string };\n};\n/* eslint-enable @typescript-eslint/naming-convention */\n\n/**\n * @type ApiNftCreator\n *\n * NFT creator object coming from OpenSea api\n *\n * @property user - Object containing a `username`\n * @property profile_img_url - URI of NFT image associated with this owner\n * @property address - The owner address\n */\n/* eslint-disable @typescript-eslint/naming-convention */\nexport type ApiNftCreator = {\n user: { username: string };\n profile_img_url: string;\n address: string;\n};\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport type ReservoirResponse = {\n tokens: TokensResponse[];\n continuation?: string | null;\n};\n\nexport type TokensResponse = {\n token: TokenResponse;\n ownership: Ownership;\n market?: Market;\n blockaidResult?: Blockaid;\n};\n\nexport enum BlockaidResultType {\n Benign = 'Benign',\n Spam = 'Spam',\n Warning = 'Warning',\n Malicious = 'Malicious',\n}\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport type Blockaid = {\n contract: string;\n chainId: number;\n result_type: BlockaidResultType;\n malicious_score: string;\n attack_types: object;\n};\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport type Market = {\n floorAsk?: FloorAsk;\n topBid?: TopBid;\n};\n\nexport type TokenResponse = {\n chainId: number;\n contract: string;\n tokenId: string;\n kind?: string;\n name?: string;\n image?: string;\n imageSmall?: string;\n imageLarge?: string;\n metadata?: Metadata;\n description?: string;\n supply?: number;\n remainingSupply?: number;\n rarityScore?: number;\n rarity?: number;\n rarityRank?: number;\n media?: string;\n isFlagged?: boolean;\n isSpam?: boolean;\n isNsfw?: boolean;\n metadataDisabled?: boolean;\n lastFlagUpdate?: string;\n lastFlagChange?: string;\n collection?: Collection;\n lastSale?: LastSale;\n topBid?: TopBid;\n lastAppraisalValue?: number;\n attributes?: Attributes[];\n};\n\nexport type TopBid = {\n id?: string;\n price?: Price;\n source?: {\n id?: string;\n domain?: string;\n name?: string;\n icon?: string;\n url?: string;\n };\n};\n\nexport type LastSale = {\n saleId?: string;\n token?: {\n contract?: string;\n tokenId?: string;\n name?: string;\n image?: string;\n collection?: {\n id?: string;\n name?: string;\n };\n };\n orderSource?: string;\n orderSide?: 'ask' | 'bid';\n orderKind?: string;\n orderId?: string;\n from?: string;\n to?: string;\n amount?: string;\n fillSource?: string;\n block?: number;\n txHash?: string;\n logIndex?: number;\n batchIndex?: number;\n timestamp?: number;\n price?: Price;\n washTradingScore?: number;\n royaltyFeeBps?: number;\n marketplaceFeeBps?: number;\n paidFullRoyalty?: boolean;\n feeBreakdown?: FeeBreakdown[];\n isDeleted?: boolean;\n createdAt?: string;\n updatedAt?: string;\n};\n\nexport type FeeBreakdown = {\n kind?: string;\n bps?: number;\n recipient?: string;\n source?: string;\n rawAmount?: string;\n};\n\nexport type Attributes = {\n key?: string;\n kind?: string;\n value: string;\n tokenCount?: number;\n onSaleCount?: number;\n floorAskPrice?: Price | null;\n topBidValue?: number | null;\n createdAt?: string;\n};\n\nexport type GetCollectionsResponse = {\n collections: CollectionResponse[];\n};\n\nexport type CollectionResponse = {\n id?: string;\n chainId?: number;\n openseaVerificationStatus?: string;\n contractDeployedAt?: string;\n creator?: string;\n ownerCount?: string;\n topBid?: TopBid & {\n sourceDomain?: string;\n };\n};\n\nexport type FloorAskCollection = {\n id?: string;\n price?: Price;\n maker?: string;\n kind?: string;\n validFrom?: number;\n validUntil?: number;\n source?: SourceCollection;\n rawData?: Metadata;\n isNativeOffChainCancellable?: boolean;\n};\n\nexport type SourceCollection = {\n id: string;\n domain: string;\n name: string;\n icon: string;\n url: string;\n};\n\nexport type TokenCollection = {\n id?: string;\n name?: string;\n slug?: string;\n symbol?: string;\n imageUrl?: string;\n image?: string;\n isSpam?: boolean;\n isNsfw?: boolean;\n creator?: string;\n tokenCount?: string;\n metadataDisabled?: boolean;\n openseaVerificationStatus?: string;\n floorAskPrice?: Price;\n royaltiesBps?: number;\n royalties?: Royalties[];\n floorAsk?: FloorAskCollection;\n};\n\nexport type Collection = TokenCollection & CollectionResponse;\n\nexport type Royalties = {\n bps?: number;\n recipient?: string;\n};\n\nexport type Ownership = {\n tokenCount?: string;\n onSaleCount?: string;\n floorAsk?: FloorAsk;\n acquiredAt?: string;\n};\n\nexport type FloorAsk = {\n id?: string;\n price?: Price;\n maker?: string;\n kind?: string;\n validFrom?: number;\n validUntil?: number;\n source?: Source;\n rawData?: Metadata;\n isNativeOffChainCancellable?: boolean;\n};\n\nexport type Price = {\n currency?: {\n contract?: string;\n name?: string;\n symbol?: string;\n decimals?: number;\n chainId?: number;\n };\n amount?: {\n raw?: string;\n decimal?: number;\n usd?: number;\n native?: number;\n };\n netAmount?: {\n raw?: string;\n decimal?: number;\n usd?: number;\n native?: number;\n };\n};\n\nexport type Metadata = {\n imageOriginal?: string;\n tokenURI?: string;\n};\n\n/**\n * Controller that passively detects nfts for a user address\n */\nexport class NftDetectionController extends BaseController<\n typeof controllerName,\n NFTDetectionControllerState,\n NftDetectionControllerMessenger\n> {\n #disabled: boolean;\n\n readonly #addNfts: NftController['addNfts'];\n\n readonly #removeNft: NftController['removeNft'];\n\n readonly #getNftState: () => NftControllerState;\n\n #inProcessNftFetchingUpdates: Record<`${string}:${string}`, Promise<void>>;\n\n /**\n * The controller options\n *\n * @param options - The controller options.\n * @param options.messenger - A reference to the messaging system.\n * @param options.disabled - Represents previous value of useNftDetection. Used to detect changes of useNftDetection. Default value is true.\n * @param options.addNfts - Add multiple NFTs.\n * @param options.removeNft - Remove a single NFT.\n * @param options.getNftState - Gets the current state of the Assets controller.\n */\n constructor({\n messenger,\n disabled = false,\n addNfts,\n removeNft,\n getNftState,\n }: {\n messenger: NftDetectionControllerMessenger;\n disabled: boolean;\n addNfts: NftController['addNfts'];\n removeNft: NftController['removeNft'];\n getNftState: () => NftControllerState;\n }) {\n super({\n name: controllerName,\n messenger,\n metadata: {},\n state: {},\n });\n this.#disabled = disabled;\n this.#inProcessNftFetchingUpdates = {};\n\n this.#getNftState = getNftState;\n this.#addNfts = addNfts;\n this.#removeNft = removeNft;\n\n this.messenger.subscribe(\n 'PreferencesController:stateChange',\n this.#onPreferencesControllerStateChange.bind(this),\n );\n }\n\n /**\n * Checks whether network is mainnet or not.\n *\n * @returns Whether current network is mainnet.\n */\n isMainnet(): boolean {\n const { selectedNetworkClientId } = this.messenger.call(\n 'NetworkController:getState',\n );\n const {\n configuration: { chainId },\n } = this.messenger.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n );\n return chainId === ChainId.mainnet;\n }\n\n isMainnetByNetworkClientId(networkClient: NetworkClient): boolean {\n return networkClient.configuration.chainId === ChainId.mainnet;\n }\n\n /**\n * Handles the state change of the preference controller.\n *\n * @param preferencesState - The new state of the preference controller.\n * @param preferencesState.useNftDetection - Boolean indicating user preference on NFT detection.\n */\n #onPreferencesControllerStateChange({\n useNftDetection,\n }: PreferencesState): void {\n if (!useNftDetection !== this.#disabled) {\n this.#disabled = !useNftDetection;\n }\n }\n\n #getOwnerNftApi({\n chainIds,\n address,\n next,\n }: {\n chainIds: string[];\n address: string;\n next?: string;\n }): string {\n // from chainIds construct a string of chainIds that can be used like chainIds=1&chainIds=56\n const chainIdsString = chainIds.join('&chainIds=');\n return `${\n NFT_API_BASE_URL as string\n }/users/${address}/tokens?chainIds=${chainIdsString}&limit=50&includeTopBid=true&continuation=${next ?? ''}`;\n }\n\n async #getOwnerNfts(\n address: string,\n chainIds: Hex[],\n cursor: string | undefined,\n ): Promise<ReservoirResponse> {\n // Convert hex chainId to number\n const convertedChainIds = chainIds.map((chainId) =>\n convertHexToDecimal(chainId).toString(),\n );\n\n const filteredChainIds = convertedChainIds.filter(\n (chainId) => chainId !== '0',\n );\n\n // Avoid making the API call for non-EVM chains\n if (filteredChainIds.length === 0) {\n return {\n tokens: [],\n continuation: null,\n };\n }\n\n const url = this.#getOwnerNftApi({\n chainIds: filteredChainIds,\n address,\n next: cursor,\n });\n const nftApiResponse: ReservoirResponse = await handleFetch(url, {\n headers: {\n Version: NFT_API_VERSION,\n },\n });\n return nftApiResponse;\n }\n\n /**\n * Triggers asset ERC721 token auto detection on mainnet. Any newly detected NFTs are\n * added.\n *\n * @param chainIds - The chain IDs to detect NFTs on.\n * @param options - Options bag.\n * @param options.userAddress - The address to detect NFTs for.\n * @param options.firstPageOnly - Whether to only detect the first page of NFTs.\n * @param options.signal - An optional abort signal to cancel the operation.\n */\n async detectNfts(\n chainIds: Hex[],\n options?: {\n userAddress?: string;\n firstPageOnly?: boolean;\n signal?: AbortSignal;\n },\n ): Promise<void> {\n const userAddress =\n options?.userAddress ??\n this.messenger.call('AccountsController:getSelectedAccount').address;\n\n /* istanbul ignore if */\n if (chainIds.length === 0 || this.#disabled) {\n return;\n }\n /* istanbul ignore else */\n if (!userAddress) {\n return;\n }\n // create a string of all chainIds\n const chainIdsString = chainIds.join(',');\n\n const updateKey: `${string}:${string}` = `${chainIdsString}:${userAddress}`;\n if (updateKey in this.#inProcessNftFetchingUpdates) {\n // This prevents redundant updates\n // This promise is resolved after the in-progress update has finished,\n // and state has been updated.\n await this.#inProcessNftFetchingUpdates[updateKey];\n return;\n }\n\n const {\n promise: inProgressUpdate,\n resolve: updateSucceeded,\n reject: updateFailed,\n } = createDeferredPromise({ suppressUnhandledRejection: true });\n this.#inProcessNftFetchingUpdates[updateKey] = inProgressUpdate;\n\n let next;\n let apiNfts: TokensResponse[] = [];\n let resultNftApi: ReservoirResponse;\n try {\n do {\n resultNftApi = await this.#getOwnerNfts(userAddress, chainIds, next);\n apiNfts = resultNftApi.tokens.filter(\n (elm) =>\n elm.token.isSpam === false &&\n (elm.blockaidResult?.result_type\n ? elm.blockaidResult?.result_type === BlockaidResultType.Benign\n : true),\n );\n\n // Remove NFTs that the API now marks as spam but are still in state\n const spamNfts = resultNftApi.tokens.filter(\n (elm) => elm.token.isSpam === true,\n );\n for (const { token } of spamNfts) {\n const { contract, tokenId, chainId } = token;\n if (!chainId) {\n continue;\n }\n const hexChainId = toHex(chainId);\n const { allNfts } = this.#getNftState();\n const nftsForChain = allNfts[userAddress]?.[hexChainId] ?? [];\n const checksumAddress = toChecksumHexAddress(contract);\n const existingNft = nftsForChain.find(\n (nft) =>\n nft.address.toLowerCase() === checksumAddress.toLowerCase() &&\n nft.tokenId === tokenId,\n );\n // NFTs the user added (manually or by approving a dapp suggestion)\n // are never auto-removed. NFTs without a stored source were added\n // before sources were recorded and can still be removed.\n if (\n existingNft &&\n (!existingNft.source || existingNft.source === Source.Detected)\n ) {\n try {\n const networkClientId = this.messenger.call(\n 'NetworkController:findNetworkClientIdByChainId',\n hexChainId,\n );\n this.#removeNft(contract, tokenId, networkClientId, {\n userAddress,\n });\n } catch {\n // Network may not be configured; skip this NFT\n }\n }\n }\n\n // Proceed to add NFTs\n const nftsToAdd = apiNfts\n .map((nft) => {\n const {\n tokenId,\n contract,\n kind,\n image: imageUrl,\n imageSmall: imageThumbnailUrl,\n metadata,\n name,\n description,\n attributes,\n topBid,\n lastSale,\n rarityRank,\n rarityScore,\n collection,\n chainId,\n } = nft.token;\n\n // Use a fallback if metadata is null\n const { imageOriginal: imageOriginalUrl } = metadata ?? {};\n\n let ignored;\n /* istanbul ignore else */\n const { ignoredNfts } = this.#getNftState();\n if (ignoredNfts.length) {\n ignored = ignoredNfts.find((ignoredNft) => {\n /* istanbul ignore next */\n return (\n ignoredNft.address === toChecksumHexAddress(contract) &&\n ignoredNft.tokenId === tokenId\n );\n });\n }\n\n /* istanbul ignore else */\n if (!ignored) {\n /* istanbul ignore next */\n const nftMetadata: NftMetadata & { chainId: number } =\n Object.assign(\n {},\n { name },\n description && { description },\n imageUrl && { image: imageUrl },\n imageThumbnailUrl && { imageThumbnail: imageThumbnailUrl },\n imageOriginalUrl && { imageOriginal: imageOriginalUrl },\n kind && { standard: kind.toUpperCase() },\n lastSale && { lastSale },\n attributes && { attributes },\n topBid && { topBid },\n rarityRank && { rarityRank },\n rarityScore && { rarityScore },\n collection && { collection },\n chainId && { chainId },\n );\n\n return {\n tokenAddress: contract,\n tokenId,\n nftMetadata,\n };\n }\n return;\n })\n .filter((nft): nft is NonNullable<typeof nft> => nft !== undefined);\n\n await this.#addNfts(nftsToAdd, userAddress, Source.Detected);\n } while (\n (next = resultNftApi.continuation) &&\n !options?.firstPageOnly &&\n !options?.signal?.aborted\n );\n updateSucceeded();\n } catch (error) {\n updateFailed(error);\n throw error;\n } finally {\n delete this.#inProcessNftFetchingUpdates[updateKey];\n }\n }\n}\n\nexport default NftDetectionController;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/assets-controllers",
3
- "version": "112.2.0-preview-4a8d4a2",
3
+ "version": "112.2.0-preview-5669a8ae0",
4
4
  "description": "Controllers which manage interactions involving ERC-20, ERC-721, and ERC-1155 tokens (including NFTs)",
5
5
  "keywords": [
6
6
  "Ethereum",