Skip to content

Commit

Permalink
add hedera collection
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyAdoniev committed Oct 24, 2023
1 parent cbda92e commit 71cf82c
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 1 deletion.
84 changes: 84 additions & 0 deletions src/factory/hedera.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import axios, { AxiosRequestConfig, AxiosResponse } from "axios";

import { NFT, setupURI } from ".";

import { proxy } from "..";

import { Default } from "./index";
import { extractType } from "..";

const cheerio = require("cherio");

export const hederaParser = async (
collectionIdent: string,
nft: any,
account: string,
whitelisted: boolean,
chainId?: string
) => {
let parsed;
switch (true) {
case /(0x000000000000000000000000000000000008f387)/.test(
collectionIdent
):
parsed = await BRONZE(nft, account, whitelisted);
break;

default:
parsed = await Default(nft, account, whitelisted);
break;
}

return parsed;
};

const BRONZE = async (nft: any, account: string, whitelisted: boolean) => {
const {
native,
native: { contract, tokenId, chainId },
collectionIdent,
uri,
} = nft;

try {
const response = (await axios(`${proxy}${setupURI(uri)}`))?.data;

if (!response) throw new Error("Could not fetch hedera nft::BRONZE");

let img = response.image?.description
? (await axios(`${proxy}${setupURI(response.image.description)}`))
?.data
: "";

if (img) {
const $ = cheerio.load(img);
const link = $(
"#content table tbody tr:first-child td:nth-child(2) > a"
).attr("href");
img = "https://cloudflare-ipfs.com" + link;
}

const nft: NFT = {
native,
chainId,
tokenId,
owner: account,
uri,
contract,
collectionIdent,
metaData: {
name: response.name,
description: response.description?.description,
image: img,
imageFormat: extractType(img),
whitelisted: true,
},
};

return nft;
} catch (error) {
console.error(error);

return nft;
}
};
1 change: 1 addition & 0 deletions src/factory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export const Default = async (
response = await moralis(contract, tokenId, chain);
response = { data: response };
break;

default:
response = undefined;
break;
Expand Down
9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { tronParser } from "./factory/tron";
import { tonParser } from "./factory/ton";
import { abeyParser } from "./factory/abey";
import { nearParser } from "./factory/near";
import { hederaParser } from "./factory/hedera";

export const videoFormats = [
"MP4",
Expand Down Expand Up @@ -290,6 +291,14 @@ export const nftGeneralParser = async (
whitelisted
);
break;
case "29":
parsed = await hederaParser(
collectionIdent,
nft,
account,
whitelisted
);
break;
default:
return await evmParser(collectionIdent, nft, account, whitelisted);
}
Expand Down
1 change: 0 additions & 1 deletion tools/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { setupURI } from "../src/factory";
import { proxy } from "../src";

import { fromBuffer } from "file-type";
import { rejects } from "assert";

export const getWrappedNft = async (
nft: any,
Expand Down

0 comments on commit 71cf82c

Please sign in to comment.