diff --git a/packages/assets-controllers/src/NftController.test.ts b/packages/assets-controllers/src/NftController.test.ts index 78b78a41f4e..eaf7382ad9a 100644 --- a/packages/assets-controllers/src/NftController.test.ts +++ b/packages/assets-controllers/src/NftController.test.ts @@ -2216,47 +2216,6 @@ describe('NftController', () => { defaultSelectedAccount: OWNER_ACCOUNT, }); - const testTopBid = { - id: 'id', - sourceDomain: 'opensea.io', - price: { - currency: { - contract: '0x01', - name: 'Wrapped Ether', - symbol: 'WETH', - decimals: 18, - }, - amount: { - raw: '201300000000000000', - decimal: 0.2013, - usd: 716.46131, - native: 0.2013, - }, - netAmount: { - raw: '196267500000000000', - decimal: 0.19627, - usd: 698.54978, - native: 0.19627, - }, - }, - maker: 'testMaker', - validFrom: 1719228327, - validUntil: 1719228927, - }; - - nock(NFT_API_BASE_URL) - .get(`/collections?chainId=1&id=0x1`) - .reply(200, { - collections: [ - { - contractDeployedAt: 'timestampTest', - ownerCount: '989', - openseaVerificationStatus: 'verified', - topBid: testTopBid, - }, - ], - }); - await nftController.addNft('0x01', '1', 'mainnet'); expect( nftController.state.allNfts[OWNER_ACCOUNT.address][ChainId.mainnet][0], @@ -2276,10 +2235,6 @@ describe('NftController', () => { id: '0x1', creator: 'Oxaddress', tokenCount: 0, - contractDeployedAt: 'timestampTest', - ownerCount: '989', - openseaVerificationStatus: 'verified', - topBid: testTopBid, }, }); }); @@ -2316,10 +2271,6 @@ describe('NftController', () => { ], }); - nock(NFT_API_BASE_URL) - .get(`/collections?chainId=1&id=${ERC721_KUDOSADDRESS}`) - .replyWithError(new Error('Failed to fetch')); - nock('https://ipfs.gitcoin.co:443') .get('/api/v0/cat/QmPmt6EAaioN78ECnW5oCL8v2YvVSpoBjLCjrXhhsAvoov') .reply(200, { @@ -2349,12 +2300,7 @@ describe('NftController', () => { tokenURI: 'https://ipfs.gitcoin.co:443/api/v0/cat/QmPmt6EAaioN78ECnW5oCL8v2YvVSpoBjLCjrXhhsAvoov', collection: { - contractDeployedAt: undefined, - creator: undefined, id: ERC721_KUDOSADDRESS, - openseaVerificationStatus: undefined, - ownerCount: undefined, - topBid: undefined, }, }); @@ -2369,7 +2315,7 @@ describe('NftController', () => { schemaName: ERC721, }); }); - it('should add NFT erc721 and aggregate NFT data from both contract and NFT-API when call to Get Collections succeeds', async () => { + it('should add NFT erc721 and aggregate NFT data from both contract and NFT-API', async () => { const { nftController } = setupController({ getERC721AssetName: jest.fn().mockResolvedValue('KudosToken'), getERC721AssetSymbol: jest.fn().mockResolvedValue('KDO'), @@ -2401,19 +2347,6 @@ describe('NftController', () => { ], }); - nock(NFT_API_BASE_URL) - .get(`/collections?chainId=1&id=${ERC721_KUDOSADDRESS}`) - .reply(200, { - collections: [ - { - contractDeployedAt: 'timestampTest', - ownerCount: '989', - openseaVerificationStatus: 'verified', - creator: '0xcreator', - }, - ], - }); - nock('https://ipfs.gitcoin.co:443') .get('/api/v0/cat/QmPmt6EAaioN78ECnW5oCL8v2YvVSpoBjLCjrXhhsAvoov') .reply(200, { @@ -2444,11 +2377,6 @@ describe('NftController', () => { 'https://ipfs.gitcoin.co:443/api/v0/cat/QmPmt6EAaioN78ECnW5oCL8v2YvVSpoBjLCjrXhhsAvoov', collection: { id: ERC721_KUDOSADDRESS, - creator: '0xcreator', - contractDeployedAt: 'timestampTest', - ownerCount: '989', - openseaVerificationStatus: 'verified', - topBid: undefined, }, }); @@ -2802,10 +2730,6 @@ describe('NftController', () => { ], }); - nock(NFT_API_BASE_URL) - .get(`/collections?chainId=1&id=${ERC721_KUDOSADDRESS}`) - .replyWithError(new Error('Failed to fetch')); - await nftController.addNft( '0x6EbeAf8e8E946F0716E6533A6f2cefc83f60e8Ab', '123', @@ -2855,11 +2779,6 @@ describe('NftController', () => { tokenCount: '10', image: 'Kudos logo (from proxy API)', name: 'Kudos', - creator: undefined, - openseaVerificationStatus: undefined, - ownerCount: undefined, - contractDeployedAt: undefined, - topBid: undefined, }, }, ]); @@ -2886,7 +2805,7 @@ describe('NftController', () => { }); }); - it('should add an nft and nftContract when there is valid contract information and source is "detected" when call to get collections succeeds', async () => { + it('should add an nft and nftContract when there is valid contract information and source is "detected"', async () => { const mockOnNftAdded = jest.fn(); const { nftController } = setupController({ options: { @@ -2924,17 +2843,6 @@ describe('NftController', () => { ], }); - nock(NFT_API_BASE_URL) - .get(`/collections?chainId=1&id=${ERC721_KUDOSADDRESS}`) - .reply(200, { - collections: [ - { - creator: '0xcreator', - openseaVerificationStatus: 'verified', - }, - ], - }); - await nftController.addNft( '0x6EbeAf8e8E946F0716E6533A6f2cefc83f60e8Ab', '123', @@ -2984,11 +2892,6 @@ describe('NftController', () => { tokenCount: '10', image: 'Kudos logo (from proxy API)', name: 'Kudos', - creator: '0xcreator', - openseaVerificationStatus: 'verified', - ownerCount: undefined, - contractDeployedAt: undefined, - topBid: undefined, }, }, ]); @@ -5470,49 +5373,6 @@ describe('NftController', () => { expect(updateNftMetadataSpy).not.toHaveBeenCalled(); }); - describe('getNFTContractInfo', () => { - it('fetches NFT collections metadata successfully', async () => { - const contractAddresses = [ - '0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB', - '0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB', - ]; - const collections = [ - { - id: contractAddresses[0], - name: 'CryptoPunks', - slug: 'cryptopunks', - symbol: 'PUNK', - imageUrl: 'url', - }, - { - id: contractAddresses[1], - name: 'Kudos', - slug: 'kudos', - symbol: 'KUDOS', - imageUrl: 'url', - }, - ]; - nock(NFT_API_BASE_URL) - .get( - `/collections?chainId=0x1&contract=${contractAddresses[0]}&contract=${contractAddresses[1]}`, - ) - .reply(200, { - collections, - }); - - const { nftController } = setupController(); - - const response = await nftController.getNFTContractInfo( - contractAddresses, - ChainId.mainnet, - ); - - expect(response).toStrictEqual({ - collections, - }); - }); - }); - describe('resetState', () => { it('resets the state to default state', () => { const initialState: NftControllerState = { diff --git a/packages/assets-controllers/src/NftController.ts b/packages/assets-controllers/src/NftController.ts index 15113baa394..45dcf78c1b3 100644 --- a/packages/assets-controllers/src/NftController.ts +++ b/packages/assets-controllers/src/NftController.ts @@ -62,7 +62,6 @@ import type { Collection, Attributes, LastSale, - GetCollectionsResponse, TopBid, } from './NftDetectionController'; import type { NetworkControllerFindNetworkClientIdByChainIdAction } from '../../network-controller/src/NetworkController'; @@ -524,10 +523,6 @@ export class NftController extends BaseController< }); } - #getNftCollectionApi(): string { - return `${NFT_API_BASE_URL}/collections`; - } - /** * Request individual NFT information from NFT API. * @@ -559,21 +554,7 @@ export class NftController extends BaseController< }, }, }); - // Params for getCollections API call - const getCollectionParams = new URLSearchParams({ - chainId: '1', - id: `${nftInformation?.tokens[0]?.token?.collection?.id as string}`, - }).toString(); - // Fetch collection information using collectionId - const collectionInformation: GetCollectionsResponse | undefined = - await fetchWithErrorHandling({ - url: `${NFT_API_BASE_URL as string}/collections?${getCollectionParams}`, - options: { - headers: { - Version: NFT_API_VERSION, - }, - }, - }); + // if we were still unable to fetch the data we return out the default/null of `NftMetadata` if (!nftInformation?.tokens?.[0]?.token) { return { @@ -618,20 +599,7 @@ export class NftController extends BaseController< }, rarityRank && { rarityRank }, rarity && { rarity }, - (collection || collectionInformation) && { - collection: { - ...(collection || {}), - creator: - collection?.creator || - collectionInformation?.collections[0].creator, - openseaVerificationStatus: - collectionInformation?.collections[0].openseaVerificationStatus, - contractDeployedAt: - collectionInformation?.collections[0].contractDeployedAt, - ownerCount: collectionInformation?.collections[0].ownerCount, - topBid: collectionInformation?.collections[0].topBid, - }, - }, + collection && { collection }, ); return nftMetadata; @@ -2036,34 +2004,6 @@ export class NftController extends BaseController< return true; } - /** - * Fetches NFT Collection Metadata from the NFT API. - * - * @param contractAddresses - The contract addresses of the NFTs. - * @param chainId - The chain ID of the network where the NFT is located. - * @returns NFT collections metadata. - */ - async getNFTContractInfo( - contractAddresses: string[], - chainId: Hex, - ): Promise<{ - collections: Collection[]; - }> { - const url = new URL(this.#getNftCollectionApi()); - - url.searchParams.append('chainId', chainId); - - for (const address of contractAddresses) { - url.searchParams.append('contract', address); - } - - return await handleFetch(url, { - headers: { - Version: NFT_API_VERSION, - }, - }); - } - async _requestApproval(suggestedNftMeta: SuggestedNftMeta) { return this.messenger.call( 'ApprovalController:addRequest', diff --git a/packages/assets-controllers/src/NftDetectionController.ts b/packages/assets-controllers/src/NftDetectionController.ts index cff23beeb25..2adf229bd79 100644 --- a/packages/assets-controllers/src/NftDetectionController.ts +++ b/packages/assets-controllers/src/NftDetectionController.ts @@ -304,10 +304,6 @@ export type Attributes = { createdAt?: string; }; -export type GetCollectionsResponse = { - collections: CollectionResponse[]; -}; - export type CollectionResponse = { id?: string; chainId?: number;