Skip to content

Commit

Permalink
kind of functioning code
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobHomanics committed Jan 18, 2024
1 parent 652c23b commit 498917a
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 52 deletions.
3 changes: 1 addition & 2 deletions packages/foundry/script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ contract DeployScript is ScaffoldETHDeploy {

ReputationTokensStandalone instance = new ReputationTokensStandalone(
0x62286D694F89a1B12c0214bfcD567bb6c2951491,
admins,
baseURI
admins
);

instance.grantRole(
Expand Down
78 changes: 41 additions & 37 deletions packages/nextjs/components/example-ui/ContractData.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// import { useERC1155Information } from "./tokens/TokenInteractions";
import { useERC1155Information } from "./tokens/TokenInteractions";
// import { ImageProperties } from "./tokens/token-card/ImageCard";
// import { DefaultTokenGroupCard } from "./tokens/token-group-card/DefaultTokenGroupCard";
// import {
Expand All @@ -10,10 +10,11 @@
// prettifyLoadingProps,
// } from "./tokens/token-group-card/TokenGroupCardConfig";
// import { useEffect, useState } from "react";
import { useEffect, useState } from "react";
// import { useEffect, useState } from "react";
import { useAccount } from "wagmi";

// import { useScaffoldContract, useScaffoldContractRead } from "~~/hooks/scaffold-eth";
// import { useScaffoldContract, useScaffoldContractRead } from "~~/hooks/scaffold-eth";
import { useScaffoldContract, useScaffoldContractRead } from "~~/hooks/scaffold-eth";

export const ContractData = () => {
const { address } = useAccount();
Expand Down Expand Up @@ -76,51 +77,54 @@ export const ContractData = () => {
// getUris();
// }, [address, repTokensInstance]);

// const { token0, token1 } = useERC1155Information(address);
//const { token0, token1 } =
useERC1155Information(address);

const { data: repTokensInstance } = useScaffoldContract({ contractName: "ReputationTokensStandalone" });
// const { data: repTokensInstance } = useScaffoldContract({ contractName: "ReputationTokensStandalone" });

const { data: numOfTokens } = useScaffoldContractRead({
contractName: "ReputationTokensStandalone",
functionName: "getNumOfTokenTypes",
});
// const { data: numOfTokens } = useScaffoldContractRead({
// contractName: "ReputationTokensStandalone",
// functionName: "getNumOfTokenTypes",
// });

const addressArr = [];
const tokenIdsArr: bigint[] = [];
// const addressArr = [];
// const tokenIdsArr: bigint[] = [];

for (let i = 0; i < numOfTokens!; i++) {
addressArr.push(address!);
tokenIdsArr.push(BigInt(i));
}
// for (let i = 0; i < numOfTokens!; i++) {
// addressArr.push(address!);
// tokenIdsArr.push(BigInt(i));
// }

const { data: balanceOfBatch } = useScaffoldContractRead({
contractName: "ReputationTokensStandalone",
functionName: "balanceOfBatch",
args: [addressArr, tokenIdsArr],
});
console.log(balanceOfBatch);
// const { data: balanceOfBatch } = useScaffoldContractRead({
// contractName: "ReputationTokensStandalone",
// functionName: "balanceOfBatch",
// args: [addressArr, tokenIdsArr],
// });
// console.log(balanceOfBatch);

const [uris, setUris] = useState<string[]>([]);
// const [uris, setUris] = useState<string[]>([]);

useEffect(() => {
async function getUris() {
if (!address) return;
if (!repTokensInstance) return;
// useEffect(() => {
// async function getUris() {
// if (!address || !repTokensInstance || tokenIdsArr.length === 0) return;

const arr = [];
for (let i = 0; i < tokenIdsArr.length; i++) {
const result = await repTokensInstance.read.uri([tokenIdsArr[i]]);
if (result != undefined) arr.push(result);
}
// const arr = [];
// for (let i = 0; i < tokenIdsArr.length; i++) {
// const result = await repTokensInstance.read.uri([tokenIdsArr[i]]);
// if (result !== undefined) arr.push(result);
// }

console.log(arr);
setUris([...arr]);
}
// console.log(arr);
// setUris([...arr]);
// }

getUris();
}, [address, repTokensInstance]);
// // Run the effect only once when the component mounts
// if (uris.length === 0) {
// getUris();
// }
// }, [address, repTokensInstance, tokenIdsArr]); // Empty dependency array to run the effect only once

console.log(uris);
// console.log(uris);

// token0.image = token0.image?.replace("ipfs://", "https://ipfs.io/ipfs/");
// token1.image = token1.image?.replace("ipfs://", "https://ipfs.io/ipfs/");
Expand Down
37 changes: 25 additions & 12 deletions packages/nextjs/components/example-ui/tokens/TokenInteractions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,33 +69,46 @@ export const useERC1155Information = (address?: string) => {

useEffect(() => {
async function getUris() {
if (!address) return;
if (!repTokensInstance) return;
if (!address || !repTokensInstance || tokenIdsArr.length === 0) return;

const arr = [];
for (let i = 0; i < tokenIdsArr.length; i++) {
const result = await repTokensInstance.read.uri([tokenIdsArr[i]]);
if (result != undefined) arr.push(result);
if (result !== undefined) arr.push(result);
}

console.log(arr);
setUris([...arr]);
}

getUris();
}, [address, repTokensInstance]);
// Run the effect only once when the component mounts
if (uris.length === 0) {
getUris();
}
}, [address, repTokensInstance, tokenIdsArr]); // Empty dependency array to run the effect only once

console.log(uris);

// useEffect(()=> {
// async function getJson() {
// const response = await fetch("http://example.com/movies.json");
// const movies = await response.json();
// }
const [responses, setResponses] = useState<Nft[]>([]);

useEffect(() => {
async function getJson() {
if (uris.length === 0) return;

const arr = [];
for (let i = 0; i < uris.length; i++) {
const response = await fetch(uris[i].replace("ipfs://", "https://ipfs.io/ipfs/"));
const responseJson = await response.json();
arr.push(responseJson);
}

setResponses([...arr]);
}

// getJson();
if (responses.length === 0) getJson();
}, [uris]);

// }, [])
console.log(responses);

const { data: json0 /* error: error0 */ } = useFetch<Nft>(uri0?.replace("ipfs://", "https://ipfs.io/ipfs/"));
const { data: json1 /* error: error1 */ } = useFetch<Nft>(uri1?.replace("ipfs://", "https://ipfs.io/ipfs/"));
Expand Down

0 comments on commit 498917a

Please sign in to comment.