Skip to content

Commit 503b977

Browse files
authored
Merge pull request dabit3#1 from vytjan/v0
lazy load and fixed web3 connect.
2 parents 1d24e57 + bb6f6a1 commit 503b977

File tree

10 files changed

+4733
-11069
lines changed

10 files changed

+4733
-11069
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ yarn-error.log*
3030
.env.development.local
3131
.env.test.local
3232
.env.production.local
33+
.env
3334

3435
# vercel
3536
.vercel

lib/api.js

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,20 @@
1-
import DaturiansNFT from '../artifacts/Daturians.json';
2-
import { ethers } from 'ethers';
31
import axios from 'axios';
4-
import cookie from "cookie";
5-
import {
6-
nftcontractaddress
7-
} from '../config'
82

9-
export const getMetadataById = async (id) => {
3+
export const getMetadataById = async (id, contract) => {
104

11-
const ipfs_gateway = "https://daturians.mypinata.cloud/ipfs/"
12-
const provider = new ethers.providers.JsonRpcProvider("https://polygon-rpc.com/")
13-
// const provider = new ethers.providers.JsonRpcProvider(node_url)
14-
const contract = new ethers.Contract(nftcontractaddress, DaturiansNFT.abi, provider)
155
const tokenUri = await contract.tokenURI(id)
6+
const ipfs_gateway = "https://daturians.mypinata.cloud/ipfs/"
167

17-
// console.log(tokenUri)
18-
198
let newUri = tokenUri.replace("ipfs://", ipfs_gateway)
209
const meta = await axios.get(newUri)
21-
// let price = ethers.utils.formatUnits(i.price.toString(), 'ether')
22-
// console.log(meta)
2310
let imgUri = meta.data.image.replace("ipfs://", ipfs_gateway)
24-
// const raw = await axios.get(imgUri, {
25-
// responseType: "arraybuffer",
26-
// })
27-
// // create a base64 encoded string
28-
// let base64 = Buffer.from(raw.data, "binary").toString("base64");
29-
30-
// // create image src
31-
// let img = 'data:${raw.headers["content-type"]};base64,${base64}';
32-
// console.log(img)
3311
let item = {
34-
// price,
3512
tokenId: id,
36-
// seller: i.seller,
37-
// owner: i.owner,
3813
image: imgUri,
3914
name: meta.data.name,
4015
description: meta.data.description,
4116
data: meta.data
4217
}
43-
// console.log(item)
4418
return item
4519
};
4620

47-
export const parseCookies = (req) => {
48-
return cookie.parse(req ? req.headers.cookie || "" : document.cookie)
49-
};

0 commit comments

Comments
 (0)