diff --git a/src/NFT/NFT.router.spec.ts b/src/NFT/NFT.router.spec.ts index f2fc5c8c..692fed96 100644 --- a/src/NFT/NFT.router.spec.ts +++ b/src/NFT/NFT.router.spec.ts @@ -130,7 +130,9 @@ describe('when getting nfts', () => { it('should fail with a server error', async () => { mockNFTService.prototype.getNFTs.mockRejectedValueOnce('Rejected!') - const response = await server.get('/v1/nfts').expect(STATUS_CODES.error) + const response = await server + .get(`/v1/nfts?owner=${mockAddress}`) + .expect(STATUS_CODES.error) expect(response.body).toEqual({ data: {}, @@ -147,9 +149,13 @@ describe('when getting nfts', () => { nfts: [], }) - const response = await server.get('/v1/nfts').expect(STATUS_CODES.ok) + const response = await server + .get(`/v1/nfts?owner=${mockAddress}`) + .expect(STATUS_CODES.ok) - expect(mockNFTService.prototype.getNFTs).toHaveBeenCalledWith({}) + expect(mockNFTService.prototype.getNFTs).toHaveBeenCalledWith({ + owner: mockAddress, + }) expect(response.body).toEqual({ data: { @@ -244,7 +250,51 @@ describe('when getting a single nft', () => { }) it('should return an nft', async () => { - const nft: NFT = getMockNFT() + const nft: NFT = getMockNFT({ + identifier: '8166776806102523123120990578362437074920', + collection: 'decentraland', + contract: '0xf87e31492faf9a91b02ee0deaad50d51d56d5d4d', + token_standard: 'erc721', + name: 'metropolis', + description: null, + image_url: + 'https://api.decentraland.org/v1/parcels/23/-24/map.png?size=24&width=1024&height=1024', + metadata_url: + 'https://api.decentraland.org/v2/contracts/0xf87e31492faf9a91b02ee0deaad50d51d56d5d4d/tokens/8166776806102523123120990578362437074920', + opensea_url: + 'https://opensea.io/assets/ethereum/0xf87e31492faf9a91b02ee0deaad50d51d56d5d4d/8166776806102523123120990578362437074920', + updated_at: '2021-03-20T19:08:07.308381', + is_disabled: false, + is_nsfw: false, + animation_url: null, + is_suspicious: false, + creator: '0x52e4e32428c123a1f83da9839f139734a5a5b2b9', + traits: [ + { + trait_type: 'Type', + display_type: null, + max_value: null, + value: 'Land', + }, + { + trait_type: 'Distance to Road', + display_type: 'number', + max_value: null, + value: 0, + }, + { trait_type: 'X', display_type: 'number', max_value: null, value: 23 }, + { + trait_type: 'Y', + display_type: 'number', + max_value: null, + value: -24, + }, + ], + owners: [ + { address: '0x87956abc4078a0cc3b89b419928b857b8af826ed', quantity: 1 }, + ], + rarity: null, + }) mockNFTService.prototype.getNFT.mockResolvedValueOnce(nft) diff --git a/src/NFT/NFT.router.ts b/src/NFT/NFT.router.ts index 688e654e..caac436c 100644 --- a/src/NFT/NFT.router.ts +++ b/src/NFT/NFT.router.ts @@ -63,9 +63,12 @@ export class NFTRouter extends Router { let nfts: GetNFTsResponse // Get NFTs from service + if (!query.owner) { + throw new HTTPError('Owner is required', STATUS_CODES.badRequest) + } try { nfts = await this.nftService.getNFTs({ - owner: query.owner?.toString(), + owner: query.owner.toString(), first: query.first ? +query.first : undefined, skip: query.skip ? +query.skip : undefined, cursor: query.cursor?.toString(), diff --git a/src/NFT/NFT.service.spec.ts b/src/NFT/NFT.service.spec.ts index 77ce6d95..56089cce 100644 --- a/src/NFT/NFT.service.spec.ts +++ b/src/NFT/NFT.service.spec.ts @@ -1,7 +1,7 @@ import { env } from 'decentraland-commons' import fetch, { Response } from 'node-fetch' import { NFTService } from './NFT.service' -import { NFT } from './NFT.types' +import { NFT, OpenSeaV2AccountNFT, OpenSeaV2NFT } from './NFT.types' import { getMockNFT } from './utils' jest.mock('node-fetch') @@ -15,10 +15,14 @@ const mockApiKey = 'https://some-url.com/v1' let service: NFTService let requestInit: RequestInit -let mockExternalNFT: any +let mockExternalNFT: OpenSeaV2NFT +let mockExternalNFTByAccount: OpenSeaV2AccountNFT let mockMappedExternalNFT: NFT +let mockMappedExternalAccountNFT: NFT +let network: string beforeEach(() => { + network = 'ethereum' mockEnv.get.mockReturnValueOnce(mockUrl) mockEnv.get.mockReturnValueOnce(mockApiKey) @@ -32,163 +36,94 @@ beforeEach(() => { } mockExternalNFT = { - background_color: 'background_color', - asset_contract: { - address: 'address', - created_date: 'created_date', - name: 'name', - nft_version: 'nft_version', - schema_name: 'schema_name', - symbol: 'symbol', - total_supply: 'total_supply', - description: 'description', - external_link: 'external_link', - image_url: 'image_url', - }, - description: 'description', - external_link: 'external_link', - image_original_url: 'image_original_url', - image_preview_url: 'image_preview_url', - image_thumbnail_url: 'image_thumbnail_url', - image_url: 'image_url', - last_sale: { - event_type: 'event_type', - event_timestamp: 'event_timestamp', - total_price: 'total_price', - quantity: 'quantity', - payment_token: { - id: 100, - symbol: 'symbol', - address: 'address', - image_url: 'image_url', - name: 'name', - decimals: 18, - eth_price: 'eth_price', - usd_price: 'usd_price', - }, - transaction: { - id: 100, - from_account: { - address: 'address', - config: 'config', - profile_img_url: 'profile_img_url', - user: { - username: 'username', - }, - }, - to_account: { - address: 'address', - config: 'config', - profile_img_url: 'profile_img_url', - user: { - username: 'username', - }, - }, - transaction_hash: 'transaction_hash', - }, - }, - name: 'name', - orders: [ + identifier: '8166776806102523123120990578362437074920', + collection: 'decentraland', + contract: '0xf87e31492faf9a91b02ee0deaad50d51d56d5d4d', + token_standard: 'erc721', + name: 'metropolis', + description: null, + image_url: + 'https://api.decentraland.org/v1/parcels/23/-24/map.png?size=24&width=1024&height=1024', + metadata_url: + 'https://api.decentraland.org/v2/contracts/0xf87e31492faf9a91b02ee0deaad50d51d56d5d4d/tokens/8166776806102523123120990578362437074920', + opensea_url: + 'https://opensea.io/assets/ethereum/0xf87e31492faf9a91b02ee0deaad50d51d56d5d4d/8166776806102523123120990578362437074920', + updated_at: '2021-03-20T19:08:07.308381', + is_disabled: false, + is_nsfw: false, + animation_url: null, + is_suspicious: false, + creator: '0x52e4e32428c123a1f83da9839f139734a5a5b2b9', + traits: [ { - maker: { - address: 'address', - config: 'config', - profile_img_url: 'profile_img_url', - user: { - username: 'username', - }, - }, - current_price: 'current_price', - payment_token_contract: { - id: 100, - symbol: 'symbol', - address: 'address', - image_url: 'image_url', - name: 'name', - decimals: 18, - eth_price: 'eth_price', - usd_price: 'usd_price', - }, + trait_type: 'Type', + display_type: null, + max_value: null, + value: 'Land', }, - ], - owner: { - address: 'address', - config: 'config', - profile_img_url: 'profile_img_url', - user: { - username: 'username', - }, - }, - sell_orders: [ { - maker: { - address: 'address', - config: 'config', - profile_img_url: 'profile_img_url', - user: { - username: 'username', - }, - }, - current_price: 'current_price', - payment_token_contract: { - id: 100, - symbol: 'symbol', - address: 'address', - image_url: 'image_url', - name: 'name', - decimals: 18, - eth_price: 'eth_price', - usd_price: 'usd_price', - }, + trait_type: 'Distance to Road', + display_type: 'number', + max_value: null, + value: 0, }, + { trait_type: 'X', display_type: 'number', max_value: null, value: 23 }, + { trait_type: 'Y', display_type: 'number', max_value: null, value: -24 }, ], - token_id: 'token_id', - top_ownerships: [ - { - owner: { - address: 'address', - config: 'config', - profile_img_url: 'profile_img_url', - user: { - username: 'username', - }, - }, - quantity: 'quantity', - }, - ], - traits: [ - { - display_type: 'display_type', - trait_type: 'trait_type', - value: 'value', - }, + owners: [ + { address: '0x87956abc4078a0cc3b89b419928b857b8af826ed', quantity: 1 }, ], + rarity: null, + } + + mockExternalNFTByAccount = { + identifier: '209', + collection: 'decentraland-wearables', + contract: '0x30d3387ff3de2a21bef7032f82d00ff7739e403c', + token_standard: 'erc721', + name: 'Wing sneakers', + description: + 'No run, no swim, just fly. These have a handwritten signature from creators Chestnutbruz and Pablo Estornut. By Mana-fever 2020 © \n' + + '\n' + + 'DCL Wearable 38/100', + image_url: + 'https://peer.decentraland.org/content/contents/QmWXP9pDUM22FtbxjXs3faNntAoWtjYQi834B8ATBEb5NY', + metadata_url: + 'https://wearable-api.decentraland.org/v2/standards/erc721-metadata/collections/mf_sammichgamer/wearables/mf_wingsneakers/38', + opensea_url: + 'https://opensea.io/assets/ethereum/0x30d3387ff3de2a21bef7032f82d00ff7739e403c/209', + updated_at: '2022-01-06T21:19:12.837825', + is_disabled: false, + is_nsfw: false, } - mockMappedExternalNFT = getMockNFT() + mockMappedExternalNFT = getMockNFT(mockExternalNFT) + mockMappedExternalAccountNFT = getMockNFT(mockExternalNFTByAccount) jest.clearAllMocks() }) -describe('when getting a list of nfts', () => { +describe('when getting a list of nfts by account', () => { + let owner: string beforeEach(() => { + owner = '0xanAddress' mockFetch.mockResolvedValueOnce({ ok: true, json: () => Promise.resolve({ next: 'next', previous: 'previous', - assets: [mockExternalNFT], + nfts: [mockExternalNFTByAccount], }), } as Response) }) describe('when owner is provided', () => { it('should make a request with the owner query param', async () => { - await service.getNFTs({ owner: 'owner' }) + await service.getNFTs({ owner }) expect(mockFetch).toHaveBeenCalledWith( - `${mockUrl}/assets?owner=owner`, + `${mockUrl}/chain/${network}/account/${owner}/nfts`, requestInit ) }) @@ -196,10 +131,10 @@ describe('when getting a list of nfts', () => { describe('when first is provided', () => { it('should make a request with the limit query param', async () => { - await service.getNFTs({ first: 10 }) + await service.getNFTs({ owner, first: 10 }) expect(mockFetch).toHaveBeenCalledWith( - `${mockUrl}/assets?limit=10`, + `${mockUrl}/chain/${network}/account/${owner}/nfts?limit=10`, requestInit ) }) @@ -207,10 +142,10 @@ describe('when getting a list of nfts', () => { describe('when cursor is provided', () => { it('should make a request with the cursor query param', async () => { - await service.getNFTs({ cursor: 'cursor' }) + await service.getNFTs({ owner, cursor: 'cursor' }) expect(mockFetch).toHaveBeenCalledWith( - `${mockUrl}/assets?cursor=cursor`, + `${mockUrl}/chain/${network}/account/${owner}/nfts?cursor=cursor`, requestInit ) }) @@ -219,10 +154,10 @@ describe('when getting a list of nfts', () => { describe('when skip is provided', () => { describe('when first is provided', () => { it('should make a request with the limit and offset query param', async () => { - await service.getNFTs({ first: 10, skip: 20 }) + await service.getNFTs({ owner, first: 10, skip: 20 }) expect(mockFetch).toHaveBeenCalledWith( - `${mockUrl}/assets?limit=10&offset=20`, + `${mockUrl}/chain/${network}/account/${owner}/nfts?limit=10&offset=20`, requestInit ) }) @@ -230,9 +165,12 @@ describe('when getting a list of nfts', () => { describe('when first is not provided', () => { it('should make a request without the offset query param', async () => { - await service.getNFTs({ skip: 20 }) + await service.getNFTs({ owner, skip: 20 }) - expect(mockFetch).toHaveBeenCalledWith(`${mockUrl}/assets`, requestInit) + expect(mockFetch).toHaveBeenCalledWith( + `${mockUrl}/chain/${network}/account/${owner}/nfts`, + requestInit + ) }) }) }) @@ -240,14 +178,14 @@ describe('when getting a list of nfts', () => { describe('when all params are provided', () => { it('should make a request with all params added to the url', async () => { await service.getNFTs({ - owner: 'owner', + owner, first: 10, skip: 20, cursor: 'cursor', }) expect(mockFetch).toHaveBeenCalledWith( - `${mockUrl}/assets?owner=owner&limit=10&offset=20&cursor=cursor`, + `${mockUrl}/chain/${network}/account/${owner}/nfts?limit=10&offset=20&cursor=cursor`, requestInit ) }) @@ -258,7 +196,7 @@ describe('when getting a list of nfts', () => { mockFetch.mockReset() mockFetch.mockResolvedValueOnce({ ok: false } as Response) - await expect(service.getNFTs()).rejects.toEqual( + await expect(service.getNFTs({ owner })).rejects.toEqual( new Error('Failed to fetch NFTs') ) }) @@ -266,25 +204,17 @@ describe('when getting a list of nfts', () => { describe('when the response is ok', () => { it('should return cursor data and the list of nfts', async () => { - const data = await service.getNFTs() + const data = await service.getNFTs({ owner }) expect(data).toEqual({ next: 'next', - nfts: [mockMappedExternalNFT], + nfts: [mockMappedExternalAccountNFT], previous: 'previous', }) }) describe('and is an ens', () => { - let mockNFT: any - let mockMappedNFT: NFT beforeEach(() => { - mockNFT = { ...mockExternalNFT, owner: null, top_ownerships: undefined } - mockMappedNFT = { - ...mockMappedExternalNFT, - owner: null, - topOwnerships: null, - } mockFetch.mockReset() mockFetch.mockResolvedValueOnce({ ok: true, @@ -292,17 +222,17 @@ describe('when getting a list of nfts', () => { Promise.resolve({ next: 'next', previous: 'previous', - assets: [mockNFT], + nfts: [mockExternalNFTByAccount], }), } as Response) }) it('should return an nft without owner', async () => { - const data = await service.getNFTs() + const data = await service.getNFTs({ owner }) expect(data).toEqual({ next: 'next', - nfts: [mockMappedNFT], + nfts: [mockMappedExternalAccountNFT], previous: 'previous', }) }) @@ -311,10 +241,14 @@ describe('when getting a list of nfts', () => { }) describe('when getting an nft', () => { + let contractAddress: string + let tokenId: string beforeEach(() => { + contractAddress = '0xcontractAddress' + tokenId = 'tokenId' mockFetch.mockResolvedValueOnce({ ok: true, - json: () => Promise.resolve(mockExternalNFT), + json: () => Promise.resolve({ nft: mockExternalNFT }), } as Response) }) @@ -325,8 +259,8 @@ describe('when getting an nft', () => { await expect( service.getNFT({ - contractAddress: 'contractAddress', - tokenId: 'tokenId', + contractAddress, + tokenId, }) ).resolves.toBeUndefined() }) @@ -334,12 +268,12 @@ describe('when getting an nft', () => { it('should make a request with contractAddress and tokenId in the url', async () => { await service.getNFT({ - contractAddress: 'contractAddress', - tokenId: 'tokenId', + contractAddress, + tokenId, }) expect(mockFetch).toHaveBeenCalledWith( - `${mockUrl}/asset/contractAddress/tokenId/`, + `${mockUrl}/chain/${network}/contract/${contractAddress}/nfts/${tokenId}`, requestInit ) }) diff --git a/src/NFT/NFT.service.ts b/src/NFT/NFT.service.ts index 9c35f51c..fccb85a2 100644 --- a/src/NFT/NFT.service.ts +++ b/src/NFT/NFT.service.ts @@ -5,14 +5,8 @@ import { GetNFTsParams, GetNFTsResponse, NFT, - NFTAccount, - NFTContract, - NFTSale, - NFTOrder, - NFTOwnership, - NFTToken, - NFTTrait, - NFTTransaction, + OpenSeaV2AccountNFT, + OpenSeaV2NFT, } from './NFT.types' export class NFTService { @@ -49,14 +43,11 @@ export class NFTService { first, skip, cursor, - }: GetNFTsParams = {}): Promise { + network = 'ethereum', + }: GetNFTsParams): Promise { // Build query params for request const params: string[] = [] - if (owner) { - params.push(`owner=${owner}`) - } - if (first) { params.push(`limit=${first}`) } @@ -70,7 +61,7 @@ export class NFTService { } // Build url - let url = `${this.OPEN_SEA_URL}/assets` + let url = `${this.OPEN_SEA_URL}/chain/${network}/account/${owner}/nfts` if (params.length > 0) { url = `${url}?${params.join('&')}` @@ -90,10 +81,16 @@ export class NFTService { const json = await response.json() - const externalNFTs: any[] = json.assets + const externalNFTs: OpenSeaV2AccountNFT[] = json.nfts // Map OpenSea assets into our NFT object - const nfts = externalNFTs.map(this.mapExternalNFT) + const nfts = externalNFTs.map((ext) => ({ + tokenId: ext.identifier, + contract: { address: ext.contract, name: ext.collection }, // string, + name: ext.name, + imageUrl: ext.image_url, + description: ext.description, + })) return { next: json.next, @@ -112,9 +109,10 @@ export class NFTService { public async getNFT({ contractAddress, tokenId, + network = 'ethereum', }: GetNFTParams): Promise { // Build url - let url = `${this.OPEN_SEA_URL}/asset/${contractAddress}/${tokenId}/` + let url = `${this.OPEN_SEA_URL}/chain/${network}/contract/${contractAddress}/nfts/${tokenId}` // Fetch nft const response = await fetch(url, { @@ -128,97 +126,17 @@ export class NFTService { return undefined } - const externalNFT = await response.json() - - return this.mapExternalNFT(externalNFT) - } - - private mapExternalNFT(ext: any): NFT { - const mapAccount = (account: any): NFTAccount => ({ - user: account.user ? { username: account.user.username } : null, - profileImageUrl: account.profile_img_url, - address: account.address, - config: account.config, - }) - - const mapToken = (token: any): NFTToken => ({ - id: token.id, - symbol: token.symbol, - address: token.address, - imageUrl: token.image_url, - name: token.name, - decimals: token.decimals, - ethPrice: token.eth_price, - usdPrice: token.usd_price, - }) - - const mapContract = (contract: any): NFTContract => ({ - address: contract.address, - createdDate: contract.created_date, - name: contract.name, - nftVersion: contract.nft_version, - schemaName: contract.schema_name, - symbol: contract.symbol, - totalSupply: contract.total_supply, - description: contract.description, - externalLink: contract.external_link, - imageUrl: contract.image_url, - }) - - const mapTrait = (trait: any): NFTTrait => ({ - type: trait.trait_type, - value: trait.value, - displayType: trait.display_type, - }) - - const mapTransaction = (transaction: any): NFTTransaction => ({ - id: transaction.id, - fromAccount: mapAccount(transaction.from_account), - toAccount: mapAccount(transaction.to_account), - transactionHash: transaction.transaction_hash, - }) - - const mapSale = (sale: any): NFTSale => ({ - eventType: sale.event_type, - eventTimestamp: sale.event_timestamp, - totalPrice: sale.total_price, - quantity: sale.quantity, - paymentToken: mapToken(sale.payment_token), - transaction: mapTransaction(sale.transaction), - }) - - const mapOrder = (order: any): NFTOrder => ({ - maker: mapAccount(order.maker), - currentPrice: order.current_price, - paymentTokenContract: mapToken(order.payment_token_contract), - }) - - const mapOwnership = (ownership: any): NFTOwnership => ({ - owner: mapAccount(ownership.owner), - quantity: ownership.quantity, - }) + const externalNFT: { nft: OpenSeaV2NFT } = await response.json() return { - tokenId: ext.token_id, - backgroundColor: ext.background_color, - imageUrl: ext.image_url, - imagePreviewUrl: ext.image_preview_url, - imageThumbnailUrl: ext.image_thumbnail_url, - imageOriginalUrl: ext.image_original_url, - name: ext.name, - description: ext.description, - externalLink: ext.external_link, - owner: ext.owner ? mapAccount(ext.owner) : null, - contract: mapContract(ext.asset_contract), - traits: (ext.traits as any[]).map(mapTrait), - lastSale: ext.last_sale ? mapSale(ext.last_sale) : null, - sellOrders: ext.sell_orders - ? (ext.sell_orders as any[]).map(mapOrder) - : null, - orders: ext.orders ? (ext.orders as any[]).map(mapOrder) : null, - topOwnerships: ext.top_ownerships - ? (ext.top_ownerships as any[]).map(mapOwnership) - : null, + tokenId: externalNFT.nft.identifier, + contract: { + address: externalNFT.nft.contract, + name: externalNFT.nft.collection, + }, + name: externalNFT.nft.name, + imageUrl: externalNFT.nft.image_url, + description: externalNFT.nft.description || '', } } } diff --git a/src/NFT/NFT.types.ts b/src/NFT/NFT.types.ts index 97e03c10..f8b610c0 100644 --- a/src/NFT/NFT.types.ts +++ b/src/NFT/NFT.types.ts @@ -1,93 +1,19 @@ // NFT Entity export type NFT = { tokenId: string - backgroundColor: string | null imageUrl: string - imagePreviewUrl: string | null - imageThumbnailUrl: string | null - imageOriginalUrl: string | null - name: string | null - description: string | null - externalLink: string | null - owner: NFTAccount | null - contract: NFTContract - traits: NFTTrait[] - lastSale: NFTSale | null - sellOrders: NFTOrder[] | null - orders: NFTOrder[] | null - topOwnerships: NFTOwnership[] | null -} - -export type NFTAccount = { - user: { username: string } | null - profileImageUrl: string - address: string - config: string -} - -export type NFTContract = { - address: string - createdDate: string name: string - nftVersion: string | null - schemaName: string - symbol: string - totalSupply: string | null description: string - externalLink: string | null - imageUrl: string | null -} - -export type NFTTrait = { - type: string - value: string | number - displayType: string | null -} - -export type NFTSale = { - eventType: string - eventTimestamp: string - totalPrice: string - quantity: string - paymentToken: NFTToken - transaction: NFTTransaction -} - -export type NFTOrder = { - maker: NFTAccount - currentPrice: string - paymentTokenContract: NFTToken -} - -export type NFTOwnership = { - owner: NFTAccount - quantity: string -} - -export type NFTToken = { - id: number - symbol: string - address: string - imageUrl: string - name: string - decimals: number - ethPrice: string - usdPrice: string -} - -export type NFTTransaction = { - id: number - fromAccount: NFTAccount - toAccount: NFTAccount - transactionHash: string + contract: { address: string; name: string } } // Service types export type GetNFTsParams = { - owner?: string + owner: string first?: number skip?: number cursor?: string + network?: string } export type GetNFTsResponse = { @@ -99,4 +25,68 @@ export type GetNFTsResponse = { export type GetNFTParams = { contractAddress: string tokenId: string + network?: string +} + +// OpensSea API response types +export type OpenSeaV2GetNFTsByAccountResponse = { + nfts: OpenSeaV2AccountNFT[] +} + +export type OpenSeaV2AccountNFT = { + identifier: string + collection: string + contract: string + token_standard: string + name: string + description: string + image_url: string + metadata_url: string + opensea_url: string + updated_at: string + is_disabled: boolean + is_nsfw: boolean +} + +export type OpenSeaV2NFT = { + identifier: string + collection: string + contract: string + token_standard: string + name: string + description: string | null + image_url: string + metadata_url: string + opensea_url: string + updated_at: string + is_disabled: boolean + is_nsfw: boolean + animation_url: string | null + is_suspicious: boolean + creator: string + traits: { + trait_type: string + display_type: string | null + max_value: string | null + value: number | string + }[] + + owners: [ + { + address: string + quantity: number + } + ] + rarity: { + strategy_id: {} + strategy_version: string + rank: number + score: number + calculated_at: '' + max_rank: number + total_supply: number + ranking_features: { + unique_attribute_count: number + } + } | null } diff --git a/src/NFT/utils.ts b/src/NFT/utils.ts index 663d5a05..f29bd3e9 100644 --- a/src/NFT/utils.ts +++ b/src/NFT/utils.ts @@ -1,135 +1,12 @@ -import { NFT } from './NFT.types' +import { NFT, OpenSeaV2AccountNFT, OpenSeaV2NFT } from './NFT.types' -export const getMockNFT = (): NFT => ({ - backgroundColor: 'background_color', +export const getMockNFT = (mock: OpenSeaV2NFT | OpenSeaV2AccountNFT): NFT => ({ + tokenId: mock.identifier, + imageUrl: mock.image_url, + name: mock.name, contract: { - address: 'address', - createdDate: 'created_date', - name: 'name', - nftVersion: 'nft_version', - schemaName: 'schema_name', - symbol: 'symbol', - totalSupply: 'total_supply', - description: 'description', - externalLink: 'external_link', - imageUrl: 'image_url', + address: mock.contract, + name: mock.collection, }, - description: 'description', - externalLink: 'external_link', - imageOriginalUrl: 'image_original_url', - imagePreviewUrl: 'image_preview_url', - imageThumbnailUrl: 'image_thumbnail_url', - imageUrl: 'image_url', - lastSale: { - eventType: 'event_type', - eventTimestamp: 'event_timestamp', - totalPrice: 'total_price', - quantity: 'quantity', - paymentToken: { - id: 100, - symbol: 'symbol', - address: 'address', - imageUrl: 'image_url', - name: 'name', - decimals: 18, - ethPrice: 'eth_price', - usdPrice: 'usd_price', - }, - transaction: { - id: 100, - fromAccount: { - address: 'address', - config: 'config', - profileImageUrl: 'profile_img_url', - user: { - username: 'username', - }, - }, - toAccount: { - address: 'address', - config: 'config', - profileImageUrl: 'profile_img_url', - user: { - username: 'username', - }, - }, - transactionHash: 'transaction_hash', - }, - }, - name: 'name', - orders: [ - { - maker: { - address: 'address', - config: 'config', - profileImageUrl: 'profile_img_url', - user: { - username: 'username', - }, - }, - currentPrice: 'current_price', - paymentTokenContract: { - id: 100, - symbol: 'symbol', - address: 'address', - imageUrl: 'image_url', - name: 'name', - decimals: 18, - ethPrice: 'eth_price', - usdPrice: 'usd_price', - }, - }, - ], - owner: { - address: 'address', - config: 'config', - profileImageUrl: 'profile_img_url', - user: { - username: 'username', - }, - }, - sellOrders: [ - { - maker: { - address: 'address', - config: 'config', - profileImageUrl: 'profile_img_url', - user: { - username: 'username', - }, - }, - currentPrice: 'current_price', - paymentTokenContract: { - id: 100, - symbol: 'symbol', - address: 'address', - imageUrl: 'image_url', - name: 'name', - decimals: 18, - ethPrice: 'eth_price', - usdPrice: 'usd_price', - }, - }, - ], - tokenId: 'token_id', - topOwnerships: [ - { - owner: { - address: 'address', - config: 'config', - profileImageUrl: 'profile_img_url', - user: { - username: 'username', - }, - }, - quantity: 'quantity', - }, - ], - traits: [ - { - displayType: 'display_type', - type: 'trait_type', - value: 'value', - }, - ], + description: mock.description || '', })