From a98e29bb42da862b53a7f7333e270301f228389f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Roycourt?= Date: Wed, 18 Oct 2023 10:22:43 +0200 Subject: [PATCH 1/2] fix(web): add console log for nfts api --- apps/web/src/server/api/routers/nfts.ts | 93 +++++++++++++------------ 1 file changed, 50 insertions(+), 43 deletions(-) diff --git a/apps/web/src/server/api/routers/nfts.ts b/apps/web/src/server/api/routers/nfts.ts index 740625a7..951cc15e 100644 --- a/apps/web/src/server/api/routers/nfts.ts +++ b/apps/web/src/server/api/routers/nfts.ts @@ -73,54 +73,61 @@ export const nftsRouter = createTRPCRouter({ .query(async ({ input }) => { const { address } = input; - // TODO @YohanTz: Type env object - const ownedNftsResponse = await fetch( - `${ - process.env.NEXT_PUBLIC_ARK_API_DOMAIN ?? "" - }/v1/owners/${validateAndParseAddress(address)}/tokens`, - { - headers: { - "Content-Type": "application/json", - "X-API-KEY": "yW0akON1f55mOFwBPXPme4AFfLktbRiQ2GNdT1Mc", - }, - } - ); + try { + // TODO @YohanTz: Type env object + const ownedNftsResponse = await fetch( + `${ + process.env.NEXT_PUBLIC_ARK_API_DOMAIN ?? "" + }/v1/owners/${validateAndParseAddress(address)}/tokens`, + { + headers: { + "Content-Type": "application/json", + "X-API-KEY": "yW0akON1f55mOFwBPXPme4AFfLktbRiQ2GNdT1Mc", + }, + } + ); - if (ownedNftsResponse.status !== 200) { - return { byCollection: {}, raw: [] }; - } + console.log("Response status: ", ownedNftsResponse.status); - const ownedNfts = (await ownedNftsResponse.json()) as { - result: Array<{ - contract_address: string; - token_id: string; - }>; - }; - - const rawNfts = ownedNfts.result.map((ownedNft) => { - return { - collectionContractAddress: ownedNft.contract_address, - collectionName: "No metadata", - id: `${ownedNft.contract_address}-${ownedNft.token_id}`, - image: undefined, - title: `#${ownedNft.token_id}`, - tokenId: ownedNft.token_id, - }; - }); + if (ownedNftsResponse.status !== 200) { + return { byCollection: {}, raw: [] }; + } - const nftsByCollection = rawNfts.reduce>>( - (acc, nft) => { - if (acc[nft.collectionName] === undefined) { - acc[nft.collectionName] = []; - } + const ownedNfts = (await ownedNftsResponse.json()) as { + result: Array<{ + contract_address: string; + token_id: string; + }>; + }; - acc[nft.collectionName]?.push(nft); - return acc; - }, - {} - ); + const rawNfts = ownedNfts.result.map((ownedNft) => { + return { + collectionContractAddress: ownedNft.contract_address, + collectionName: "No metadata", + id: `${ownedNft.contract_address}-${ownedNft.token_id}`, + image: undefined, + title: `#${ownedNft.token_id}`, + tokenId: ownedNft.token_id, + }; + }); + + const nftsByCollection = rawNfts.reduce>>( + (acc, nft) => { + if (acc[nft.collectionName] === undefined) { + acc[nft.collectionName] = []; + } + + acc[nft.collectionName]?.push(nft); + return acc; + }, + {} + ); - return { byCollection: nftsByCollection, raw: rawNfts }; + return { byCollection: nftsByCollection, raw: rawNfts }; + } catch (err) { + console.error("getL2NftsByCollection error: ", err); + return { byCollection: {}, raw: [] }; + } }), // getAll: publicProcedure.query(({ ctx }) => { // return ctx.prisma.example.findMany(); From 0c1ba1ac6d0ba4a406c33c36728fc750ff0e7730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Roycourt?= Date: Wed, 18 Oct 2023 10:30:17 +0200 Subject: [PATCH 2/2] fix(web): add console log for nfts api --- apps/web/src/server/api/routers/nfts.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/apps/web/src/server/api/routers/nfts.ts b/apps/web/src/server/api/routers/nfts.ts index 951cc15e..9add44f0 100644 --- a/apps/web/src/server/api/routers/nfts.ts +++ b/apps/web/src/server/api/routers/nfts.ts @@ -75,17 +75,19 @@ export const nftsRouter = createTRPCRouter({ try { // TODO @YohanTz: Type env object - const ownedNftsResponse = await fetch( - `${ - process.env.NEXT_PUBLIC_ARK_API_DOMAIN ?? "" - }/v1/owners/${validateAndParseAddress(address)}/tokens`, - { - headers: { - "Content-Type": "application/json", - "X-API-KEY": "yW0akON1f55mOFwBPXPme4AFfLktbRiQ2GNdT1Mc", - }, - } - ); + + const url = `${ + process.env.NEXT_PUBLIC_ARK_API_DOMAIN ?? "" + }/v1/owners/${validateAndParseAddress(address)}/tokens`; + + console.log("Fetching api: ", url); + + const ownedNftsResponse = await fetch(url, { + headers: { + "Content-Type": "application/json", + "X-API-KEY": "yW0akON1f55mOFwBPXPme4AFfLktbRiQ2GNdT1Mc", + }, + }); console.log("Response status: ", ownedNftsResponse.status);