@metamask-previews/assets-controllers 56.0.0-preview-3fadbce0 → 56.0.0-preview-01658838

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.
@@ -1 +1 @@
1
- {"version":3,"file":"NftController.mjs","sourceRoot":"","sources":["../src/NftController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,+BAA+B;AAWnD,OAAO,EACL,cAAc,EAEf,kCAAkC;AACnC,OAAO,EACL,aAAa,EACb,WAAW,EACX,oBAAoB,EACpB,OAAO,EACP,sBAAsB,EACtB,wBAAwB,EACxB,MAAM,EACN,OAAO,EACP,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,KAAK,EACN,mCAAmC;AAUpC,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAEjD,OAAO,EAAE,QAAQ,EAAE,wBAAwB;AAC3C,OAAO,EAAE,KAAK,EAAE,oBAAoB;AACpC,OAAO,GAAE,cAAc;;AACvB,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,aAAa;AAUpC,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACvB,yBAAqB;AACtB,OAAO,EAAE,MAAM,EAAE,wBAAoB;AAqJrC,MAAM,qBAAqB,GAAG;IAC5B,eAAe,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE;IACpD,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE;IAC5C,WAAW,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE;CACjD,CAAC;AAEF,MAAM,kBAAkB,GAAG,SAAS,CAAC;AACrC,MAAM,4BAA4B,GAAG,iBAAiB,CAAC;AAOvD;;GAEG;AACH,MAAM,cAAc,GAAG,eAAe,CAAC;AA8CvC,MAAM,CAAC,MAAM,4BAA4B,GAA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,EAAE,CAC1C,CAAC,IAAI,EAAE,CAAC;IAET,mBAAmB;IACnB,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAC9B,CAAC,SAAS,EAAE,EAAE,CACZ,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,WAAW,IAAI,CAAC,SAAS,CAAC,KAAK,CAChE,CAAC;IACF,IACE,YAAY,CAAC,MAAM,KAAK,CAAC;QACzB,YAAY,CAAC,MAAM,GAAG,oBAAoB,EAC1C;QACA,oCAAoC;QACpC,MAAM,IAAI,CAAC,iBAAiB,CAAC;YAC3B,IAAI,EAAE,YAAY;YAClB,WAAW,EAAE,OAAO,CAAC,OAAO;SAC7B,CAAC,CAAC;KACJ;AACH,CAAC;AAYH,eAAe,aAAa,CAAC","sourcesContent":["import { isAddress } from '@ethersproject/address';\nimport type {\n AccountsControllerSelectedEvmAccountChangeEvent,\n AccountsControllerGetAccountAction,\n AccountsControllerGetSelectedAccountAction,\n} from '@metamask/accounts-controller';\nimport type { AddApprovalRequest } from '@metamask/approval-controller';\nimport type {\n RestrictedMessenger,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport {\n BaseController,\n type ControllerGetStateAction,\n} from '@metamask/base-controller';\nimport {\n safelyExecute,\n handleFetch,\n toChecksumHexAddress,\n BNToHex,\n fetchWithErrorHandling,\n IPFS_DEFAULT_GATEWAY_URL,\n ERC721,\n ERC1155,\n ApprovalType,\n NFT_API_BASE_URL,\n NFT_API_VERSION,\n convertHexToDecimal,\n toHex,\n} from '@metamask/controller-utils';\nimport { type InternalAccount } from '@metamask/keyring-internal-api';\nimport type {\n NetworkClientId,\n NetworkControllerGetNetworkClientByIdAction,\n} from '@metamask/network-controller';\nimport type {\n PreferencesControllerStateChangeEvent,\n PreferencesState,\n} from '@metamask/preferences-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { Hex } from '@metamask/utils';\nimport { remove0x } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\nimport BN from 'bn.js';\nimport { v4 as random } from 'uuid';\n\nimport type {\n AssetsContractControllerGetERC1155BalanceOfAction,\n AssetsContractControllerGetERC1155TokenURIAction,\n AssetsContractControllerGetERC721AssetNameAction,\n AssetsContractControllerGetERC721AssetSymbolAction,\n AssetsContractControllerGetERC721OwnerOfAction,\n AssetsContractControllerGetERC721TokenURIAction,\n} from './AssetsContractController';\nimport {\n compareNftMetadata,\n getFormattedIpfsUrl,\n hasNewCollectionFields,\n} from './assetsUtil';\nimport { Source } from './constants';\nimport type {\n ApiNftContract,\n ReservoirResponse,\n Collection,\n Attributes,\n LastSale,\n GetCollectionsResponse,\n TopBid,\n} from './NftDetectionController';\nimport type { NetworkControllerGetNetworkClientIdByChainIdAction } from '../../network-controller/src/NetworkController';\n\nexport type NFTStandardType = 'ERC721' | 'ERC1155';\n\ntype SuggestedNftMeta = {\n asset: { address: string; tokenId: string } & NftMetadata;\n id: string;\n time: number;\n type: NFTStandardType;\n interactingAddress: string;\n origin: string;\n};\n\n/**\n * @type Nft\n *\n * NFT representation\n * @property address - Hex address of a ERC721 contract\n * @property description - The NFT description\n * @property image - URI of custom NFT image associated with this tokenId\n * @property name - Name associated with this tokenId and contract address\n * @property tokenId - The NFT identifier\n * @property numberOfSales - Number of sales\n * @property backgroundColor - The background color to be displayed with the item\n * @property imagePreview - URI of a smaller image associated with this NFT\n * @property imageThumbnail - URI of a thumbnail image associated with this NFT\n * @property imageOriginal - URI of the original image associated with this NFT\n * @property animation - URI of a animation associated with this NFT\n * @property animationOriginal - URI of the original animation associated with this NFT\n * @property externalLink - External link containing additional information\n * @property creator - The NFT owner information object\n * @property isCurrentlyOwned - Boolean indicating whether the address/chainId combination where it's currently stored currently owns this NFT\n * @property transactionId - Transaction Id associated with the NFT\n */\nexport type Nft = {\n tokenId: string;\n address: string;\n isCurrentlyOwned?: boolean;\n} & NftMetadata;\n\ntype NftUpdate = {\n nft: Nft;\n newMetadata: NftMetadata;\n};\n\n/**\n * @type NftContract\n *\n * NFT contract information representation\n * @property name - Contract name\n * @property logo - Contract logo\n * @property address - Contract address\n * @property symbol - Contract symbol\n * @property description - Contract description\n * @property totalSupply - Total supply of NFTs\n * @property assetContractType - The NFT type, it could be `semi-fungible` or `non-fungible`\n * @property createdDate - Creation date\n * @property schemaName - The schema followed by the contract, it could be `ERC721` or `ERC1155`\n * @property externalLink - External link containing additional information\n */\nexport type NftContract = {\n name?: string;\n logo?: string;\n address: string;\n symbol?: string;\n description?: string;\n totalSupply?: string;\n assetContractType?: string;\n createdDate?: string;\n schemaName?: string;\n externalLink?: string;\n};\n\n/**\n * @type NftMetadata\n *\n * NFT custom information\n * @property name - NFT custom name\n * @property description - The NFT description\n * @property numberOfSales - Number of sales\n * @property backgroundColor - The background color to be displayed with the item\n * @property image - Image custom image URI\n * @property imagePreview - URI of a smaller image associated with this NFT\n * @property imageThumbnail - URI of a thumbnail image associated with this NFT\n * @property imageOriginal - URI of the original image associated with this NFT\n * @property animation - URI of a animation associated with this NFT\n * @property animationOriginal - URI of the original animation associated with this NFT\n * @property externalLink - External link containing additional information\n * @property creator - The NFT owner information object\n * @property standard - NFT standard name for the NFT, e.g., ERC-721 or ERC-1155\n */\nexport type NftMetadata = {\n name: string | null;\n description: string | null;\n image: string | null;\n standard: string | null;\n favorite?: boolean;\n numberOfSales?: number;\n backgroundColor?: string;\n imagePreview?: string;\n imageThumbnail?: string;\n imageOriginal?: string;\n animation?: string;\n animationOriginal?: string;\n externalLink?: string;\n creator?: string;\n transactionId?: string;\n tokenURI?: string | null;\n collection?: Collection;\n address?: string;\n attributes?: Attributes[];\n lastSale?: LastSale;\n rarityRank?: string;\n topBid?: TopBid;\n chainId?: number;\n};\n\n/**\n * @type NftControllerState\n *\n * NFT controller state\n * @property allNftContracts - Object containing NFT contract information\n * @property allNfts - Object containing NFTs per account and network\n * @property ignoredNfts - List of NFTs that should be ignored\n */\nexport type NftControllerState = {\n allNftContracts: {\n [key: string]: {\n [chainId: Hex]: NftContract[];\n };\n };\n allNfts: {\n [key: string]: {\n [chainId: Hex]: Nft[];\n };\n };\n ignoredNfts: Nft[];\n};\n\nconst nftControllerMetadata = {\n allNftContracts: { persist: true, anonymous: false },\n allNfts: { persist: true, anonymous: false },\n ignoredNfts: { persist: true, anonymous: false },\n};\n\nconst ALL_NFTS_STATE_KEY = 'allNfts';\nconst ALL_NFTS_CONTRACTS_STATE_KEY = 'allNftContracts';\n\ntype NftAsset = {\n address: string;\n tokenId: string;\n};\n\n/**\n * The name of the {@link NftController}.\n */\nconst controllerName = 'NftController';\n\nexport type NftControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n NftControllerState\n>;\nexport type NftControllerActions = NftControllerGetStateAction;\n\n/**\n * The external actions available to the {@link NftController}.\n */\nexport type AllowedActions =\n | AddApprovalRequest\n | AccountsControllerGetAccountAction\n | AccountsControllerGetSelectedAccountAction\n | NetworkControllerGetNetworkClientByIdAction\n | AssetsContractControllerGetERC721AssetNameAction\n | AssetsContractControllerGetERC721AssetSymbolAction\n | AssetsContractControllerGetERC721TokenURIAction\n | AssetsContractControllerGetERC721OwnerOfAction\n | AssetsContractControllerGetERC1155BalanceOfAction\n | AssetsContractControllerGetERC1155TokenURIAction\n | NetworkControllerGetNetworkClientIdByChainIdAction;\n\nexport type AllowedEvents =\n | PreferencesControllerStateChangeEvent\n | AccountsControllerSelectedEvmAccountChangeEvent;\n\nexport type NftControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n NftControllerState\n>;\n\nexport type NftControllerEvents = NftControllerStateChangeEvent;\n\n/**\n * The messenger of the {@link NftController}.\n */\nexport type NftControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n NftControllerActions | AllowedActions,\n NftControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\nexport const getDefaultNftControllerState = (): NftControllerState => ({\n allNftContracts: {},\n allNfts: {},\n ignoredNfts: [],\n});\n\nconst NFT_UPDATE_THRESHOLD = 500;\n\n/**\n * Controller that stores assets and exposes convenience methods\n */\nexport class NftController extends BaseController<\n typeof controllerName,\n NftControllerState,\n NftControllerMessenger\n> {\n readonly #mutex = new Mutex();\n\n /**\n * Optional API key to use with opensea\n */\n openSeaApiKey?: string;\n\n #selectedAccountId: string;\n\n #ipfsGateway: string;\n\n #openSeaEnabled: boolean;\n\n #useIpfsSubdomains: boolean;\n\n #isIpfsGatewayEnabled: boolean;\n\n readonly #onNftAdded?: (data: {\n address: string;\n symbol: string | undefined;\n tokenId: string;\n standard: string | null;\n source: Source;\n }) => void;\n\n /**\n * Creates an NftController instance.\n *\n * @param options - The controller options.\n * @param options.ipfsGateway - The configured IPFS gateway.\n * @param options.openSeaEnabled - Controls whether the OpenSea API is used.\n * @param options.useIpfsSubdomains - Controls whether IPFS subdomains are used.\n * @param options.isIpfsGatewayEnabled - Controls whether IPFS is enabled or not.\n * @param options.onNftAdded - Callback that is called when an NFT is added. Currently used pass data\n * for tracking the NFT added event.\n * @param options.messenger - The messenger.\n * @param options.state - Initial state to set on this controller.\n */\n constructor({\n ipfsGateway = IPFS_DEFAULT_GATEWAY_URL,\n openSeaEnabled = false,\n useIpfsSubdomains = true,\n isIpfsGatewayEnabled = true,\n onNftAdded,\n messenger,\n state = {},\n }: {\n ipfsGateway?: string;\n openSeaEnabled?: boolean;\n useIpfsSubdomains?: boolean;\n isIpfsGatewayEnabled?: boolean;\n onNftAdded?: (data: {\n address: string;\n symbol: string | undefined;\n tokenId: string;\n standard: string | null;\n source: string;\n }) => void;\n messenger: NftControllerMessenger;\n state?: Partial<NftControllerState>;\n }) {\n super({\n name: controllerName,\n metadata: nftControllerMetadata,\n messenger,\n state: {\n ...getDefaultNftControllerState(),\n ...state,\n },\n });\n\n this.#selectedAccountId = this.messagingSystem.call(\n 'AccountsController:getSelectedAccount',\n ).id;\n this.#ipfsGateway = ipfsGateway;\n this.#openSeaEnabled = openSeaEnabled;\n this.#useIpfsSubdomains = useIpfsSubdomains;\n this.#isIpfsGatewayEnabled = isIpfsGatewayEnabled;\n this.#onNftAdded = onNftAdded;\n\n this.messagingSystem.subscribe(\n 'PreferencesController:stateChange',\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.#onPreferencesControllerStateChange.bind(this),\n );\n\n this.messagingSystem.subscribe(\n 'AccountsController:selectedEvmAccountChange',\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.#onSelectedAccountChange.bind(this),\n );\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.ipfsGateway - The configured IPFS gateway.\n * @param preferencesState.openSeaEnabled - Controls whether the OpenSea API is used.\n * @param preferencesState.isIpfsGatewayEnabled - Controls whether IPFS is enabled or not.\n */\n async #onPreferencesControllerStateChange({\n ipfsGateway,\n openSeaEnabled,\n isIpfsGatewayEnabled,\n }: PreferencesState) {\n const selectedAccount = this.messagingSystem.call(\n 'AccountsController:getSelectedAccount',\n );\n this.#selectedAccountId = selectedAccount.id;\n // Get current state values\n if (\n this.#ipfsGateway !== ipfsGateway ||\n this.#openSeaEnabled !== openSeaEnabled ||\n this.#isIpfsGatewayEnabled !== isIpfsGatewayEnabled\n ) {\n this.#ipfsGateway = ipfsGateway;\n this.#openSeaEnabled = openSeaEnabled;\n this.#isIpfsGatewayEnabled = isIpfsGatewayEnabled;\n const needsUpdateNftMetadata =\n (isIpfsGatewayEnabled && ipfsGateway !== '') || openSeaEnabled;\n\n if (needsUpdateNftMetadata && selectedAccount) {\n await this.#updateNftUpdateForAccount(selectedAccount);\n }\n }\n }\n\n /**\n * Handles the selected account change on the accounts controller.\n *\n * @param internalAccount - The new selected account.\n */\n async #onSelectedAccountChange(internalAccount: InternalAccount) {\n const oldSelectedAccountId = this.#selectedAccountId;\n this.#selectedAccountId = internalAccount.id;\n\n const needsUpdateNftMetadata =\n ((this.#isIpfsGatewayEnabled && this.#ipfsGateway !== '') ||\n this.#openSeaEnabled) &&\n oldSelectedAccountId !== internalAccount.id;\n\n if (needsUpdateNftMetadata) {\n await this.#updateNftUpdateForAccount(internalAccount);\n }\n }\n\n getNftApi() {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n return `${NFT_API_BASE_URL}/tokens`;\n }\n\n /**\n * Helper method to update nested state for allNfts and allNftContracts.\n *\n * @param newCollection - the modified piece of state to update in the controller's store\n * @param baseStateKey - The root key in the store to update.\n * @param passedConfig - An object containing the selectedAddress and chainId that are passed through the auto-detection flow.\n * @param passedConfig.userAddress - the address passed through the NFT detection flow to ensure assets are stored to the correct account\n * @param passedConfig.chainId - the chainId passed through the NFT detection flow to ensure assets are stored to the correct account\n */\n #updateNestedNftState<\n Key extends typeof ALL_NFTS_STATE_KEY | typeof ALL_NFTS_CONTRACTS_STATE_KEY,\n NftCollection extends Key extends typeof ALL_NFTS_STATE_KEY\n ? Nft[]\n : NftContract[],\n >(\n newCollection: NftCollection,\n baseStateKey: Key,\n { userAddress, chainId }: { userAddress: string; chainId: Hex },\n ) {\n // userAddress can be an empty string if it is not set via an account change or in constructor\n // while this doesn't cause any issues, we want to ensure that we don't store assets to an empty string address\n if (!userAddress) {\n return;\n }\n\n this.update((state) => {\n const oldState = state[baseStateKey];\n const addressState = oldState[userAddress] || {};\n const newAddressState = {\n ...addressState,\n [chainId]: newCollection,\n };\n state[baseStateKey] = {\n ...oldState,\n [userAddress]: newAddressState,\n };\n });\n }\n\n #getNftCollectionApi(): string {\n // False negative.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n return `${NFT_API_BASE_URL}/collections`;\n }\n\n /**\n * Request individual NFT information from NFT API.\n *\n * @param contractAddress - Hex address of the NFT contract.\n * @param tokenId - The NFT identifier.\n * @returns Promise resolving to the current NFT name and image.\n */\n async #getNftInformationFromApi(\n contractAddress: string,\n tokenId: string,\n ): Promise<NftMetadata> {\n // TODO Parameterize this by chainId for non-mainnet token detection\n // Attempt to fetch the data with the nft-api\n const urlParams = new URLSearchParams({\n chainIds: '1',\n tokens: `${contractAddress}:${tokenId}`,\n includeTopBid: 'true',\n includeAttributes: 'true',\n includeLastSale: 'true',\n }).toString();\n\n // First fetch token information\n const nftInformation: ReservoirResponse | undefined =\n await fetchWithErrorHandling({\n url: `${this.getNftApi()}?${urlParams}`,\n options: {\n headers: {\n Version: NFT_API_VERSION,\n },\n },\n });\n // Params for getCollections API call\n const getCollectionParams = new URLSearchParams({\n chainId: '1',\n id: `${nftInformation?.tokens[0]?.token?.collection?.id as string}`,\n }).toString();\n // Fetch collection information using collectionId\n const collectionInformation: GetCollectionsResponse | undefined =\n await fetchWithErrorHandling({\n url: `${NFT_API_BASE_URL as string}/collections?${getCollectionParams}`,\n options: {\n headers: {\n Version: NFT_API_VERSION,\n },\n },\n });\n // if we were still unable to fetch the data we return out the default/null of `NftMetadata`\n if (!nftInformation?.tokens?.[0]?.token) {\n return {\n name: null,\n description: null,\n image: null,\n standard: null,\n };\n }\n\n // if we've reached this point, we have successfully fetched some data for nftInformation\n // now we reconfigure the data to conform to the `NftMetadata` type for storage.\n\n const {\n image,\n metadata: { imageOriginal } = {},\n name,\n description,\n collection,\n kind,\n rarityRank,\n rarity,\n attributes,\n lastSale,\n imageSmall,\n } = nftInformation.tokens[0].token;\n\n /* istanbul ignore next */\n const nftMetadata: NftMetadata = Object.assign(\n {},\n { name: name || null },\n { description: description || null },\n { image: image || null },\n collection?.creator && { creator: collection.creator },\n imageOriginal && { imageOriginal },\n imageSmall && { imageThumbnail: imageSmall },\n kind && { standard: kind.toUpperCase() },\n lastSale && { lastSale },\n attributes && { attributes },\n nftInformation.tokens[0].market?.topBid && {\n topBid: nftInformation.tokens[0].market?.topBid,\n },\n rarityRank && { rarityRank },\n rarity && { rarity },\n (collection || collectionInformation) && {\n collection: {\n ...(collection || {}),\n creator:\n collection?.creator ||\n collectionInformation?.collections[0].creator,\n openseaVerificationStatus:\n collectionInformation?.collections[0].openseaVerificationStatus,\n contractDeployedAt:\n collectionInformation?.collections[0].contractDeployedAt,\n ownerCount: collectionInformation?.collections[0].ownerCount,\n topBid: collectionInformation?.collections[0].topBid,\n },\n },\n );\n\n return nftMetadata;\n }\n\n /**\n * Request individual NFT information from contracts that follows Metadata Interface.\n *\n * @param contractAddress - Hex address of the NFT contract.\n * @param tokenId - The NFT identifier.\n * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @returns Promise resolving to the current NFT name and image.\n */\n async #getNftInformationFromTokenURI(\n contractAddress: string,\n tokenId: string,\n networkClientId: NetworkClientId,\n ): Promise<NftMetadata> {\n const result = await this.#getNftURIAndStandard(\n contractAddress,\n tokenId,\n networkClientId,\n );\n let tokenURI = result[0];\n const standard = result[1];\n\n const hasIpfsTokenURI = tokenURI.startsWith('ipfs://');\n\n if (hasIpfsTokenURI && !this.#isIpfsGatewayEnabled) {\n return {\n image: null,\n name: null,\n description: null,\n standard: standard || null,\n favorite: false,\n tokenURI: tokenURI ?? null,\n };\n }\n\n const isDisplayNFTMediaToggleEnabled = this.#openSeaEnabled;\n if (!hasIpfsTokenURI && !isDisplayNFTMediaToggleEnabled) {\n return {\n image: null,\n name: null,\n description: null,\n standard: standard || null,\n favorite: false,\n tokenURI: tokenURI ?? null,\n };\n }\n\n if (hasIpfsTokenURI) {\n tokenURI = await getFormattedIpfsUrl(\n this.#ipfsGateway,\n tokenURI,\n this.#useIpfsSubdomains,\n );\n }\n if (tokenURI.startsWith('data:image/')) {\n return {\n image: tokenURI,\n name: null,\n description: null,\n standard: standard || null,\n favorite: false,\n tokenURI: tokenURI ?? null,\n };\n }\n\n try {\n const object = await handleFetch(tokenURI);\n // TODO: Check image_url existence. This is not part of EIP721 nor EIP1155\n const image = Object.prototype.hasOwnProperty.call(object, 'image')\n ? 'image'\n : /* istanbul ignore next */ 'image_url';\n\n return {\n image: object[image],\n name: object.name,\n description: object.description,\n standard,\n favorite: false,\n tokenURI: tokenURI ?? null,\n };\n } catch {\n return {\n image: null,\n name: null,\n description: null,\n standard: standard || null,\n favorite: false,\n tokenURI: tokenURI ?? null,\n };\n }\n }\n\n /**\n * Retrieve NFT uri with metadata. TODO Update method to use IPFS.\n *\n * @param contractAddress - NFT contract address.\n * @param tokenId - NFT token id.\n * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @returns Promise resolving NFT uri and token standard.\n */\n async #getNftURIAndStandard(\n contractAddress: string,\n tokenId: string,\n networkClientId: NetworkClientId,\n ): Promise<[string, string]> {\n // try ERC721 uri\n try {\n const uri = await this.messagingSystem.call(\n 'AssetsContractController:getERC721TokenURI',\n contractAddress,\n tokenId,\n networkClientId,\n );\n return [uri, ERC721];\n } catch {\n // Ignore error\n }\n\n // try ERC1155 uri\n try {\n const tokenURI = await this.messagingSystem.call(\n 'AssetsContractController:getERC1155TokenURI',\n contractAddress,\n tokenId,\n networkClientId,\n );\n\n /**\n * According to EIP1155 the URI value allows for ID substitution\n * in case the string `{id}` exists.\n * https://eips.ethereum.org/EIPS/eip-1155#metadata\n */\n\n if (!tokenURI.includes('{id}')) {\n return [tokenURI, ERC1155];\n }\n\n const hexTokenId = remove0x(BNToHex(new BN(tokenId)))\n .padStart(64, '0')\n .toLowerCase();\n return [tokenURI.replace('{id}', hexTokenId), ERC1155];\n } catch {\n // Ignore error\n }\n\n return ['', ''];\n }\n\n /**\n * Request individual NFT information (name, image url and description).\n *\n * @param contractAddress - Hex address of the NFT contract.\n * @param tokenId - The NFT identifier.\n * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @returns Promise resolving to the current NFT name and image.\n */\n async #getNftInformation(\n contractAddress: string,\n tokenId: string,\n networkClientId: NetworkClientId,\n ): Promise<NftMetadata> {\n const {\n configuration: { chainId },\n } = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n const [blockchainMetadata, nftApiMetadata] = await Promise.all([\n safelyExecute(() =>\n this.#getNftInformationFromTokenURI(\n contractAddress,\n tokenId,\n networkClientId,\n ),\n ),\n this.#openSeaEnabled && chainId === '0x1'\n ? safelyExecute(() =>\n this.#getNftInformationFromApi(contractAddress, tokenId),\n )\n : undefined,\n ]);\n return {\n ...nftApiMetadata,\n name: blockchainMetadata?.name ?? nftApiMetadata?.name ?? null,\n description:\n blockchainMetadata?.description ?? nftApiMetadata?.description ?? null,\n image: nftApiMetadata?.image ?? blockchainMetadata?.image ?? null,\n standard:\n blockchainMetadata?.standard ?? nftApiMetadata?.standard ?? null,\n tokenURI: blockchainMetadata?.tokenURI ?? null,\n };\n }\n\n /**\n * Request NFT contract information from the contract itself.\n *\n * @param contractAddress - Hex address of the NFT contract.\n * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @returns Promise resolving to the current NFT name and image.\n */\n async #getNftContractInformationFromContract(\n // TODO for calls to blockchain we need to explicitly pass the currentNetworkClientId since its relying on the provider\n contractAddress: string,\n networkClientId: NetworkClientId,\n ): Promise<\n Partial<ApiNftContract> &\n Pick<ApiNftContract, 'address'> &\n Pick<ApiNftContract, 'collection'>\n > {\n const [name, symbol] = await Promise.all([\n this.messagingSystem.call(\n 'AssetsContractController:getERC721AssetName',\n contractAddress,\n networkClientId,\n ),\n this.messagingSystem.call(\n 'AssetsContractController:getERC721AssetSymbol',\n contractAddress,\n networkClientId,\n ),\n ]);\n\n return {\n collection: { name },\n symbol,\n address: contractAddress,\n };\n }\n\n /**\n * Request NFT contract information from Blockchain and aggregate with received data from NFTMetadata.\n *\n * @param contractAddress - Hex address of the NFT contract.\n * @param nftMetadataFromApi - Received NFT information to be aggregated with blockchain contract information.\n * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @returns Promise resolving to the NFT contract name, image and description.\n */\n async #getNftContractInformation(\n contractAddress: string,\n nftMetadataFromApi: NftMetadata,\n networkClientId: NetworkClientId,\n ): Promise<\n Partial<ApiNftContract> &\n Pick<ApiNftContract, 'address'> &\n Pick<ApiNftContract, 'collection'>\n > {\n const blockchainContractData = await safelyExecute(() =>\n this.#getNftContractInformationFromContract(\n contractAddress,\n networkClientId,\n ),\n );\n\n if (\n blockchainContractData ||\n !Object.values(nftMetadataFromApi).every((value) => value === null)\n ) {\n return {\n address: contractAddress,\n ...blockchainContractData,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n schema_name: nftMetadataFromApi?.standard ?? null,\n collection: {\n name: null,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n image_url:\n nftMetadataFromApi?.collection?.image ??\n nftMetadataFromApi?.collection?.imageUrl ??\n null,\n tokenCount: nftMetadataFromApi?.collection?.tokenCount ?? null,\n ...nftMetadataFromApi?.collection,\n ...blockchainContractData?.collection,\n },\n };\n }\n\n /* istanbul ignore next */\n return {\n address: contractAddress,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n asset_contract_type: null,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n created_date: null,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n schema_name: null,\n symbol: null,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n total_supply: null,\n description: null,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n external_link: null,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n collection: { name: null, image_url: null },\n };\n }\n\n /**\n * Adds an individual NFT to the stored NFT list.\n *\n * @param tokenAddress - Hex address of the NFT contract.\n * @param tokenId - The NFT identifier.\n * @param nftMetadata - NFT optional information (name, image and description).\n * @param nftContract - An object containing contract data of the NFT being added.\n * @param chainId - The chainId of the network where the NFT is being added.\n * @param userAddress - The address of the account where the NFT is being added.\n * @param source - Whether the NFT was detected, added manually or suggested by a dapp.\n * @returns A promise resolving to `undefined`.\n */\n async #addIndividualNft(\n tokenAddress: string,\n tokenId: string,\n nftMetadata: NftMetadata,\n nftContract: NftContract,\n chainId: Hex,\n userAddress: string,\n source: Source,\n ): Promise<void> {\n const releaseLock = await this.#mutex.acquire();\n try {\n const checksumHexAddress = toChecksumHexAddress(tokenAddress);\n const { allNfts } = this.state;\n\n const nfts = [...(allNfts[userAddress]?.[chainId] ?? [])];\n\n const existingEntry = nfts.find(\n (nft) =>\n nft.address.toLowerCase() === checksumHexAddress.toLowerCase() &&\n nft.tokenId === tokenId,\n );\n\n if (existingEntry) {\n const differentMetadata = compareNftMetadata(\n nftMetadata,\n existingEntry,\n );\n\n const hasNewFields = hasNewCollectionFields(nftMetadata, existingEntry);\n\n if (\n !differentMetadata &&\n existingEntry.isCurrentlyOwned &&\n !hasNewFields\n ) {\n return;\n }\n\n const indexToUpdate = nfts.findIndex(\n (nft) =>\n nft.address.toLowerCase() === checksumHexAddress.toLowerCase() &&\n nft.tokenId === tokenId,\n );\n\n if (indexToUpdate !== -1) {\n nfts[indexToUpdate] = {\n ...existingEntry,\n ...nftMetadata,\n };\n }\n } else {\n const newEntry: Nft = {\n address: checksumHexAddress,\n tokenId,\n favorite: false,\n isCurrentlyOwned: true,\n ...nftMetadata,\n };\n\n nfts.push(newEntry);\n }\n\n this.#updateNestedNftState(nfts, ALL_NFTS_STATE_KEY, {\n chainId,\n userAddress,\n });\n\n if (this.#onNftAdded) {\n this.#onNftAdded({\n address: checksumHexAddress,\n symbol: nftContract.symbol,\n tokenId: tokenId.toString(),\n standard: nftMetadata.standard,\n source,\n });\n }\n } finally {\n releaseLock();\n }\n }\n\n /**\n * Adds an NFT contract to the stored NFT contracts list.\n *\n * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @param options - options.\n * @param options.tokenAddress - Hex address of the NFT contract.\n * @param options.userAddress - The address of the account where the NFT is being added.\n * @param options.nftMetadata - The retrieved NFTMetadata from API.\n * @param options.source - Whether the NFT was detected, added manually or suggested by a dapp.\n * @returns Promise resolving to the current NFT contracts list.\n */\n async #addNftContract(\n networkClientId: NetworkClientId,\n {\n tokenAddress,\n userAddress,\n source,\n nftMetadata,\n }: {\n tokenAddress: string;\n userAddress: string;\n nftMetadata: NftMetadata;\n source?: Source;\n },\n ): Promise<NftContract[]> {\n const releaseLock = await this.#mutex.acquire();\n try {\n const checksumHexAddress = toChecksumHexAddress(tokenAddress);\n const { allNftContracts } = this.state;\n const {\n configuration: { chainId },\n } = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n networkClientId as NetworkClientId,\n );\n\n const nftContracts = allNftContracts[userAddress]?.[chainId] || [];\n\n const existingEntry = nftContracts.find(\n (nftContract) =>\n nftContract.address.toLowerCase() ===\n checksumHexAddress.toLowerCase(),\n );\n if (existingEntry) {\n return nftContracts;\n }\n\n // this doesn't work currently for detection if the user switches networks while the detection is processing\n // will be fixed once detection uses networkClientIds\n // get name and symbol if ERC721 then put together the metadata\n const contractInformation = await this.#getNftContractInformation(\n checksumHexAddress,\n nftMetadata,\n networkClientId,\n );\n const {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n asset_contract_type,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n created_date,\n symbol,\n description,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n external_link,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n schema_name,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n collection: { name, image_url, tokenCount },\n } = contractInformation;\n\n // If the nft is auto-detected we want some valid metadata to be present\n if (\n source === Source.Detected &&\n 'address' in contractInformation &&\n typeof contractInformation.address === 'string' &&\n 'collection' in contractInformation &&\n contractInformation.collection.name === null &&\n 'image_url' in contractInformation.collection &&\n contractInformation.collection.image_url === null &&\n Object.entries(contractInformation).every(([key, value]) => {\n return key === 'address' || key === 'collection' || !value;\n })\n ) {\n return nftContracts;\n }\n\n /* istanbul ignore next */\n const newEntry: NftContract = Object.assign(\n {},\n { address: checksumHexAddress },\n description && { description },\n name && { name },\n image_url && { logo: image_url },\n symbol && { symbol },\n tokenCount !== null &&\n typeof tokenCount !== 'undefined' && { totalSupply: tokenCount },\n asset_contract_type && { assetContractType: asset_contract_type },\n created_date && { createdDate: created_date },\n schema_name && { schemaName: schema_name },\n external_link && { externalLink: external_link },\n );\n const newNftContracts = [...nftContracts, newEntry];\n this.#updateNestedNftState(\n newNftContracts,\n ALL_NFTS_CONTRACTS_STATE_KEY,\n {\n chainId,\n userAddress,\n },\n );\n\n return newNftContracts;\n } finally {\n releaseLock();\n }\n }\n\n /**\n * Removes an individual NFT from the stored token list and saves it in ignored NFTs list.\n *\n * @param address - Hex address of the NFT contract.\n * @param tokenId - Token identifier of the NFT.\n * @param options - options.\n * @param options.chainId - The chainId of the network where the NFT is being removed.\n * @param options.userAddress - The address of the account where the NFT is being removed.\n */\n #removeAndIgnoreIndividualNft(\n address: string,\n tokenId: string,\n {\n chainId,\n userAddress,\n }: {\n chainId: Hex;\n userAddress: string;\n },\n ) {\n const checksumHexAddress = toChecksumHexAddress(address);\n const { allNfts, ignoredNfts } = this.state;\n const newIgnoredNfts = [...ignoredNfts];\n const nfts = allNfts[userAddress]?.[chainId] || [];\n const newNfts = nfts.filter((nft) => {\n if (\n nft.address.toLowerCase() === checksumHexAddress.toLowerCase() &&\n nft.tokenId === tokenId\n ) {\n const alreadyIgnored = newIgnoredNfts.find(\n (c) => c.address === checksumHexAddress && c.tokenId === tokenId,\n );\n !alreadyIgnored && newIgnoredNfts.push(nft);\n return false;\n }\n return true;\n });\n\n this.#updateNestedNftState(newNfts, ALL_NFTS_STATE_KEY, {\n userAddress,\n chainId,\n });\n\n this.update((state) => {\n state.ignoredNfts = newIgnoredNfts;\n });\n }\n\n /**\n * Removes an individual NFT from the stored token list.\n *\n * @param address - Hex address of the NFT contract.\n * @param tokenId - Token identifier of the NFT.\n * @param options - options.\n * @param options.chainId - The chainId of the network where the NFT is being removed.\n * @param options.userAddress - The address of the account where the NFT is being removed.\n */\n #removeIndividualNft(\n address: string,\n tokenId: string,\n { chainId, userAddress }: { chainId: Hex; userAddress: string },\n ) {\n const checksumHexAddress = toChecksumHexAddress(address);\n const { allNfts } = this.state;\n const nfts = allNfts[userAddress]?.[chainId] || [];\n const newNfts = nfts.filter(\n (nft) =>\n !(\n nft.address.toLowerCase() === checksumHexAddress.toLowerCase() &&\n nft.tokenId === tokenId\n ),\n );\n this.#updateNestedNftState(newNfts, ALL_NFTS_STATE_KEY, {\n userAddress,\n chainId,\n });\n }\n\n /**\n * Removes an NFT contract to the stored NFT contracts list.\n *\n * @param address - Hex address of the NFT contract.\n * @param options - options.\n * @param options.chainId - The chainId of the network where the NFT is being removed.\n * @param options.userAddress - The address of the account where the NFT is being removed.\n * @returns Promise resolving to the current NFT contracts list.\n */\n #removeNftContract(\n address: string,\n { chainId, userAddress }: { chainId: Hex; userAddress: string },\n ): NftContract[] {\n const checksumHexAddress = toChecksumHexAddress(address);\n const { allNftContracts } = this.state;\n const nftContracts = allNftContracts[userAddress]?.[chainId] || [];\n\n const newNftContracts = nftContracts.filter(\n (nftContract) =>\n !(\n nftContract.address.toLowerCase() === checksumHexAddress.toLowerCase()\n ),\n );\n this.#updateNestedNftState(newNftContracts, ALL_NFTS_CONTRACTS_STATE_KEY, {\n chainId,\n userAddress,\n });\n\n return newNftContracts;\n }\n\n async #validateWatchNft(\n asset: NftAsset,\n type: NFTStandardType,\n userAddress: string,\n networkClientId: NetworkClientId,\n ) {\n const { address: contractAddress, tokenId } = asset;\n\n // Validate parameters\n if (!type) {\n throw rpcErrors.invalidParams('Asset type is required');\n }\n\n if (type !== ERC721 && type !== ERC1155) {\n throw rpcErrors.invalidParams(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `Non NFT asset type ${type} not supported by watchNft`,\n );\n }\n\n if (!contractAddress || !tokenId) {\n throw rpcErrors.invalidParams('Both address and tokenId are required');\n }\n\n if (!isAddress(contractAddress)) {\n throw rpcErrors.invalidParams('Invalid address');\n }\n\n if (!/^\\d+$/u.test(tokenId)) {\n throw rpcErrors.invalidParams('Invalid tokenId');\n }\n\n // Check if the user owns the suggested NFT\n try {\n const isOwner = await this.isNftOwner(\n userAddress,\n contractAddress,\n tokenId,\n networkClientId,\n );\n if (!isOwner) {\n throw rpcErrors.invalidInput(\n 'Suggested NFT is not owned by the selected account',\n );\n }\n } catch (error) {\n // error thrown here: \"Unable to verify ownership. Possibly because the standard is not supported or the user's currently selected network does not match the chain of the asset in question.\"\n if (error instanceof Error) {\n throw rpcErrors.resourceUnavailable(error.message);\n }\n throw error;\n }\n }\n\n /**\n * Adds a new suggestedAsset to state. Parameters will be validated according to\n * asset type being watched. A `<suggestedNftMeta.id>:pending` hub event will be emitted once added.\n *\n * @param asset - The asset to be watched. For now ERC721 and ERC1155 tokens are accepted.\n * @param asset.address - The address of the asset contract.\n * @param asset.tokenId - The ID of the asset.\n * @param type - The asset type.\n * @param origin - Domain origin to register the asset from.\n * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @param options - Options bag.\n * @param options.userAddress - The address of the account where the NFT is being added.\n * @returns Object containing a Promise resolving to the suggestedAsset address if accepted.\n */\n async watchNft(\n asset: NftAsset,\n type: NFTStandardType,\n origin: string,\n networkClientId: NetworkClientId,\n {\n userAddress,\n }: {\n userAddress?: string;\n } = {},\n ) {\n const addressToSearch = this.#getAddressOrSelectedAddress(userAddress);\n if (!addressToSearch) {\n return;\n }\n if (!networkClientId) {\n throw rpcErrors.invalidParams('Network client id is required');\n }\n\n await this.#validateWatchNft(asset, type, addressToSearch, networkClientId);\n\n const nftMetadata = await this.#getNftInformation(\n asset.address,\n asset.tokenId,\n networkClientId,\n );\n\n if (nftMetadata.standard && nftMetadata.standard !== type) {\n throw rpcErrors.invalidInput(\n `Suggested NFT of type ${nftMetadata.standard} does not match received type ${type}`,\n );\n }\n\n const suggestedNftMeta: SuggestedNftMeta = {\n asset: { ...asset, ...nftMetadata },\n type,\n id: random(),\n time: Date.now(),\n interactingAddress: addressToSearch,\n origin,\n };\n await this._requestApproval(suggestedNftMeta);\n const { address, tokenId } = asset;\n const { name, standard, description, image } = nftMetadata;\n await this.addNft(address, tokenId, networkClientId, {\n nftMetadata: {\n name: name ?? null,\n description: description ?? null,\n image: image ?? null,\n standard: standard ?? null,\n },\n userAddress,\n source: Source.Dapp,\n });\n }\n\n /**\n * Sets an OpenSea API key to retrieve NFT information.\n *\n * @param openSeaApiKey - OpenSea API key.\n */\n setApiKey(openSeaApiKey: string) {\n this.openSeaApiKey = openSeaApiKey;\n }\n\n /**\n * Checks the ownership of a ERC-721 or ERC-1155 NFT for a given address.\n *\n * @param ownerAddress - User public address.\n * @param nftAddress - NFT contract address.\n * @param tokenId - NFT token ID.\n * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @returns Promise resolving the NFT ownership.\n */\n async isNftOwner(\n ownerAddress: string,\n nftAddress: string,\n tokenId: string,\n networkClientId: NetworkClientId,\n ): Promise<boolean> {\n // Checks the ownership for ERC-721.\n try {\n const owner = await this.messagingSystem.call(\n 'AssetsContractController:getERC721OwnerOf',\n nftAddress,\n tokenId,\n networkClientId,\n );\n return ownerAddress.toLowerCase() === owner.toLowerCase();\n // eslint-disable-next-line no-empty\n } catch {\n // Ignore ERC-721 contract error\n }\n\n // Checks the ownership for ERC-1155.\n try {\n const balance = await this.messagingSystem.call(\n 'AssetsContractController:getERC1155BalanceOf',\n ownerAddress,\n nftAddress,\n tokenId,\n networkClientId,\n );\n return !balance.isZero();\n // eslint-disable-next-line no-empty\n } catch {\n // Ignore ERC-1155 contract error\n }\n\n throw new Error(\n `Unable to verify ownership. Possibly because the standard is not supported or the user's currently selected network does not match the chain of the asset in question.`,\n );\n }\n\n /**\n * Verifies currently selected address owns entered NFT address/tokenId combo and\n * adds the NFT and respective NFT contract to the stored NFT and NFT contracts lists.\n *\n * @param address - Hex address of the NFT contract.\n * @param tokenId - The NFT identifier.\n * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @param options - an object of arguments\n * @param options.userAddress - The address of the current user.\n * @param options.source - Whether the NFT was detected, added manually or suggested by a dapp.\n */\n async addNftVerifyOwnership(\n address: string,\n tokenId: string,\n networkClientId: NetworkClientId,\n {\n userAddress,\n source,\n }: {\n userAddress?: string;\n source?: Source;\n } = {},\n ) {\n const addressToSearch = this.#getAddressOrSelectedAddress(userAddress);\n\n if (\n !(await this.isNftOwner(\n addressToSearch,\n address,\n tokenId,\n networkClientId,\n ))\n ) {\n throw new Error('This NFT is not owned by the user');\n }\n\n await this.addNft(address, tokenId, networkClientId, {\n userAddress: addressToSearch,\n source,\n });\n }\n\n /**\n * Adds an NFT and respective NFT contract to the stored NFT and NFT contracts lists.\n *\n * @param tokenAddress - Hex address of the NFT contract.\n * @param tokenId - The NFT identifier.\n * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @param options - an object of arguments\n * @param options.nftMetadata - NFT optional metadata.\n * @param options.userAddress - The address of the current user.\n * @param options.source - Whether the NFT was detected, added manually or suggested by a dapp.\n * @returns Promise resolving to the current NFT list.\n */\n async addNft(\n tokenAddress: string,\n tokenId: string,\n networkClientId: NetworkClientId,\n {\n nftMetadata,\n userAddress,\n source = Source.Custom,\n }: {\n nftMetadata?: NftMetadata;\n userAddress?: string;\n source?: Source;\n } = {},\n ) {\n const addressToSearch = this.#getAddressOrSelectedAddress(userAddress);\n if (!addressToSearch) {\n return;\n }\n\n const checksumHexAddress = toChecksumHexAddress(tokenAddress);\n\n nftMetadata =\n nftMetadata ||\n (await this.#getNftInformation(\n checksumHexAddress,\n tokenId,\n networkClientId,\n ));\n\n const newNftContracts = await this.#addNftContract(networkClientId, {\n tokenAddress: checksumHexAddress,\n userAddress: addressToSearch,\n source,\n nftMetadata,\n });\n\n // If NFT contract was not added, do not add individual NFT\n const nftContract = newNftContracts.find(\n (contract) =>\n contract.address.toLowerCase() === checksumHexAddress.toLowerCase(),\n );\n const {\n configuration: { chainId },\n } = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n // This is the case when the NFT is added manually and not detected automatically\n // TODO: An improvement would be to make the chainId a required field and return it when getting the NFT information\n if (!nftMetadata.chainId) {\n nftMetadata.chainId = convertHexToDecimal(chainId);\n }\n\n // If NFT contract information, add individual NFT\n if (nftContract) {\n await this.#addIndividualNft(\n checksumHexAddress,\n tokenId,\n nftMetadata,\n nftContract,\n chainId,\n addressToSearch,\n source,\n );\n }\n }\n\n /**\n * Refetches NFT metadata and updates the state\n *\n * @param options - Options for refetching NFT metadata\n * @param options.nfts - nfts to update metadata for.\n * @param options.userAddress - The current user address\n */\n async updateNftMetadata({\n nfts,\n userAddress,\n }: {\n nfts: Nft[];\n userAddress?: string;\n }) {\n const addressToSearch = this.#getAddressOrSelectedAddress(userAddress);\n\n const releaseLock = await this.#mutex.acquire();\n\n try {\n const nftsWithChecksumAdr = nfts.map((nft) => {\n return {\n ...nft,\n address: toChecksumHexAddress(nft.address),\n };\n });\n const nftMetadataResults = await Promise.all(\n nftsWithChecksumAdr.map(async (nft) => {\n // Each NFT should have a chainId; convert nft.chainId to networkClientId\n const networkClientId = this.messagingSystem.call(\n 'NetworkController:getNetworkClientIdByChainId',\n toHex(nft.chainId as number),\n );\n const resMetadata = networkClientId\n ? await this.#getNftInformation(\n nft.address,\n nft.tokenId,\n networkClientId,\n )\n : undefined;\n return {\n nft,\n newMetadata: resMetadata,\n };\n }),\n );\n\n // We want to avoid updating the state if the state and fetched nft info are the same\n const nftsWithDifferentMetadata: NftUpdate[] = [];\n const { allNfts } = this.state;\n // get from state allNfts that match nftsWithChecksumAdr\n const stateNfts = nftsWithChecksumAdr.map((nft) => {\n return allNfts[addressToSearch]?.[toHex(nft.chainId as number)]?.find(\n (nftElement) =>\n nftElement.address.toLowerCase() === nft.address.toLowerCase() &&\n nftElement.tokenId === nft.tokenId,\n );\n });\n\n nftMetadataResults.forEach(\n (singleNft: { nft: Nft; newMetadata: NftMetadata | undefined }) => {\n const existingEntry: Nft | undefined = stateNfts.find(\n (nft) =>\n nft?.address.toLowerCase() ===\n singleNft.nft.address.toLowerCase() &&\n nft?.tokenId === singleNft.nft.tokenId,\n );\n\n if (existingEntry && singleNft.newMetadata) {\n const differentMetadata = compareNftMetadata(\n singleNft.newMetadata,\n existingEntry,\n );\n\n if (differentMetadata) {\n nftsWithDifferentMetadata.push({\n nft: singleNft.nft,\n newMetadata: singleNft.newMetadata,\n });\n }\n }\n },\n );\n\n if (nftsWithDifferentMetadata.length !== 0) {\n nftsWithDifferentMetadata.forEach((elm) =>\n this.updateNft(\n elm.nft,\n elm.newMetadata,\n addressToSearch,\n toHex(elm.nft.chainId as number),\n ),\n );\n }\n } finally {\n releaseLock();\n }\n }\n\n /**\n * Removes an NFT from the stored token list.\n *\n * @param address - Hex address of the NFT contract.\n * @param tokenId - Token identifier of the NFT.\n * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @param options - an object of arguments\n * @param options.userAddress - The address of the account where the NFT is being removed.\n */\n removeNft(\n address: string,\n tokenId: string,\n networkClientId: NetworkClientId,\n { userAddress }: { userAddress?: string } = {},\n ) {\n const addressToSearch = this.#getAddressOrSelectedAddress(userAddress);\n\n const {\n configuration: { chainId },\n } = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n networkClientId as NetworkClientId,\n );\n\n const checksumHexAddress = toChecksumHexAddress(address);\n this.#removeIndividualNft(checksumHexAddress, tokenId, {\n chainId,\n userAddress: addressToSearch,\n });\n const { allNfts } = this.state;\n const nfts = allNfts[addressToSearch]?.[chainId] || [];\n const remainingNft = nfts.find(\n (nft) => nft.address.toLowerCase() === checksumHexAddress.toLowerCase(),\n );\n\n if (!remainingNft) {\n this.#removeNftContract(checksumHexAddress, {\n chainId,\n userAddress: addressToSearch,\n });\n }\n }\n\n /**\n * Removes an NFT from the stored token list and saves it in ignored NFTs list.\n *\n * @param address - Hex address of the NFT contract.\n * @param tokenId - Token identifier of the NFT.\n * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @param options - an object of arguments\n * @param options.userAddress - The address of the account where the NFT is being removed.\n */\n removeAndIgnoreNft(\n address: string,\n tokenId: string,\n networkClientId: NetworkClientId,\n { userAddress }: { userAddress?: string } = {},\n ) {\n const addressToSearch = this.#getAddressOrSelectedAddress(userAddress);\n const {\n configuration: { chainId },\n } = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n networkClientId as NetworkClientId,\n );\n const checksumHexAddress = toChecksumHexAddress(address);\n this.#removeAndIgnoreIndividualNft(checksumHexAddress, tokenId, {\n chainId,\n userAddress: addressToSearch,\n });\n const { allNfts } = this.state;\n const nfts = allNfts[addressToSearch]?.[chainId] || [];\n const remainingNft = nfts.find(\n (nft) => nft.address.toLowerCase() === checksumHexAddress.toLowerCase(),\n );\n if (!remainingNft) {\n this.#removeNftContract(checksumHexAddress, {\n chainId,\n userAddress: addressToSearch,\n });\n }\n }\n\n /**\n * Removes all NFTs from the ignored list.\n */\n clearIgnoredNfts() {\n this.update((state) => {\n state.ignoredNfts = [];\n });\n }\n\n /**\n * Checks whether input NFT is still owned by the user\n * And updates the isCurrentlyOwned value on the NFT object accordingly.\n *\n * @param nft - The NFT object to check and update.\n * @param batch - A boolean indicating whether this method is being called as part of a batch or single update.\n * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @param accountParams - The userAddress and chainId to check ownership against\n * @param accountParams.userAddress - the address passed through the confirmed transaction flow to ensure assets are stored to the correct account\n * @returns the NFT with the updated isCurrentlyOwned value\n */\n async checkAndUpdateSingleNftOwnershipStatus(\n nft: Nft,\n batch: boolean,\n networkClientId: NetworkClientId,\n { userAddress }: { userAddress?: string } = {},\n ) {\n const addressToSearch = this.#getAddressOrSelectedAddress(userAddress);\n const {\n configuration: { chainId },\n } = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n networkClientId as NetworkClientId,\n );\n const { address, tokenId } = nft;\n let isOwned = nft.isCurrentlyOwned;\n try {\n isOwned = await this.isNftOwner(\n addressToSearch,\n address,\n tokenId,\n networkClientId,\n );\n } catch {\n // ignore error\n // this will only throw an error 'Unable to verify ownership' in which case\n // we want to keep the current value of isCurrentlyOwned for this flow.\n }\n\n const updatedNft = {\n ...nft,\n isCurrentlyOwned: isOwned,\n };\n\n if (batch) {\n return updatedNft;\n }\n\n // if this is not part of a batched update we update this one NFT in state\n const { allNfts } = this.state;\n const nfts = [...(allNfts[addressToSearch]?.[chainId] || [])];\n const indexToUpdate = nfts.findIndex(\n (item) =>\n item.tokenId === tokenId &&\n item.address.toLowerCase() === address.toLowerCase(),\n );\n\n if (indexToUpdate !== -1) {\n nfts[indexToUpdate] = updatedNft;\n this.update((state) => {\n state.allNfts[addressToSearch] = Object.assign(\n {},\n state.allNfts[addressToSearch],\n {\n [chainId]: nfts,\n },\n );\n });\n this.#updateNestedNftState(nfts, ALL_NFTS_STATE_KEY, {\n userAddress: addressToSearch,\n chainId,\n });\n }\n\n return updatedNft;\n }\n\n /**\n * Checks whether NFTs associated with current selectedAddress/chainId combination are still owned by the user\n * And updates the isCurrentlyOwned value on each accordingly.\n *\n * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @param options - an object of arguments\n * @param options.userAddress - The address of the account where the NFT ownership status is checked/updated.\n */\n async checkAndUpdateAllNftsOwnershipStatus(\n networkClientId: NetworkClientId,\n {\n userAddress,\n }: {\n userAddress?: string;\n } = {},\n ) {\n const addressToSearch = this.#getAddressOrSelectedAddress(userAddress);\n const {\n configuration: { chainId },\n } = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n networkClientId as NetworkClientId,\n );\n const { allNfts } = this.state;\n const nfts = allNfts[addressToSearch]?.[chainId] || [];\n const updatedNfts = await Promise.all(\n nfts.map(async (nft) => {\n return (\n (await this.checkAndUpdateSingleNftOwnershipStatus(\n nft,\n true,\n networkClientId,\n {\n userAddress,\n },\n )) ?? nft\n );\n }),\n );\n\n this.#updateNestedNftState(updatedNfts, ALL_NFTS_STATE_KEY, {\n userAddress: addressToSearch,\n chainId,\n });\n }\n\n /**\n * Update NFT favorite status.\n *\n * @param address - Hex address of the NFT contract.\n * @param tokenId - Hex address of the NFT contract.\n * @param favorite - NFT new favorite status.\n * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @param options - an object of arguments\n * @param options.userAddress - The address of the account where the NFT is being removed.\n */\n updateNftFavoriteStatus(\n address: string,\n tokenId: string,\n favorite: boolean,\n networkClientId: NetworkClientId,\n {\n userAddress,\n }: {\n userAddress?: string;\n } = {},\n ) {\n const addressToSearch = this.#getAddressOrSelectedAddress(userAddress);\n const {\n configuration: { chainId },\n } = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n networkClientId as NetworkClientId,\n );\n const { allNfts } = this.state;\n const nfts = [...(allNfts[addressToSearch]?.[chainId] || [])];\n const index: number = nfts.findIndex(\n (nft) => nft.address === address && nft.tokenId === tokenId,\n );\n\n if (index === -1) {\n return;\n }\n\n const updatedNft: Nft = {\n ...nfts[index],\n favorite,\n };\n\n // Update Nfts array\n nfts[index] = updatedNft;\n\n this.#updateNestedNftState(nfts, ALL_NFTS_STATE_KEY, {\n chainId,\n userAddress: addressToSearch,\n });\n }\n\n /**\n * Returns an NFT by the address and token id.\n *\n * @param address - Hex address of the NFT contract.\n * @param tokenId - Number that represents the id of the token.\n * @param selectedAddress - Hex address of the user account.\n * @param chainId - Id of the current network.\n * @returns Object containing the NFT and its position in the array\n */\n findNftByAddressAndTokenId(\n address: string,\n tokenId: string,\n selectedAddress: string,\n chainId: Hex,\n ): { nft: Nft; index: number } | null {\n const { allNfts } = this.state;\n const nfts = allNfts[selectedAddress]?.[chainId] || [];\n const index: number = nfts.findIndex(\n (nft) =>\n nft.address.toLowerCase() === address.toLowerCase() &&\n nft.tokenId === tokenId,\n );\n\n if (index === -1) {\n return null;\n }\n\n return { nft: nfts[index], index };\n }\n\n /**\n * Update NFT data.\n *\n * @param nft - NFT object to find the right NFT to updates.\n * @param updates - NFT partial object to update properties of the NFT.\n * @param selectedAddress - Hex address of the user account.\n * @param chainId - Id of the current network.\n */\n updateNft(\n nft: Nft,\n updates: Partial<Nft>,\n selectedAddress: string,\n chainId: Hex,\n ) {\n const { allNfts } = this.state;\n const nfts = allNfts[selectedAddress]?.[chainId] || [];\n const nftInfo = this.findNftByAddressAndTokenId(\n nft.address,\n nft.tokenId,\n selectedAddress,\n chainId,\n );\n\n if (!nftInfo) {\n return;\n }\n\n const updatedNft: Nft = {\n ...nft,\n ...updates,\n };\n\n const newNfts = [\n ...nfts.slice(0, nftInfo.index),\n updatedNft,\n ...nfts.slice(nftInfo.index + 1),\n ];\n this.#updateNestedNftState(newNfts, ALL_NFTS_STATE_KEY, {\n chainId,\n userAddress: selectedAddress,\n });\n }\n\n /**\n * Resets the transaction status of an NFT.\n *\n * @param transactionId - NFT transaction id.\n * @param selectedAddress - Hex address of the user account.\n * @param chainId - Id of the current network.\n * @returns a boolean indicating if the reset was well succeeded or not\n */\n resetNftTransactionStatusByTransactionId(\n transactionId: string,\n selectedAddress: string,\n chainId: Hex,\n ): boolean {\n const { allNfts } = this.state;\n const nfts = allNfts[selectedAddress]?.[chainId] || [];\n const index: number = nfts.findIndex(\n (nft) => nft.transactionId === transactionId,\n );\n\n if (index === -1) {\n return false;\n }\n const updatedNft: Nft = {\n ...nfts[index],\n transactionId: undefined,\n };\n\n const newNfts = [\n ...nfts.slice(0, index),\n updatedNft,\n ...nfts.slice(index + 1),\n ];\n\n this.#updateNestedNftState(newNfts, ALL_NFTS_STATE_KEY, {\n chainId,\n userAddress: selectedAddress,\n });\n\n return true;\n }\n\n /**\n * Fetches NFT Collection Metadata from the NFT API.\n *\n * @param contractAddresses - The contract addresses of the NFTs.\n * @param chainId - The chain ID of the network where the NFT is located.\n * @returns NFT collections metadata.\n */\n async getNFTContractInfo(\n contractAddresses: string[],\n chainId: Hex,\n ): Promise<{\n collections: Collection[];\n }> {\n const url = new URL(this.#getNftCollectionApi());\n\n url.searchParams.append('chainId', chainId);\n\n for (const address of contractAddresses) {\n url.searchParams.append('contract', address);\n }\n\n return await handleFetch(url, {\n headers: {\n Version: NFT_API_VERSION,\n },\n });\n }\n\n async _requestApproval(suggestedNftMeta: SuggestedNftMeta) {\n return this.messagingSystem.call(\n 'ApprovalController:addRequest',\n {\n id: suggestedNftMeta.id,\n origin: suggestedNftMeta.origin,\n type: ApprovalType.WatchAsset,\n requestData: {\n id: suggestedNftMeta.id,\n interactingAddress: suggestedNftMeta.interactingAddress,\n asset: {\n address: suggestedNftMeta.asset.address,\n tokenId: suggestedNftMeta.asset.tokenId,\n name: suggestedNftMeta.asset.name,\n description: suggestedNftMeta.asset.description,\n image: suggestedNftMeta.asset.image,\n standard: suggestedNftMeta.asset.standard,\n },\n },\n },\n true,\n );\n }\n\n #getAddressOrSelectedAddress(address: string | undefined): string {\n if (address) {\n return address;\n }\n\n // If the address is not defined (or empty), we fallback to the currently selected account's address\n const selectedAccount = this.messagingSystem.call(\n 'AccountsController:getAccount',\n this.#selectedAccountId,\n );\n return selectedAccount?.address || '';\n }\n\n /**\n * Updates the all nfts in state for the account.\n * Nfts will be updated if they don't have a name, description or image.\n *\n * @param account - The account to update the NFT metadata for.\n */\n async #updateNftUpdateForAccount(account: InternalAccount) {\n // get all nfts for the account for all chains\n const nfts: Nft[] = Object.values(\n this.state.allNfts[account.address] || {},\n ).flat();\n\n // Filter only nfts\n const nftsToUpdate = nfts.filter(\n (singleNft) =>\n !singleNft.name && !singleNft.description && !singleNft.image,\n );\n if (\n nftsToUpdate.length !== 0 &&\n nftsToUpdate.length < NFT_UPDATE_THRESHOLD\n ) {\n // TODO: get the chainId for the NFT\n await this.updateNftMetadata({\n nfts: nftsToUpdate,\n userAddress: account.address,\n });\n }\n }\n\n /**\n * Reset the controller state to the default state.\n */\n resetState() {\n this.update(() => {\n return getDefaultNftControllerState();\n });\n }\n}\n\nexport default NftController;\n"]}
1
+ {"version":3,"file":"NftController.mjs","sourceRoot":"","sources":["../src/NftController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,+BAA+B;AAWnD,OAAO,EACL,cAAc,EAEf,kCAAkC;AACnC,OAAO,EACL,aAAa,EACb,WAAW,EACX,oBAAoB,EACpB,OAAO,EACP,sBAAsB,EACtB,wBAAwB,EACxB,MAAM,EACN,OAAO,EACP,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACpB,mCAAmC;AAYpC,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAEjD,OAAO,EAAE,QAAQ,EAAE,wBAAwB;AAC3C,OAAO,EAAE,KAAK,EAAE,oBAAoB;AACpC,OAAO,GAAE,cAAc;;AACvB,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,aAAa;AAUpC,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACvB,yBAAqB;AACtB,OAAO,EAAE,MAAM,EAAE,wBAAoB;AAoJrC,MAAM,qBAAqB,GAAG;IAC5B,eAAe,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE;IACpD,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE;IAC5C,WAAW,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE;CACjD,CAAC;AAEF,MAAM,kBAAkB,GAAG,SAAS,CAAC;AACrC,MAAM,4BAA4B,GAAG,iBAAiB,CAAC;AAOvD;;GAEG;AACH,MAAM,cAAc,GAAG,eAAe,CAAC;AA8CvC,MAAM,CAAC,MAAM,4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mB;IACnB,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAC9B,CAAC,SAAS,EAAE,EAAE,CACZ,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,WAAW,IAAI,CAAC,SAAS,CAAC,KAAK,CAChE,CAAC;IACF,IACE,YAAY,CAAC,MAAM,KAAK,CAAC;QACzB,YAAY,CAAC,MAAM,GAAG,oBAAoB,EAC1C;QACA,MAAM,IAAI,CAAC,iBAAiB,CAAC;YAC3B,IAAI,EAAE,YAAY;YAClB,WAAW,EAAE,OAAO,CAAC,OAAO;SAC7B,CAAC,CAAC;KACJ;AACH,CAAC;AAYH,eAAe,aAAa,CAAC","sourcesContent":["import { isAddress } from '@ethersproject/address';\nimport type {\n AccountsControllerSelectedEvmAccountChangeEvent,\n AccountsControllerGetAccountAction,\n AccountsControllerGetSelectedAccountAction,\n} from '@metamask/accounts-controller';\nimport type { AddApprovalRequest } from '@metamask/approval-controller';\nimport type {\n RestrictedMessenger,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport {\n BaseController,\n type ControllerGetStateAction,\n} from '@metamask/base-controller';\nimport {\n safelyExecute,\n handleFetch,\n toChecksumHexAddress,\n BNToHex,\n fetchWithErrorHandling,\n IPFS_DEFAULT_GATEWAY_URL,\n ERC721,\n ERC1155,\n ApprovalType,\n NFT_API_BASE_URL,\n NFT_API_VERSION,\n convertHexToDecimal,\n} from '@metamask/controller-utils';\nimport { type InternalAccount } from '@metamask/keyring-internal-api';\nimport type {\n NetworkClientId,\n NetworkControllerGetNetworkClientByIdAction,\n NetworkControllerNetworkDidChangeEvent,\n NetworkState,\n} from '@metamask/network-controller';\nimport type {\n PreferencesControllerStateChangeEvent,\n PreferencesState,\n} from '@metamask/preferences-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { Hex } from '@metamask/utils';\nimport { remove0x } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\nimport BN from 'bn.js';\nimport { v4 as random } from 'uuid';\n\nimport type {\n AssetsContractControllerGetERC1155BalanceOfAction,\n AssetsContractControllerGetERC1155TokenURIAction,\n AssetsContractControllerGetERC721AssetNameAction,\n AssetsContractControllerGetERC721AssetSymbolAction,\n AssetsContractControllerGetERC721OwnerOfAction,\n AssetsContractControllerGetERC721TokenURIAction,\n} from './AssetsContractController';\nimport {\n compareNftMetadata,\n getFormattedIpfsUrl,\n hasNewCollectionFields,\n} from './assetsUtil';\nimport { Source } from './constants';\nimport type {\n ApiNftContract,\n ReservoirResponse,\n Collection,\n Attributes,\n LastSale,\n GetCollectionsResponse,\n TopBid,\n} from './NftDetectionController';\n\ntype NFTStandardType = 'ERC721' | 'ERC1155';\n\ntype SuggestedNftMeta = {\n asset: { address: string; tokenId: string } & NftMetadata;\n id: string;\n time: number;\n type: NFTStandardType;\n interactingAddress: string;\n origin: string;\n};\n\n/**\n * @type Nft\n *\n * NFT representation\n * @property address - Hex address of a ERC721 contract\n * @property description - The NFT description\n * @property image - URI of custom NFT image associated with this tokenId\n * @property name - Name associated with this tokenId and contract address\n * @property tokenId - The NFT identifier\n * @property numberOfSales - Number of sales\n * @property backgroundColor - The background color to be displayed with the item\n * @property imagePreview - URI of a smaller image associated with this NFT\n * @property imageThumbnail - URI of a thumbnail image associated with this NFT\n * @property imageOriginal - URI of the original image associated with this NFT\n * @property animation - URI of a animation associated with this NFT\n * @property animationOriginal - URI of the original animation associated with this NFT\n * @property externalLink - External link containing additional information\n * @property creator - The NFT owner information object\n * @property isCurrentlyOwned - Boolean indicating whether the address/chainId combination where it's currently stored currently owns this NFT\n * @property transactionId - Transaction Id associated with the NFT\n */\nexport type Nft = {\n tokenId: string;\n address: string;\n isCurrentlyOwned?: boolean;\n} & NftMetadata;\n\ntype NftUpdate = {\n nft: Nft;\n newMetadata: NftMetadata;\n};\n\n/**\n * @type NftContract\n *\n * NFT contract information representation\n * @property name - Contract name\n * @property logo - Contract logo\n * @property address - Contract address\n * @property symbol - Contract symbol\n * @property description - Contract description\n * @property totalSupply - Total supply of NFTs\n * @property assetContractType - The NFT type, it could be `semi-fungible` or `non-fungible`\n * @property createdDate - Creation date\n * @property schemaName - The schema followed by the contract, it could be `ERC721` or `ERC1155`\n * @property externalLink - External link containing additional information\n */\nexport type NftContract = {\n name?: string;\n logo?: string;\n address: string;\n symbol?: string;\n description?: string;\n totalSupply?: string;\n assetContractType?: string;\n createdDate?: string;\n schemaName?: string;\n externalLink?: string;\n};\n\n/**\n * @type NftMetadata\n *\n * NFT custom information\n * @property name - NFT custom name\n * @property description - The NFT description\n * @property numberOfSales - Number of sales\n * @property backgroundColor - The background color to be displayed with the item\n * @property image - Image custom image URI\n * @property imagePreview - URI of a smaller image associated with this NFT\n * @property imageThumbnail - URI of a thumbnail image associated with this NFT\n * @property imageOriginal - URI of the original image associated with this NFT\n * @property animation - URI of a animation associated with this NFT\n * @property animationOriginal - URI of the original animation associated with this NFT\n * @property externalLink - External link containing additional information\n * @property creator - The NFT owner information object\n * @property standard - NFT standard name for the NFT, e.g., ERC-721 or ERC-1155\n */\nexport type NftMetadata = {\n name: string | null;\n description: string | null;\n image: string | null;\n standard: string | null;\n favorite?: boolean;\n numberOfSales?: number;\n backgroundColor?: string;\n imagePreview?: string;\n imageThumbnail?: string;\n imageOriginal?: string;\n animation?: string;\n animationOriginal?: string;\n externalLink?: string;\n creator?: string;\n transactionId?: string;\n tokenURI?: string | null;\n collection?: Collection;\n address?: string;\n attributes?: Attributes[];\n lastSale?: LastSale;\n rarityRank?: string;\n topBid?: TopBid;\n chainId?: number;\n};\n\n/**\n * @type NftControllerState\n *\n * NFT controller state\n * @property allNftContracts - Object containing NFT contract information\n * @property allNfts - Object containing NFTs per account and network\n * @property ignoredNfts - List of NFTs that should be ignored\n */\nexport type NftControllerState = {\n allNftContracts: {\n [key: string]: {\n [chainId: Hex]: NftContract[];\n };\n };\n allNfts: {\n [key: string]: {\n [chainId: Hex]: Nft[];\n };\n };\n ignoredNfts: Nft[];\n};\n\nconst nftControllerMetadata = {\n allNftContracts: { persist: true, anonymous: false },\n allNfts: { persist: true, anonymous: false },\n ignoredNfts: { persist: true, anonymous: false },\n};\n\nconst ALL_NFTS_STATE_KEY = 'allNfts';\nconst ALL_NFTS_CONTRACTS_STATE_KEY = 'allNftContracts';\n\ntype NftAsset = {\n address: string;\n tokenId: string;\n};\n\n/**\n * The name of the {@link NftController}.\n */\nconst controllerName = 'NftController';\n\nexport type NftControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n NftControllerState\n>;\nexport type NftControllerActions = NftControllerGetStateAction;\n\n/**\n * The external actions available to the {@link NftController}.\n */\nexport type AllowedActions =\n | AddApprovalRequest\n | AccountsControllerGetAccountAction\n | AccountsControllerGetSelectedAccountAction\n | NetworkControllerGetNetworkClientByIdAction\n | AssetsContractControllerGetERC721AssetNameAction\n | AssetsContractControllerGetERC721AssetSymbolAction\n | AssetsContractControllerGetERC721TokenURIAction\n | AssetsContractControllerGetERC721OwnerOfAction\n | AssetsContractControllerGetERC1155BalanceOfAction\n | AssetsContractControllerGetERC1155TokenURIAction;\n\nexport type AllowedEvents =\n | PreferencesControllerStateChangeEvent\n | NetworkControllerNetworkDidChangeEvent\n | AccountsControllerSelectedEvmAccountChangeEvent;\n\nexport type NftControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n NftControllerState\n>;\n\nexport type NftControllerEvents = NftControllerStateChangeEvent;\n\n/**\n * The messenger of the {@link NftController}.\n */\nexport type NftControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n NftControllerActions | AllowedActions,\n NftControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\nexport const getDefaultNftControllerState = (): NftControllerState => ({\n allNftContracts: {},\n allNfts: {},\n ignoredNfts: [],\n});\n\nconst NFT_UPDATE_THRESHOLD = 500;\n\n/**\n * Controller that stores assets and exposes convenience methods\n */\nexport class NftController extends BaseController<\n typeof controllerName,\n NftControllerState,\n NftControllerMessenger\n> {\n readonly #mutex = new Mutex();\n\n /**\n * Optional API key to use with opensea\n */\n openSeaApiKey?: string;\n\n #selectedAccountId: string;\n\n #chainId: Hex;\n\n #ipfsGateway: string;\n\n #openSeaEnabled: boolean;\n\n #useIpfsSubdomains: boolean;\n\n #isIpfsGatewayEnabled: boolean;\n\n readonly #onNftAdded?: (data: {\n address: string;\n symbol: string | undefined;\n tokenId: string;\n standard: string | null;\n source: Source;\n }) => void;\n\n /**\n * Creates an NftController instance.\n *\n * @param options - The controller options.\n * @param options.chainId - The chain ID of the current network.\n * @param options.ipfsGateway - The configured IPFS gateway.\n * @param options.openSeaEnabled - Controls whether the OpenSea API is used.\n * @param options.useIpfsSubdomains - Controls whether IPFS subdomains are used.\n * @param options.isIpfsGatewayEnabled - Controls whether IPFS is enabled or not.\n * @param options.onNftAdded - Callback that is called when an NFT is added. Currently used pass data\n * for tracking the NFT added event.\n * @param options.messenger - The messenger.\n * @param options.state - Initial state to set on this controller.\n */\n constructor({\n chainId: initialChainId,\n ipfsGateway = IPFS_DEFAULT_GATEWAY_URL,\n openSeaEnabled = false,\n useIpfsSubdomains = true,\n isIpfsGatewayEnabled = true,\n onNftAdded,\n messenger,\n state = {},\n }: {\n chainId: Hex;\n ipfsGateway?: string;\n openSeaEnabled?: boolean;\n useIpfsSubdomains?: boolean;\n isIpfsGatewayEnabled?: boolean;\n onNftAdded?: (data: {\n address: string;\n symbol: string | undefined;\n tokenId: string;\n standard: string | null;\n source: string;\n }) => void;\n messenger: NftControllerMessenger;\n state?: Partial<NftControllerState>;\n }) {\n super({\n name: controllerName,\n metadata: nftControllerMetadata,\n messenger,\n state: {\n ...getDefaultNftControllerState(),\n ...state,\n },\n });\n\n this.#selectedAccountId = this.messagingSystem.call(\n 'AccountsController:getSelectedAccount',\n ).id;\n this.#chainId = initialChainId;\n this.#ipfsGateway = ipfsGateway;\n this.#openSeaEnabled = openSeaEnabled;\n this.#useIpfsSubdomains = useIpfsSubdomains;\n this.#isIpfsGatewayEnabled = isIpfsGatewayEnabled;\n this.#onNftAdded = onNftAdded;\n\n this.messagingSystem.subscribe(\n 'PreferencesController:stateChange',\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.#onPreferencesControllerStateChange.bind(this),\n );\n\n this.messagingSystem.subscribe(\n 'NetworkController:networkDidChange',\n this.#onNetworkControllerNetworkDidChange.bind(this),\n );\n\n this.messagingSystem.subscribe(\n 'AccountsController:selectedEvmAccountChange',\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.#onSelectedAccountChange.bind(this),\n );\n }\n\n /**\n * Handles the network change on the network controller.\n * @param networkState - The new state of the preference controller.\n * @param networkState.selectedNetworkClientId - The current selected network client id.\n */\n #onNetworkControllerNetworkDidChange({\n selectedNetworkClientId,\n }: NetworkState) {\n const {\n configuration: { chainId },\n } = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n );\n this.#chainId = chainId;\n }\n\n /**\n * Handles the state change of the preference controller.\n * @param preferencesState - The new state of the preference controller.\n * @param preferencesState.ipfsGateway - The configured IPFS gateway.\n * @param preferencesState.openSeaEnabled - Controls whether the OpenSea API is used.\n * @param preferencesState.isIpfsGatewayEnabled - Controls whether IPFS is enabled or not.\n */\n async #onPreferencesControllerStateChange({\n ipfsGateway,\n openSeaEnabled,\n isIpfsGatewayEnabled,\n }: PreferencesState) {\n const selectedAccount = this.messagingSystem.call(\n 'AccountsController:getSelectedAccount',\n );\n this.#selectedAccountId = selectedAccount.id;\n // Get current state values\n if (\n this.#ipfsGateway !== ipfsGateway ||\n this.#openSeaEnabled !== openSeaEnabled ||\n this.#isIpfsGatewayEnabled !== isIpfsGatewayEnabled\n ) {\n this.#ipfsGateway = ipfsGateway;\n this.#openSeaEnabled = openSeaEnabled;\n this.#isIpfsGatewayEnabled = isIpfsGatewayEnabled;\n const needsUpdateNftMetadata =\n (isIpfsGatewayEnabled && ipfsGateway !== '') || openSeaEnabled;\n\n if (needsUpdateNftMetadata && selectedAccount) {\n await this.#updateNftUpdateForAccount(selectedAccount);\n }\n }\n }\n\n /**\n * Handles the selected account change on the accounts controller.\n * @param internalAccount - The new selected account.\n */\n async #onSelectedAccountChange(internalAccount: InternalAccount) {\n const oldSelectedAccountId = this.#selectedAccountId;\n this.#selectedAccountId = internalAccount.id;\n\n const needsUpdateNftMetadata =\n ((this.#isIpfsGatewayEnabled && this.#ipfsGateway !== '') ||\n this.#openSeaEnabled) &&\n oldSelectedAccountId !== internalAccount.id;\n\n if (needsUpdateNftMetadata) {\n await this.#updateNftUpdateForAccount(internalAccount);\n }\n }\n\n getNftApi() {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n return `${NFT_API_BASE_URL}/tokens`;\n }\n\n /**\n * Helper method to update nested state for allNfts and allNftContracts.\n *\n * @param newCollection - the modified piece of state to update in the controller's store\n * @param baseStateKey - The root key in the store to update.\n * @param passedConfig - An object containing the selectedAddress and chainId that are passed through the auto-detection flow.\n * @param passedConfig.userAddress - the address passed through the NFT detection flow to ensure assets are stored to the correct account\n * @param passedConfig.chainId - the chainId passed through the NFT detection flow to ensure assets are stored to the correct account\n */\n #updateNestedNftState<\n Key extends typeof ALL_NFTS_STATE_KEY | typeof ALL_NFTS_CONTRACTS_STATE_KEY,\n NftCollection extends Key extends typeof ALL_NFTS_STATE_KEY\n ? Nft[]\n : NftContract[],\n >(\n newCollection: NftCollection,\n baseStateKey: Key,\n { userAddress, chainId }: { userAddress: string; chainId: Hex },\n ) {\n // userAddress can be an empty string if it is not set via an account change or in constructor\n // while this doesn't cause any issues, we want to ensure that we don't store assets to an empty string address\n if (!userAddress) {\n return;\n }\n\n this.update((state) => {\n const oldState = state[baseStateKey];\n const addressState = oldState[userAddress] || {};\n const newAddressState = {\n ...addressState,\n [chainId]: newCollection,\n };\n state[baseStateKey] = {\n ...oldState,\n [userAddress]: newAddressState,\n };\n });\n }\n\n #getNftCollectionApi(): string {\n // False negative.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n return `${NFT_API_BASE_URL}/collections`;\n }\n\n /**\n * Request individual NFT information from NFT API.\n *\n * @param contractAddress - Hex address of the NFT contract.\n * @param tokenId - The NFT identifier.\n * @returns Promise resolving to the current NFT name and image.\n */\n async #getNftInformationFromApi(\n contractAddress: string,\n tokenId: string,\n ): Promise<NftMetadata> {\n // TODO Parameterize this by chainId for non-mainnet token detection\n // Attempt to fetch the data with the nft-api\n const urlParams = new URLSearchParams({\n chainIds: '1',\n tokens: `${contractAddress}:${tokenId}`,\n includeTopBid: 'true',\n includeAttributes: 'true',\n includeLastSale: 'true',\n }).toString();\n\n // First fetch token information\n const nftInformation: ReservoirResponse | undefined =\n await fetchWithErrorHandling({\n url: `${this.getNftApi()}?${urlParams}`,\n options: {\n headers: {\n Version: NFT_API_VERSION,\n },\n },\n });\n // Params for getCollections API call\n const getCollectionParams = new URLSearchParams({\n chainId: '1',\n id: `${nftInformation?.tokens[0]?.token?.collection?.id as string}`,\n }).toString();\n // Fetch collection information using collectionId\n const collectionInformation: GetCollectionsResponse | undefined =\n await fetchWithErrorHandling({\n url: `${NFT_API_BASE_URL as string}/collections?${getCollectionParams}`,\n options: {\n headers: {\n Version: NFT_API_VERSION,\n },\n },\n });\n // if we were still unable to fetch the data we return out the default/null of `NftMetadata`\n if (!nftInformation?.tokens?.[0]?.token) {\n return {\n name: null,\n description: null,\n image: null,\n standard: null,\n };\n }\n\n // if we've reached this point, we have successfully fetched some data for nftInformation\n // now we reconfigure the data to conform to the `NftMetadata` type for storage.\n\n const {\n image,\n metadata: { imageOriginal } = {},\n name,\n description,\n collection,\n kind,\n rarityRank,\n rarity,\n attributes,\n lastSale,\n imageSmall,\n } = nftInformation.tokens[0].token;\n\n /* istanbul ignore next */\n const nftMetadata: NftMetadata = Object.assign(\n {},\n { name: name || null },\n { description: description || null },\n { image: image || null },\n collection?.creator && { creator: collection.creator },\n imageOriginal && { imageOriginal },\n imageSmall && { imageThumbnail: imageSmall },\n kind && { standard: kind.toUpperCase() },\n lastSale && { lastSale },\n attributes && { attributes },\n nftInformation.tokens[0].market?.topBid && {\n topBid: nftInformation.tokens[0].market?.topBid,\n },\n rarityRank && { rarityRank },\n rarity && { rarity },\n (collection || collectionInformation) && {\n collection: {\n ...(collection || {}),\n creator:\n collection?.creator ||\n collectionInformation?.collections[0].creator,\n openseaVerificationStatus:\n collectionInformation?.collections[0].openseaVerificationStatus,\n contractDeployedAt:\n collectionInformation?.collections[0].contractDeployedAt,\n ownerCount: collectionInformation?.collections[0].ownerCount,\n topBid: collectionInformation?.collections[0].topBid,\n },\n },\n );\n\n return nftMetadata;\n }\n\n /**\n * Request individual NFT information from contracts that follows Metadata Interface.\n *\n * @param contractAddress - Hex address of the NFT contract.\n * @param tokenId - The NFT identifier.\n * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @returns Promise resolving to the current NFT name and image.\n */\n async #getNftInformationFromTokenURI(\n contractAddress: string,\n tokenId: string,\n networkClientId?: NetworkClientId,\n ): Promise<NftMetadata> {\n const result = await this.#getNftURIAndStandard(\n contractAddress,\n tokenId,\n networkClientId,\n );\n let tokenURI = result[0];\n const standard = result[1];\n\n const hasIpfsTokenURI = tokenURI.startsWith('ipfs://');\n\n if (hasIpfsTokenURI && !this.#isIpfsGatewayEnabled) {\n return {\n image: null,\n name: null,\n description: null,\n standard: standard || null,\n favorite: false,\n tokenURI: tokenURI ?? null,\n };\n }\n\n const isDisplayNFTMediaToggleEnabled = this.#openSeaEnabled;\n if (!hasIpfsTokenURI && !isDisplayNFTMediaToggleEnabled) {\n return {\n image: null,\n name: null,\n description: null,\n standard: standard || null,\n favorite: false,\n tokenURI: tokenURI ?? null,\n };\n }\n\n if (hasIpfsTokenURI) {\n tokenURI = await getFormattedIpfsUrl(\n this.#ipfsGateway,\n tokenURI,\n this.#useIpfsSubdomains,\n );\n }\n if (tokenURI.startsWith('data:image/')) {\n return {\n image: tokenURI,\n name: null,\n description: null,\n standard: standard || null,\n favorite: false,\n tokenURI: tokenURI ?? null,\n };\n }\n\n try {\n const object = await handleFetch(tokenURI);\n // TODO: Check image_url existence. This is not part of EIP721 nor EIP1155\n const image = Object.prototype.hasOwnProperty.call(object, 'image')\n ? 'image'\n : /* istanbul ignore next */ 'image_url';\n\n return {\n image: object[image],\n name: object.name,\n description: object.description,\n standard,\n favorite: false,\n tokenURI: tokenURI ?? null,\n };\n } catch {\n return {\n image: null,\n name: null,\n description: null,\n standard: standard || null,\n favorite: false,\n tokenURI: tokenURI ?? null,\n };\n }\n }\n\n /**\n * Retrieve NFT uri with metadata. TODO Update method to use IPFS.\n *\n * @param contractAddress - NFT contract address.\n * @param tokenId - NFT token id.\n * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @returns Promise resolving NFT uri and token standard.\n */\n async #getNftURIAndStandard(\n contractAddress: string,\n tokenId: string,\n networkClientId?: NetworkClientId,\n ): Promise<[string, string]> {\n // try ERC721 uri\n try {\n const uri = await this.messagingSystem.call(\n 'AssetsContractController:getERC721TokenURI',\n contractAddress,\n tokenId,\n networkClientId,\n );\n return [uri, ERC721];\n } catch {\n // Ignore error\n }\n\n // try ERC1155 uri\n try {\n const tokenURI = await this.messagingSystem.call(\n 'AssetsContractController:getERC1155TokenURI',\n contractAddress,\n tokenId,\n networkClientId,\n );\n\n /**\n * According to EIP1155 the URI value allows for ID substitution\n * in case the string `{id}` exists.\n * https://eips.ethereum.org/EIPS/eip-1155#metadata\n */\n\n if (!tokenURI.includes('{id}')) {\n return [tokenURI, ERC1155];\n }\n\n const hexTokenId = remove0x(BNToHex(new BN(tokenId)))\n .padStart(64, '0')\n .toLowerCase();\n return [tokenURI.replace('{id}', hexTokenId), ERC1155];\n } catch {\n // Ignore error\n }\n\n return ['', ''];\n }\n\n /**\n * Request individual NFT information (name, image url and description).\n *\n * @param contractAddress - Hex address of the NFT contract.\n * @param tokenId - The NFT identifier.\n * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @returns Promise resolving to the current NFT name and image.\n */\n async #getNftInformation(\n contractAddress: string,\n tokenId: string,\n networkClientId?: NetworkClientId,\n ): Promise<NftMetadata> {\n const chainId = this.#getCorrectChainId({\n networkClientId,\n });\n const [blockchainMetadata, nftApiMetadata] = await Promise.all([\n safelyExecute(() =>\n this.#getNftInformationFromTokenURI(\n contractAddress,\n tokenId,\n networkClientId,\n ),\n ),\n this.#openSeaEnabled && chainId === '0x1'\n ? safelyExecute(() =>\n this.#getNftInformationFromApi(contractAddress, tokenId),\n )\n : undefined,\n ]);\n return {\n ...nftApiMetadata,\n name: blockchainMetadata?.name ?? nftApiMetadata?.name ?? null,\n description:\n blockchainMetadata?.description ?? nftApiMetadata?.description ?? null,\n image: nftApiMetadata?.image ?? blockchainMetadata?.image ?? null,\n standard:\n blockchainMetadata?.standard ?? nftApiMetadata?.standard ?? null,\n tokenURI: blockchainMetadata?.tokenURI ?? null,\n };\n }\n\n /**\n * Request NFT contract information from the contract itself.\n *\n * @param contractAddress - Hex address of the NFT contract.\n * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @returns Promise resolving to the current NFT name and image.\n */\n async #getNftContractInformationFromContract(\n contractAddress: string,\n networkClientId?: NetworkClientId,\n ): Promise<\n Partial<ApiNftContract> &\n Pick<ApiNftContract, 'address'> &\n Pick<ApiNftContract, 'collection'>\n > {\n const [name, symbol] = await Promise.all([\n this.messagingSystem.call(\n 'AssetsContractController:getERC721AssetName',\n contractAddress,\n networkClientId,\n ),\n this.messagingSystem.call(\n 'AssetsContractController:getERC721AssetSymbol',\n contractAddress,\n networkClientId,\n ),\n ]);\n\n return {\n collection: { name },\n symbol,\n address: contractAddress,\n };\n }\n\n /**\n * Request NFT contract information from Blockchain and aggregate with received data from NFTMetadata.\n *\n * @param contractAddress - Hex address of the NFT contract.\n * @param nftMetadataFromApi - Received NFT information to be aggregated with blockchain contract information.\n * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @returns Promise resolving to the NFT contract name, image and description.\n */\n async #getNftContractInformation(\n contractAddress: string,\n nftMetadataFromApi: NftMetadata,\n networkClientId?: NetworkClientId,\n ): Promise<\n Partial<ApiNftContract> &\n Pick<ApiNftContract, 'address'> &\n Pick<ApiNftContract, 'collection'>\n > {\n const blockchainContractData = await safelyExecute(() =>\n this.#getNftContractInformationFromContract(\n contractAddress,\n networkClientId,\n ),\n );\n\n if (\n blockchainContractData ||\n !Object.values(nftMetadataFromApi).every((value) => value === null)\n ) {\n return {\n address: contractAddress,\n ...blockchainContractData,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n schema_name: nftMetadataFromApi?.standard ?? null,\n collection: {\n name: null,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n image_url:\n nftMetadataFromApi?.collection?.image ??\n nftMetadataFromApi?.collection?.imageUrl ??\n null,\n tokenCount: nftMetadataFromApi?.collection?.tokenCount ?? null,\n ...nftMetadataFromApi?.collection,\n ...blockchainContractData?.collection,\n },\n };\n }\n\n /* istanbul ignore next */\n return {\n address: contractAddress,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n asset_contract_type: null,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n created_date: null,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n schema_name: null,\n symbol: null,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n total_supply: null,\n description: null,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n external_link: null,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n collection: { name: null, image_url: null },\n };\n }\n\n /**\n * Adds an individual NFT to the stored NFT list.\n *\n * @param tokenAddress - Hex address of the NFT contract.\n * @param tokenId - The NFT identifier.\n * @param nftMetadata - NFT optional information (name, image and description).\n * @param nftContract - An object containing contract data of the NFT being added.\n * @param chainId - The chainId of the network where the NFT is being added.\n * @param userAddress - The address of the account where the NFT is being added.\n * @param source - Whether the NFT was detected, added manually or suggested by a dapp.\n * @returns A promise resolving to `undefined`.\n */\n async #addIndividualNft(\n tokenAddress: string,\n tokenId: string,\n nftMetadata: NftMetadata,\n nftContract: NftContract,\n chainId: Hex,\n userAddress: string,\n source: Source,\n ): Promise<void> {\n const releaseLock = await this.#mutex.acquire();\n try {\n const checksumHexAddress = toChecksumHexAddress(tokenAddress);\n const { allNfts } = this.state;\n\n const nfts = [...(allNfts[userAddress]?.[chainId] ?? [])];\n\n const existingEntry = nfts.find(\n (nft) =>\n nft.address.toLowerCase() === checksumHexAddress.toLowerCase() &&\n nft.tokenId === tokenId,\n );\n\n if (existingEntry) {\n const differentMetadata = compareNftMetadata(\n nftMetadata,\n existingEntry,\n );\n\n const hasNewFields = hasNewCollectionFields(nftMetadata, existingEntry);\n\n if (\n !differentMetadata &&\n existingEntry.isCurrentlyOwned &&\n !hasNewFields\n ) {\n return;\n }\n\n const indexToUpdate = nfts.findIndex(\n (nft) =>\n nft.address.toLowerCase() === checksumHexAddress.toLowerCase() &&\n nft.tokenId === tokenId,\n );\n\n if (indexToUpdate !== -1) {\n nfts[indexToUpdate] = {\n ...existingEntry,\n ...nftMetadata,\n };\n }\n } else {\n const newEntry: Nft = {\n address: checksumHexAddress,\n tokenId,\n favorite: false,\n isCurrentlyOwned: true,\n ...nftMetadata,\n };\n\n nfts.push(newEntry);\n }\n\n this.#updateNestedNftState(nfts, ALL_NFTS_STATE_KEY, {\n chainId,\n userAddress,\n });\n\n if (this.#onNftAdded) {\n this.#onNftAdded({\n address: checksumHexAddress,\n symbol: nftContract.symbol,\n tokenId: tokenId.toString(),\n standard: nftMetadata.standard,\n source,\n });\n }\n } finally {\n releaseLock();\n }\n }\n\n /**\n * Adds an NFT contract to the stored NFT contracts list.\n *\n * @param options - options.\n * @param options.tokenAddress - Hex address of the NFT contract.\n * @param options.userAddress - The address of the account where the NFT is being added.\n * @param options.nftMetadata - The retrieved NFTMetadata from API.\n * @param options.networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @param options.source - Whether the NFT was detected, added manually or suggested by a dapp.\n * @param options.chainIdHex - The chainId to add the NFT contract to.\n * @returns Promise resolving to the current NFT contracts list.\n */\n async #addNftContract({\n tokenAddress,\n userAddress,\n networkClientId,\n source,\n nftMetadata,\n chainIdHex,\n }: {\n tokenAddress: string;\n userAddress: string;\n nftMetadata: NftMetadata;\n networkClientId?: NetworkClientId;\n source?: Source;\n chainIdHex?: Hex;\n }): Promise<NftContract[]> {\n const releaseLock = await this.#mutex.acquire();\n try {\n const checksumHexAddress = toChecksumHexAddress(tokenAddress);\n const { allNftContracts } = this.state;\n // TODO: revisit this with Solana support and instead of passing chainId, make sure chainId is read from nftMetadata when nftMetadata is available\n const chainId =\n chainIdHex || this.#getCorrectChainId({ networkClientId });\n\n const nftContracts = allNftContracts[userAddress]?.[chainId] || [];\n\n const existingEntry = nftContracts.find(\n (nftContract) =>\n nftContract.address.toLowerCase() ===\n checksumHexAddress.toLowerCase(),\n );\n if (existingEntry) {\n return nftContracts;\n }\n\n // this doesn't work currently for detection if the user switches networks while the detection is processing\n // will be fixed once detection uses networkClientIds\n // get name and symbol if ERC721 then put together the metadata\n const contractInformation = await this.#getNftContractInformation(\n checksumHexAddress,\n nftMetadata,\n networkClientId,\n );\n const {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n asset_contract_type,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n created_date,\n symbol,\n description,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n external_link,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n schema_name,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n collection: { name, image_url, tokenCount },\n } = contractInformation;\n\n // If the nft is auto-detected we want some valid metadata to be present\n if (\n source === Source.Detected &&\n 'address' in contractInformation &&\n typeof contractInformation.address === 'string' &&\n 'collection' in contractInformation &&\n contractInformation.collection.name === null &&\n 'image_url' in contractInformation.collection &&\n contractInformation.collection.image_url === null &&\n Object.entries(contractInformation).every(([key, value]) => {\n return key === 'address' || key === 'collection' || !value;\n })\n ) {\n return nftContracts;\n }\n\n /* istanbul ignore next */\n const newEntry: NftContract = Object.assign(\n {},\n { address: checksumHexAddress },\n description && { description },\n name && { name },\n image_url && { logo: image_url },\n symbol && { symbol },\n tokenCount !== null &&\n typeof tokenCount !== 'undefined' && { totalSupply: tokenCount },\n asset_contract_type && { assetContractType: asset_contract_type },\n created_date && { createdDate: created_date },\n schema_name && { schemaName: schema_name },\n external_link && { externalLink: external_link },\n );\n const newNftContracts = [...nftContracts, newEntry];\n this.#updateNestedNftState(\n newNftContracts,\n ALL_NFTS_CONTRACTS_STATE_KEY,\n {\n chainId,\n userAddress,\n },\n );\n\n return newNftContracts;\n } finally {\n releaseLock();\n }\n }\n\n /**\n * Removes an individual NFT from the stored token list and saves it in ignored NFTs list.\n *\n * @param address - Hex address of the NFT contract.\n * @param tokenId - Token identifier of the NFT.\n * @param options - options.\n * @param options.chainId - The chainId of the network where the NFT is being removed.\n * @param options.userAddress - The address of the account where the NFT is being removed.\n */\n #removeAndIgnoreIndividualNft(\n address: string,\n tokenId: string,\n {\n chainId,\n userAddress,\n }: {\n chainId: Hex;\n userAddress: string;\n },\n ) {\n const checksumHexAddress = toChecksumHexAddress(address);\n const { allNfts, ignoredNfts } = this.state;\n const newIgnoredNfts = [...ignoredNfts];\n const nfts = allNfts[userAddress]?.[chainId] || [];\n const newNfts = nfts.filter((nft) => {\n if (\n nft.address.toLowerCase() === checksumHexAddress.toLowerCase() &&\n nft.tokenId === tokenId\n ) {\n const alreadyIgnored = newIgnoredNfts.find(\n (c) => c.address === checksumHexAddress && c.tokenId === tokenId,\n );\n !alreadyIgnored && newIgnoredNfts.push(nft);\n return false;\n }\n return true;\n });\n\n this.#updateNestedNftState(newNfts, ALL_NFTS_STATE_KEY, {\n userAddress,\n chainId,\n });\n\n this.update((state) => {\n state.ignoredNfts = newIgnoredNfts;\n });\n }\n\n /**\n * Removes an individual NFT from the stored token list.\n *\n * @param address - Hex address of the NFT contract.\n * @param tokenId - Token identifier of the NFT.\n * @param options - options.\n * @param options.chainId - The chainId of the network where the NFT is being removed.\n * @param options.userAddress - The address of the account where the NFT is being removed.\n */\n #removeIndividualNft(\n address: string,\n tokenId: string,\n { chainId, userAddress }: { chainId: Hex; userAddress: string },\n ) {\n const checksumHexAddress = toChecksumHexAddress(address);\n const { allNfts } = this.state;\n const nfts = allNfts[userAddress]?.[chainId] || [];\n const newNfts = nfts.filter(\n (nft) =>\n !(\n nft.address.toLowerCase() === checksumHexAddress.toLowerCase() &&\n nft.tokenId === tokenId\n ),\n );\n this.#updateNestedNftState(newNfts, ALL_NFTS_STATE_KEY, {\n userAddress,\n chainId,\n });\n }\n\n /**\n * Removes an NFT contract to the stored NFT contracts list.\n *\n * @param address - Hex address of the NFT contract.\n * @param options - options.\n * @param options.chainId - The chainId of the network where the NFT is being removed.\n * @param options.userAddress - The address of the account where the NFT is being removed.\n * @returns Promise resolving to the current NFT contracts list.\n */\n #removeNftContract(\n address: string,\n { chainId, userAddress }: { chainId: Hex; userAddress: string },\n ): NftContract[] {\n const checksumHexAddress = toChecksumHexAddress(address);\n const { allNftContracts } = this.state;\n const nftContracts = allNftContracts[userAddress]?.[chainId] || [];\n\n const newNftContracts = nftContracts.filter(\n (nftContract) =>\n !(\n nftContract.address.toLowerCase() === checksumHexAddress.toLowerCase()\n ),\n );\n this.#updateNestedNftState(newNftContracts, ALL_NFTS_CONTRACTS_STATE_KEY, {\n chainId,\n userAddress,\n });\n\n return newNftContracts;\n }\n\n async #validateWatchNft(\n asset: NftAsset,\n type: NFTStandardType,\n userAddress: string,\n { networkClientId }: { networkClientId?: NetworkClientId } = {},\n ) {\n const { address: contractAddress, tokenId } = asset;\n\n // Validate parameters\n if (!type) {\n throw rpcErrors.invalidParams('Asset type is required');\n }\n\n if (type !== ERC721 && type !== ERC1155) {\n throw rpcErrors.invalidParams(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `Non NFT asset type ${type} not supported by watchNft`,\n );\n }\n\n if (!contractAddress || !tokenId) {\n throw rpcErrors.invalidParams('Both address and tokenId are required');\n }\n\n if (!isAddress(contractAddress)) {\n throw rpcErrors.invalidParams('Invalid address');\n }\n\n if (!/^\\d+$/u.test(tokenId)) {\n throw rpcErrors.invalidParams('Invalid tokenId');\n }\n\n // Check if the user owns the suggested NFT\n try {\n const isOwner = await this.isNftOwner(\n userAddress,\n contractAddress,\n tokenId,\n { networkClientId },\n );\n if (!isOwner) {\n throw rpcErrors.invalidInput(\n 'Suggested NFT is not owned by the selected account',\n );\n }\n } catch (error) {\n // error thrown here: \"Unable to verify ownership. Possibly because the standard is not supported or the user's currently selected network does not match the chain of the asset in question.\"\n if (error instanceof Error) {\n throw rpcErrors.resourceUnavailable(error.message);\n }\n throw error;\n }\n }\n\n // temporary method to get the correct chainId until we remove chainId from the config & the chainId arg from the detection logic\n // Just a helper method to prefer the networkClient chainId first then the chainId argument and then finally the config chainId\n #getCorrectChainId({\n networkClientId,\n }: {\n networkClientId?: NetworkClientId;\n }) {\n if (networkClientId) {\n const {\n configuration: { chainId },\n } = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n return chainId;\n }\n return this.#chainId;\n }\n\n /**\n * Adds a new suggestedAsset to state. Parameters will be validated according to\n * asset type being watched. A `<suggestedNftMeta.id>:pending` hub event will be emitted once added.\n *\n * @param asset - The asset to be watched. For now ERC721 and ERC1155 tokens are accepted.\n * @param asset.address - The address of the asset contract.\n * @param asset.tokenId - The ID of the asset.\n * @param type - The asset type.\n * @param origin - Domain origin to register the asset from.\n * @param options - Options bag.\n * @param options.networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @param options.userAddress - The address of the account where the NFT is being added.\n * @returns Object containing a Promise resolving to the suggestedAsset address if accepted.\n */\n async watchNft(\n asset: NftAsset,\n type: NFTStandardType,\n origin: string,\n {\n networkClientId,\n userAddress,\n }: {\n networkClientId?: NetworkClientId;\n userAddress?: string;\n } = {},\n ) {\n const addressToSearch = this.#getAddressOrSelectedAddress(userAddress);\n if (!addressToSearch) {\n return;\n }\n\n await this.#validateWatchNft(asset, type, addressToSearch);\n\n const nftMetadata = await this.#getNftInformation(\n asset.address,\n asset.tokenId,\n networkClientId,\n );\n\n if (nftMetadata.standard && nftMetadata.standard !== type) {\n throw rpcErrors.invalidInput(\n `Suggested NFT of type ${nftMetadata.standard} does not match received type ${type}`,\n );\n }\n\n const suggestedNftMeta: SuggestedNftMeta = {\n asset: { ...asset, ...nftMetadata },\n type,\n id: random(),\n time: Date.now(),\n interactingAddress: addressToSearch,\n origin,\n };\n await this._requestApproval(suggestedNftMeta);\n const { address, tokenId } = asset;\n const { name, standard, description, image } = nftMetadata;\n\n await this.addNft(address, tokenId, {\n nftMetadata: {\n name: name ?? null,\n description: description ?? null,\n image: image ?? null,\n standard: standard ?? null,\n },\n userAddress,\n source: Source.Dapp,\n networkClientId,\n });\n }\n\n /**\n * Sets an OpenSea API key to retrieve NFT information.\n *\n * @param openSeaApiKey - OpenSea API key.\n */\n setApiKey(openSeaApiKey: string) {\n this.openSeaApiKey = openSeaApiKey;\n }\n\n /**\n * Checks the ownership of a ERC-721 or ERC-1155 NFT for a given address.\n *\n * @param ownerAddress - User public address.\n * @param nftAddress - NFT contract address.\n * @param tokenId - NFT token ID.\n * @param options - Options bag.\n * @param options.networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @returns Promise resolving the NFT ownership.\n */\n async isNftOwner(\n ownerAddress: string,\n nftAddress: string,\n tokenId: string,\n {\n networkClientId,\n }: {\n networkClientId?: NetworkClientId;\n } = {},\n ): Promise<boolean> {\n // Checks the ownership for ERC-721.\n try {\n const owner = await this.messagingSystem.call(\n 'AssetsContractController:getERC721OwnerOf',\n nftAddress,\n tokenId,\n networkClientId,\n );\n return ownerAddress.toLowerCase() === owner.toLowerCase();\n // eslint-disable-next-line no-empty\n } catch {\n // Ignore ERC-721 contract error\n }\n\n // Checks the ownership for ERC-1155.\n try {\n const balance = await this.messagingSystem.call(\n 'AssetsContractController:getERC1155BalanceOf',\n ownerAddress,\n nftAddress,\n tokenId,\n networkClientId,\n );\n return !balance.isZero();\n // eslint-disable-next-line no-empty\n } catch {\n // Ignore ERC-1155 contract error\n }\n\n throw new Error(\n `Unable to verify ownership. Possibly because the standard is not supported or the user's currently selected network does not match the chain of the asset in question.`,\n );\n }\n\n /**\n * Verifies currently selected address owns entered NFT address/tokenId combo and\n * adds the NFT and respective NFT contract to the stored NFT and NFT contracts lists.\n *\n * @param address - Hex address of the NFT contract.\n * @param tokenId - The NFT identifier.\n * @param options - an object of arguments\n * @param options.userAddress - The address of the current user.\n * @param options.networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @param options.source - Whether the NFT was detected, added manually or suggested by a dapp.\n */\n async addNftVerifyOwnership(\n address: string,\n tokenId: string,\n {\n userAddress,\n networkClientId,\n source,\n }: {\n userAddress?: string;\n networkClientId?: NetworkClientId;\n source?: Source;\n } = {},\n ) {\n const addressToSearch = this.#getAddressOrSelectedAddress(userAddress);\n\n if (\n !(await this.isNftOwner(addressToSearch, address, tokenId, {\n networkClientId,\n }))\n ) {\n throw new Error('This NFT is not owned by the user');\n }\n await this.addNft(address, tokenId, {\n networkClientId,\n userAddress: addressToSearch,\n source,\n });\n }\n\n /**\n * Adds an NFT and respective NFT contract to the stored NFT and NFT contracts lists.\n *\n * @param tokenAddress - Hex address of the NFT contract.\n * @param tokenId - The NFT identifier.\n * @param options - an object of arguments\n * @param options.nftMetadata - NFT optional metadata.\n * @param options.userAddress - The address of the current user.\n * @param options.source - Whether the NFT was detected, added manually or suggested by a dapp.\n * @param options.networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @param options.chainId - The chain ID to add the NFT to.\n * @returns Promise resolving to the current NFT list.\n */\n async addNft(\n tokenAddress: string,\n tokenId: string,\n {\n nftMetadata,\n userAddress,\n source = Source.Custom,\n networkClientId,\n chainId,\n }: {\n nftMetadata?: NftMetadata;\n userAddress?: string;\n source?: Source;\n networkClientId?: NetworkClientId;\n chainId?: Hex;\n } = {},\n ) {\n const addressToSearch = this.#getAddressOrSelectedAddress(userAddress);\n if (!addressToSearch) {\n return;\n }\n\n const checksumHexAddress = toChecksumHexAddress(tokenAddress);\n\n // TODO: revisit this with Solana support and instead of passing chainId, make sure chainId is read from nftMetadata\n const chainIdToAddTo =\n chainId || this.#getCorrectChainId({ networkClientId });\n\n nftMetadata =\n nftMetadata ||\n (await this.#getNftInformation(\n checksumHexAddress,\n tokenId,\n networkClientId,\n ));\n\n const newNftContracts = await this.#addNftContract({\n tokenAddress: checksumHexAddress,\n userAddress: addressToSearch,\n networkClientId,\n source,\n nftMetadata,\n chainIdHex: source === Source.Detected ? chainIdToAddTo : undefined,\n });\n\n // If NFT contract was not added, do not add individual NFT\n const nftContract = newNftContracts.find(\n (contract) =>\n contract.address.toLowerCase() === checksumHexAddress.toLowerCase(),\n );\n // This is the case when the NFT is added manually and not detected automatically\n if (!nftMetadata.chainId) {\n nftMetadata.chainId = convertHexToDecimal(chainIdToAddTo);\n }\n\n // If NFT contract information, add individual NFT\n if (nftContract) {\n await this.#addIndividualNft(\n checksumHexAddress,\n tokenId,\n nftMetadata,\n nftContract,\n chainIdToAddTo,\n addressToSearch,\n source,\n );\n }\n }\n\n /**\n * Refetches NFT metadata and updates the state\n *\n * @param options - Options for refetching NFT metadata\n * @param options.nfts - nfts to update metadata for.\n * @param options.userAddress - The current user address\n * @param options.networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n */\n async updateNftMetadata({\n nfts,\n userAddress,\n networkClientId,\n }: {\n nfts: Nft[];\n userAddress?: string;\n networkClientId?: NetworkClientId;\n }) {\n const addressToSearch = this.#getAddressOrSelectedAddress(userAddress);\n\n const releaseLock = await this.#mutex.acquire();\n\n try {\n const chainId = this.#getCorrectChainId({ networkClientId });\n\n const nftsWithChecksumAdr = nfts.map((nft) => {\n return {\n ...nft,\n address: toChecksumHexAddress(nft.address),\n };\n });\n const nftMetadataResults = await Promise.all(\n nftsWithChecksumAdr.map(async (nft) => {\n const resMetadata = await this.#getNftInformation(\n nft.address,\n nft.tokenId,\n networkClientId,\n );\n return {\n nft,\n newMetadata: resMetadata,\n };\n }),\n );\n\n // We want to avoid updating the state if the state and fetched nft info are the same\n const nftsWithDifferentMetadata: NftUpdate[] = [];\n const { allNfts } = this.state;\n const stateNfts = allNfts[addressToSearch]?.[chainId] || [];\n\n nftMetadataResults.forEach((singleNft) => {\n const existingEntry: Nft | undefined = stateNfts.find(\n (nft) =>\n nft.address.toLowerCase() === singleNft.nft.address.toLowerCase() &&\n nft.tokenId === singleNft.nft.tokenId,\n );\n\n if (existingEntry) {\n const differentMetadata = compareNftMetadata(\n singleNft.newMetadata,\n existingEntry,\n );\n\n if (differentMetadata) {\n nftsWithDifferentMetadata.push(singleNft);\n }\n }\n });\n\n if (nftsWithDifferentMetadata.length !== 0) {\n nftsWithDifferentMetadata.forEach((elm) =>\n this.updateNft(elm.nft, elm.newMetadata, addressToSearch, chainId),\n );\n }\n } finally {\n releaseLock();\n }\n }\n\n /**\n * Removes an NFT from the stored token list.\n *\n * @param address - Hex address of the NFT contract.\n * @param tokenId - Token identifier of the NFT.\n * @param options - an object of arguments\n * @param options.networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @param options.userAddress - The address of the account where the NFT is being removed.\n */\n removeNft(\n address: string,\n tokenId: string,\n {\n networkClientId,\n userAddress,\n }: { networkClientId?: NetworkClientId; userAddress?: string } = {},\n ) {\n const addressToSearch = this.#getAddressOrSelectedAddress(userAddress);\n const chainId = this.#getCorrectChainId({ networkClientId });\n const checksumHexAddress = toChecksumHexAddress(address);\n this.#removeIndividualNft(checksumHexAddress, tokenId, {\n chainId,\n userAddress: addressToSearch,\n });\n const { allNfts } = this.state;\n const nfts = allNfts[addressToSearch]?.[chainId] || [];\n const remainingNft = nfts.find(\n (nft) => nft.address.toLowerCase() === checksumHexAddress.toLowerCase(),\n );\n\n if (!remainingNft) {\n this.#removeNftContract(checksumHexAddress, {\n chainId,\n userAddress: addressToSearch,\n });\n }\n }\n\n /**\n * Removes an NFT from the stored token list and saves it in ignored NFTs list.\n *\n * @param address - Hex address of the NFT contract.\n * @param tokenId - Token identifier of the NFT.\n * @param options - an object of arguments\n * @param options.networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @param options.userAddress - The address of the account where the NFT is being removed.\n */\n removeAndIgnoreNft(\n address: string,\n tokenId: string,\n {\n networkClientId,\n userAddress,\n }: { networkClientId?: NetworkClientId; userAddress?: string } = {},\n ) {\n const addressToSearch = this.#getAddressOrSelectedAddress(userAddress);\n const chainId = this.#getCorrectChainId({ networkClientId });\n const checksumHexAddress = toChecksumHexAddress(address);\n this.#removeAndIgnoreIndividualNft(checksumHexAddress, tokenId, {\n chainId,\n userAddress: addressToSearch,\n });\n const { allNfts } = this.state;\n const nfts = allNfts[addressToSearch]?.[chainId] || [];\n const remainingNft = nfts.find(\n (nft) => nft.address.toLowerCase() === checksumHexAddress.toLowerCase(),\n );\n if (!remainingNft) {\n this.#removeNftContract(checksumHexAddress, {\n chainId,\n userAddress: addressToSearch,\n });\n }\n }\n\n /**\n * Removes all NFTs from the ignored list.\n */\n clearIgnoredNfts() {\n this.update((state) => {\n state.ignoredNfts = [];\n });\n }\n\n /**\n * Checks whether input NFT is still owned by the user\n * And updates the isCurrentlyOwned value on the NFT object accordingly.\n *\n * @param nft - The NFT object to check and update.\n * @param batch - A boolean indicating whether this method is being called as part of a batch or single update.\n * @param accountParams - The userAddress and chainId to check ownership against\n * @param accountParams.userAddress - the address passed through the confirmed transaction flow to ensure assets are stored to the correct account\n * @param accountParams.networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @returns the NFT with the updated isCurrentlyOwned value\n */\n async checkAndUpdateSingleNftOwnershipStatus(\n nft: Nft,\n batch: boolean,\n {\n userAddress,\n networkClientId,\n }: { networkClientId?: NetworkClientId; userAddress?: string } = {},\n ) {\n const addressToSearch = this.#getAddressOrSelectedAddress(userAddress);\n const chainId = this.#getCorrectChainId({ networkClientId });\n const { address, tokenId } = nft;\n let isOwned = nft.isCurrentlyOwned;\n try {\n isOwned = await this.isNftOwner(addressToSearch, address, tokenId, {\n networkClientId,\n });\n } catch {\n // ignore error\n // this will only throw an error 'Unable to verify ownership' in which case\n // we want to keep the current value of isCurrentlyOwned for this flow.\n }\n\n const updatedNft = {\n ...nft,\n isCurrentlyOwned: isOwned,\n };\n\n if (batch) {\n return updatedNft;\n }\n\n // if this is not part of a batched update we update this one NFT in state\n const { allNfts } = this.state;\n const nfts = [...(allNfts[addressToSearch]?.[chainId] || [])];\n const indexToUpdate = nfts.findIndex(\n (item) =>\n item.tokenId === tokenId &&\n item.address.toLowerCase() === address.toLowerCase(),\n );\n\n if (indexToUpdate !== -1) {\n nfts[indexToUpdate] = updatedNft;\n this.update((state) => {\n state.allNfts[addressToSearch] = Object.assign(\n {},\n state.allNfts[addressToSearch],\n {\n [chainId]: nfts,\n },\n );\n });\n this.#updateNestedNftState(nfts, ALL_NFTS_STATE_KEY, {\n userAddress: addressToSearch,\n chainId,\n });\n }\n\n return updatedNft;\n }\n\n /**\n * Checks whether NFTs associated with current selectedAddress/chainId combination are still owned by the user\n * And updates the isCurrentlyOwned value on each accordingly.\n * @param options - an object of arguments\n * @param options.networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @param options.userAddress - The address of the account where the NFT ownership status is checked/updated.\n */\n async checkAndUpdateAllNftsOwnershipStatus({\n networkClientId,\n userAddress,\n }: {\n networkClientId?: NetworkClientId;\n userAddress?: string;\n } = {}) {\n const addressToSearch = this.#getAddressOrSelectedAddress(userAddress);\n const chainId = this.#getCorrectChainId({ networkClientId });\n const { allNfts } = this.state;\n const nfts = allNfts[addressToSearch]?.[chainId] || [];\n const updatedNfts = await Promise.all(\n nfts.map(async (nft) => {\n return (\n (await this.checkAndUpdateSingleNftOwnershipStatus(nft, true, {\n networkClientId,\n userAddress,\n })) ?? nft\n );\n }),\n );\n\n this.#updateNestedNftState(updatedNfts, ALL_NFTS_STATE_KEY, {\n userAddress: addressToSearch,\n chainId,\n });\n }\n\n /**\n * Update NFT favorite status.\n *\n * @param address - Hex address of the NFT contract.\n * @param tokenId - Hex address of the NFT contract.\n * @param favorite - NFT new favorite status.\n * @param options - an object of arguments\n * @param options.networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @param options.userAddress - The address of the account where the NFT is being removed.\n */\n updateNftFavoriteStatus(\n address: string,\n tokenId: string,\n favorite: boolean,\n {\n networkClientId,\n userAddress,\n }: {\n networkClientId?: NetworkClientId;\n userAddress?: string;\n } = {},\n ) {\n const addressToSearch = this.#getAddressOrSelectedAddress(userAddress);\n const chainId = this.#getCorrectChainId({ networkClientId });\n const { allNfts } = this.state;\n const nfts = [...(allNfts[addressToSearch]?.[chainId] || [])];\n const index: number = nfts.findIndex(\n (nft) => nft.address === address && nft.tokenId === tokenId,\n );\n\n if (index === -1) {\n return;\n }\n\n const updatedNft: Nft = {\n ...nfts[index],\n favorite,\n };\n\n // Update Nfts array\n nfts[index] = updatedNft;\n\n this.#updateNestedNftState(nfts, ALL_NFTS_STATE_KEY, {\n chainId,\n userAddress: addressToSearch,\n });\n }\n\n /**\n * Returns an NFT by the address and token id.\n *\n * @param address - Hex address of the NFT contract.\n * @param tokenId - Number that represents the id of the token.\n * @param selectedAddress - Hex address of the user account.\n * @param chainId - Id of the current network.\n * @returns Object containing the NFT and its position in the array\n */\n findNftByAddressAndTokenId(\n address: string,\n tokenId: string,\n selectedAddress: string,\n chainId: Hex,\n ): { nft: Nft; index: number } | null {\n const { allNfts } = this.state;\n const nfts = allNfts[selectedAddress]?.[chainId] || [];\n const index: number = nfts.findIndex(\n (nft) =>\n nft.address.toLowerCase() === address.toLowerCase() &&\n nft.tokenId === tokenId,\n );\n\n if (index === -1) {\n return null;\n }\n\n return { nft: nfts[index], index };\n }\n\n /**\n * Update NFT data.\n *\n * @param nft - NFT object to find the right NFT to updates.\n * @param updates - NFT partial object to update properties of the NFT.\n * @param selectedAddress - Hex address of the user account.\n * @param chainId - Id of the current network.\n */\n updateNft(\n nft: Nft,\n updates: Partial<Nft>,\n selectedAddress: string,\n chainId: Hex,\n ) {\n const { allNfts } = this.state;\n const nfts = allNfts[selectedAddress]?.[chainId] || [];\n const nftInfo = this.findNftByAddressAndTokenId(\n nft.address,\n nft.tokenId,\n selectedAddress,\n chainId,\n );\n\n if (!nftInfo) {\n return;\n }\n\n const updatedNft: Nft = {\n ...nft,\n ...updates,\n };\n\n const newNfts = [\n ...nfts.slice(0, nftInfo.index),\n updatedNft,\n ...nfts.slice(nftInfo.index + 1),\n ];\n this.#updateNestedNftState(newNfts, ALL_NFTS_STATE_KEY, {\n chainId,\n userAddress: selectedAddress,\n });\n }\n\n /**\n * Resets the transaction status of an NFT.\n *\n * @param transactionId - NFT transaction id.\n * @param selectedAddress - Hex address of the user account.\n * @param chainId - Id of the current network.\n * @returns a boolean indicating if the reset was well succeeded or not\n */\n resetNftTransactionStatusByTransactionId(\n transactionId: string,\n selectedAddress: string,\n chainId: Hex,\n ): boolean {\n const { allNfts } = this.state;\n const nfts = allNfts[selectedAddress]?.[chainId] || [];\n const index: number = nfts.findIndex(\n (nft) => nft.transactionId === transactionId,\n );\n\n if (index === -1) {\n return false;\n }\n const updatedNft: Nft = {\n ...nfts[index],\n transactionId: undefined,\n };\n\n const newNfts = [\n ...nfts.slice(0, index),\n updatedNft,\n ...nfts.slice(index + 1),\n ];\n\n this.#updateNestedNftState(newNfts, ALL_NFTS_STATE_KEY, {\n chainId,\n userAddress: selectedAddress,\n });\n\n return true;\n }\n\n /**\n * Fetches NFT Collection Metadata from the NFT API.\n *\n * @param contractAddresses - The contract addresses of the NFTs.\n * @param chainId - The chain ID of the network where the NFT is located.\n * @returns NFT collections metadata.\n */\n async getNFTContractInfo(\n contractAddresses: string[],\n chainId: Hex,\n ): Promise<{\n collections: Collection[];\n }> {\n const url = new URL(this.#getNftCollectionApi());\n\n url.searchParams.append('chainId', chainId);\n\n for (const address of contractAddresses) {\n url.searchParams.append('contract', address);\n }\n\n return await handleFetch(url, {\n headers: {\n Version: NFT_API_VERSION,\n },\n });\n }\n\n async _requestApproval(suggestedNftMeta: SuggestedNftMeta) {\n return this.messagingSystem.call(\n 'ApprovalController:addRequest',\n {\n id: suggestedNftMeta.id,\n origin: suggestedNftMeta.origin,\n type: ApprovalType.WatchAsset,\n requestData: {\n id: suggestedNftMeta.id,\n interactingAddress: suggestedNftMeta.interactingAddress,\n asset: {\n address: suggestedNftMeta.asset.address,\n tokenId: suggestedNftMeta.asset.tokenId,\n name: suggestedNftMeta.asset.name,\n description: suggestedNftMeta.asset.description,\n image: suggestedNftMeta.asset.image,\n standard: suggestedNftMeta.asset.standard,\n },\n },\n },\n true,\n );\n }\n\n #getAddressOrSelectedAddress(address: string | undefined): string {\n if (address) {\n return address;\n }\n\n // If the address is not defined (or empty), we fallback to the currently selected account's address\n const selectedAccount = this.messagingSystem.call(\n 'AccountsController:getAccount',\n this.#selectedAccountId,\n );\n return selectedAccount?.address || '';\n }\n\n async #updateNftUpdateForAccount(account: InternalAccount) {\n const nfts: Nft[] =\n this.state.allNfts[account.address]?.[this.#chainId] ?? [];\n\n // Filter only nfts\n const nftsToUpdate = nfts.filter(\n (singleNft) =>\n !singleNft.name && !singleNft.description && !singleNft.image,\n );\n if (\n nftsToUpdate.length !== 0 &&\n nftsToUpdate.length < NFT_UPDATE_THRESHOLD\n ) {\n await this.updateNftMetadata({\n nfts: nftsToUpdate,\n userAddress: account.address,\n });\n }\n }\n\n /**\n * Reset the controller state to the default state.\n */\n resetState() {\n this.update(() => {\n return getDefaultNftControllerState();\n });\n }\n}\n\nexport default NftController;\n"]}
@@ -207,11 +207,11 @@ class NftDetectionController extends base_controller_1.BaseController {
207
207
  if (!ignored) {
208
208
  /* istanbul ignore next */
209
209
  const nftMetadata = Object.assign({}, { name }, description && { description }, imageUrl && { image: imageUrl }, imageThumbnailUrl && { imageThumbnail: imageThumbnailUrl }, imageOriginalUrl && { imageOriginal: imageOriginalUrl }, kind && { standard: kind.toUpperCase() }, lastSale && { lastSale }, attributes && { attributes }, topBid && { topBid }, rarityRank && { rarityRank }, rarityScore && { rarityScore }, collection && { collection }, chainId && { chainId });
210
- const networkClientId = this.messagingSystem.call('NetworkController:getNetworkClientIdByChainId', (0, controller_utils_1.toHex)(chainId));
211
- await __classPrivateFieldGet(this, _NftDetectionController_addNft, "f").call(this, contract, tokenId, networkClientId, {
210
+ await __classPrivateFieldGet(this, _NftDetectionController_addNft, "f").call(this, contract, tokenId, {
212
211
  nftMetadata,
213
212
  userAddress,
214
213
  source: constants_1.Source.Detected,
214
+ chainId: (0, controller_utils_1.toHex)(chainId),
215
215
  });
216
216
  }
217
217
  });