Skip to content

Commit

Permalink
chore(tezos) fix nft parser
Browse files Browse the repository at this point in the history
  • Loading branch information
D4mph1r committed Aug 23, 2024
1 parent 59f223e commit 6572236
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/factory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,17 @@ 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, "");
}
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");
Expand Down
14 changes: 13 additions & 1 deletion src/factory/tezos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 6572236

Please sign in to comment.