From 6572236638737a714daf6a670924e91faf9cfc99 Mon Sep 17 00:00:00 2001 From: D Date: Fri, 23 Aug 2024 15:36:35 +0500 Subject: [PATCH] chore(tezos) fix nft parser --- src/factory/index.ts | 5 ++++- src/factory/tezos.ts | 14 +++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/factory/index.ts b/src/factory/index.ts index 684ca32c..5fd5d849 100644 --- a/src/factory/index.ts +++ b/src/factory/index.ts @@ -52,7 +52,7 @@ export const injectMoralis = function (M: any) { console.log("Moralis injected ", Moralis.start); }; -export const setupURI = (uri: string): string => { +export const setupURI = (uri: string, other: boolean = false): string => { if (uri) { if (uri.includes(".json")) { uri = uri.replace(/(?!\.json)\d+$/gm, ""); @@ -60,6 +60,9 @@ export const setupURI = (uri: string): string => { if (uri.includes("https://ipfs.io") || uri.includes("moralis")) { return uri; } else if (/^ipfs:\/\//.test(uri)) { + if (other) { + return uri.replace(/ipfs:\/\/(?:ipfs)?/, "https://xpnetwork.infura-ipfs.io/ipfs/"); + } return uri.replace(/ipfs:\/\/(?:ipfs)?/, "https://ipfs.io/ipfs/"); // "https://ipfs.io/ipfs/" + uri.split("://")[1]; } else if (/ipfs\.infura\.io/.test(uri)) { return uri.replace(/ipfs\.infura\.io/, "ipfs.io"); diff --git a/src/factory/tezos.ts b/src/factory/tezos.ts index eec22b44..9228f17a 100644 --- a/src/factory/tezos.ts +++ b/src/factory/tezos.ts @@ -70,7 +70,19 @@ export const checkEmptyFromTezos = async (data: any) => { }; const getMetadata = async (nft: any, account = "", whitelisted = true) => { - const res = await axios(proxy + setupURI(nft.uri)); + + console.log("URI 1", proxy + setupURI(nft.uri)); + console.log("URI 2", proxy + setupURI(nft.uri, true)); + + let res; + + try { + res = await axios(proxy + setupURI(nft.uri)); + } + catch (ex) { + res = await axios(proxy + setupURI(nft.uri, true)); + } + const { data } = res; const parsed: NFT = {