diff --git a/apps/web/src/server/api/helpers/l2nfts.ts b/apps/web/src/server/api/helpers/l2nfts.ts index d7a2fcfd..db15803b 100644 --- a/apps/web/src/server/api/helpers/l2nfts.ts +++ b/apps/web/src/server/api/helpers/l2nfts.ts @@ -8,29 +8,41 @@ const requestsHeader = { }; const nftApiUrl = process.env.NEXT_PUBLIC_ARK_API_DOMAIN ?? ""; -type ArkCollectionsApiResponse = { - result: Array<{ - contract_address: string; - contract_type: string; - image?: string; - name: string; - symbol: string; - tokens_count: number; +type PortfolioApiResponse = { + data: Array<{ + best_offer: string | null; + collection_address: string; + collection_name: string; + currency_address: string; + floor: string; + list_price: string; + metadata: { + animation_key: string | null; + animation_mime_type: string | null; + animation_url: string | null; + attributes: string | null; + background_color: string | null; + description: string | null; + external_url: string | null; + image: string | null; + image_data: string | null; + image_key: string | null; + image_mime_type: string | null; + name: string | null; + youtube_url: string | null; + }; }>; - total_count: number; + token_count: number; }; export async function getL2ContractsForOwner(address: string) { - const url = `${nftApiUrl}/v1/owners/${validateAndParseAddress( - address - )}/contracts`; + const url = `${nftApiUrl}/portfolio/${validateAndParseAddress(address)}`; const contractsResponse = await fetch(url, { headers: requestsHeader, }); - const contracts = - (await contractsResponse.json()) as ArkCollectionsApiResponse; + const apiResponse = (await contractsResponse.json()) as PortfolioApiResponse; - return contracts; + return apiResponse; } type ArkBatchNftsApiResponse = { @@ -152,11 +164,13 @@ export async function getL2WhitelistedCollections() { } } -export function getMediaObjectFromUrl(image: string | undefined): NftMedia { +export function getMediaObjectFromUrl( + image: string | undefined | null +): NftMedia { if (image === undefined) { return { format: "image", src: undefined }; } - const mediaSrc = image.replace("ipfs://", process.env.IPFS_GATEWAY ?? ""); + const mediaSrc = image?.replace("ipfs://", process.env.IPFS_GATEWAY ?? ""); const mediaFormat = mediaSrc?.split(".").pop() === "mp4" ? "video" : "image"; return { format: mediaFormat, src: mediaSrc }; diff --git a/apps/web/src/server/api/routers/l2Nfts.ts b/apps/web/src/server/api/routers/l2Nfts.ts index 1fb77cee..143f1c1e 100644 --- a/apps/web/src/server/api/routers/l2Nfts.ts +++ b/apps/web/src/server/api/routers/l2Nfts.ts @@ -36,35 +36,30 @@ export const l2NftsRouter = createTRPCRouter({ } = input; try { - const contractsForOwner = await getL2ContractsForOwner(address); + const response = await getL2ContractsForOwner(address); const whitelistedCollections = await getL2WhitelistedCollections(); - const collections: Array = contractsForOwner.result.map( - (contract) => { - const media = getMediaObjectFromUrl(contract.image); - const isBridgeable = - whitelistedCollections === undefined || - whitelistedCollections.some( - (whitelistedCollection) => - validateAndParseAddress( - whitelistedCollection - ).toLowerCase() === - validateAndParseAddress( - contract.contract_address - ).toLowerCase() - ); + const collections: Array = response.data.map((contract) => { + const media = getMediaObjectFromUrl(contract.metadata.image); + const isBridgeable = + whitelistedCollections === undefined || + whitelistedCollections.some( + (whitelistedCollection) => + validateAndParseAddress(whitelistedCollection).toLowerCase() === + validateAndParseAddress( + contract.collection_address + ).toLowerCase() + ); - return { - contractAddress: contract.contract_address, - isBridgeable, - media, - name: contract.name ?? contract.symbol ?? "Unknown", - totalBalance: contract.tokens_count, - }; - } - ); + return { + contractAddress: contract.collection_address, + isBridgeable, + media, + name: contract.collection_name ?? "Unknown", + }; + }); - return { collections, totalCount: contractsForOwner.total_count }; + return { collections, totalCount: response.token_count }; } catch (error) { console.error("getL2NftCollectionsByWallet error: ", error); return { collections: [], totalCount: 0 }; diff --git a/apps/web/src/server/api/types.ts b/apps/web/src/server/api/types.ts index db0021f9..28e552c9 100644 --- a/apps/web/src/server/api/types.ts +++ b/apps/web/src/server/api/types.ts @@ -12,5 +12,4 @@ export type Collection = { isBridgeable: boolean; media: NftMedia; name: string; - totalBalance: number; };