Skip to content

Commit

Permalink
formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobHomanics committed Feb 25, 2024
1 parent 0ef876f commit 7310c2e
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 105 deletions.
3 changes: 1 addition & 2 deletions packages/nextjs/app/blockexplorer/address/[address]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import fs from "fs";
import path from "path";
import { foundry } from "viem/chains";
Expand Down Expand Up @@ -83,4 +82,4 @@ const AddressPage = async ({ params }: PageProps) => {
return <AddressComponent address={address} contractData={contractData} />;
};

export default AddressPage;
export default AddressPage;
71 changes: 28 additions & 43 deletions packages/nextjs/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,54 @@

// import Link from "next/link";
import type { NextPage } from "next";
// import { BugAntIcon, MagnifyingGlassIcon } from "@heroicons/react/24/outline";
import { NftCard } from "~~/components/nft-card/nftCard";
import { useScaffoldContract, useScaffoldContractRead } from "~~/hooks/scaffold-eth";
// import { useAccount } from "wagmi";
// import { FormEvent } from 'react'
import { useFetches, useGetAllMetadatas } from "~~/components/nft-card/Hooks";
// import { BugAntIcon, MagnifyingGlassIcon } from "@heroicons/react/24/outline";
import { NftCard } from "~~/components/nft-card/nftCard";
import { useScaffoldContract, useScaffoldContractRead } from "~~/hooks/scaffold-eth";

// import rainey from "~~/components/assets/rainey.jpg"
// import houses from "~~/components/assets/houses.jpeg"
// import brick from "~~/components/assets/brick.jpeg"

const Home: NextPage = () => {
// const account = useAccount();


// const { data: adminRole } = useScaffoldContractRead({contractName:"RaineyStreetPartnershipNft", functionName: "DEFAULT_ADMIN_ROLE"});
// const { data: hasAdminRole } = useScaffoldContractRead({contractName:"RaineyStreetPartnershipNft", functionName: "hasRole", args: [adminRole, account.address]});
// const { writeAsync: mint } = useScaffoldContractWrite({contractName: "RaineyStreetPartnershipNft", functionName: "mint", args: [""]});
const { data: partnershipNftContract } = useScaffoldContract({contractName: "RaineyStreetPartnershipNft"});
const { data: mintCount } = useScaffoldContractRead({contractName:"RaineyStreetPartnershipNft", functionName:"getMintCount"});
const { data: partnershipNftContract } = useScaffoldContract({ contractName: "RaineyStreetPartnershipNft" });
const { data: mintCount } = useScaffoldContractRead({
contractName: "RaineyStreetPartnershipNft",
functionName: "getMintCount",
});
const { data: tokenURIs } = useGetAllMetadatas(partnershipNftContract, mintCount || BigInt(0));

for (let i = 0; i < tokenURIs.length; i++) {
if (tokenURIs[i])
tokenURIs[i] = tokenURIs[i].replace("ipfs://", "https://ipfs.io/ipfs/");
if (tokenURIs[i]) tokenURIs[i] = tokenURIs[i].replace("ipfs://", "https://ipfs.io/ipfs/");
}

const { data: metadatas } = useFetches(tokenURIs);

const nfts = metadatas!.map((metadata, index) => (
<NftCard key={index} nft={metadata}/>
));
const nfts = metadatas!.map((metadata, index) => <NftCard key={index} nft={metadata} />);

const { data: sixthPartnershipNftContract } = useScaffoldContract({contractName: "SixthStreetPartnershipNft"});
const { data: sixthMintCount } = useScaffoldContractRead({contractName:"SixthStreetPartnershipNft", functionName:"getMintCount"});
const { data: sixthPartnershipNftContract } = useScaffoldContract({ contractName: "SixthStreetPartnershipNft" });
const { data: sixthMintCount } = useScaffoldContractRead({
contractName: "SixthStreetPartnershipNft",
functionName: "getMintCount",
});
const { data: sixthTokenURIs } = useGetAllMetadatas(sixthPartnershipNftContract, sixthMintCount || BigInt(0));

console.log(sixthTokenURIs);

for (let i = 0; i < sixthTokenURIs.length; i++) {
if (sixthTokenURIs[i])
sixthTokenURIs[i] = sixthTokenURIs[i].replace("ipfs://", "https://ipfs.io/ipfs/");
if (sixthTokenURIs[i]) sixthTokenURIs[i] = sixthTokenURIs[i].replace("ipfs://", "https://ipfs.io/ipfs/");
}

const { data: sixthMetadatas } = useFetches(sixthTokenURIs);

const sixthNfts = sixthMetadatas!.map((metadata, index) => (
<NftCard key={index} nft={metadata}/>
));







const sixthNfts = sixthMetadatas!.map((metadata, index) => <NftCard key={index} nft={metadata} />);

// async function onFormSubmit(event: any) {
// event.preventDefault()
Expand All @@ -77,28 +70,20 @@ const Home: NextPage = () => {

return (
<>
{/* <div className="flex flex-col items-center pt-10">
{/* <div className="flex flex-col items-center pt-10">
{
adminOutput
}
</div> */}

<div className={`bg-[url('../components/assets/houses.jpeg')] m-20 flex flex-col justify-center items-center`}>
<p className="text-4xl m-2 text-center bg-slate-800 p-1 max-w-xs">Rainey Street</p>
<div className="grid grid-cols-3 content-center">
{
nfts
}
</div>
</div>
<div className={`bg-[url('../components/assets/brick.jpeg')] m-20 flex flex-col justify-center items-center`}>
<p className="text-4xl m-2 text-center bg-slate-800 p-1 max-w-xs">6th Street</p>
<div className="grid grid-cols-3 content-center">
{
sixthNfts
}
</div>
</div>
<div className={`bg-[url('../components/assets/houses.jpeg')] m-20 flex flex-col justify-center items-center`}>
<p className="text-4xl m-2 text-center bg-slate-800 p-1 max-w-xs">Rainey Street</p>
<div className="grid grid-cols-3 content-center">{nfts}</div>
</div>
<div className={`bg-[url('../components/assets/brick.jpeg')] m-20 flex flex-col justify-center items-center`}>
<p className="text-4xl m-2 text-center bg-slate-800 p-1 max-w-xs">6th Street</p>
<div className="grid grid-cols-3 content-center">{sixthNfts}</div>
</div>
</>
);
};
Expand Down
69 changes: 34 additions & 35 deletions packages/nextjs/components/nft-card/Hooks.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,45 @@
import { useEffect, useState } from "react";

export function useGetAllMetadatas(contract: any, mintCount: bigint) {
const [data, setData] = useState<any[]>([]);
const [data, setData] = useState<any[]>([]);

useEffect(()=> {
async function get() {
const arr = [];
for (let i = 0; i < mintCount; i++) {
let result = await contract?.read.tokenURI([i]);
arr.push(result);
}
useEffect(() => {
async function get() {
const arr = [];
for (let i = 0; i < mintCount; i++) {
let result = await contract?.read.tokenURI([i]);
arr.push(result);
}

setData([...arr]);
}
get();
}, [contract?.address, mintCount])
setData([...arr]);
}
get();
}, [contract?.address, mintCount]);

return { data }
return { data };
}

export function useFetches(uris: string[]) {
const [data, setData] = useState<any[]>([]);

useEffect(() => {
async function get() {
const arr = [];
for (let i = 0; i < uris.length; i++) {
try {
const response = await fetch(uris[i]);
const responseJson = await response.json();
arr.push(responseJson);
}
catch (e) {
console.log('Could not fetch URI');
arr.push({});
}
const [data, setData] = useState<any[]>([]);

useEffect(() => {
async function get() {
const arr = [];
for (let i = 0; i < uris.length; i++) {
try {
const response = await fetch(uris[i]);
const responseJson = await response.json();
arr.push(responseJson);
} catch (e) {
console.log("Could not fetch URI");
arr.push({});
}

setData([...arr]);
}
get();
}, [uris]);

return { data };
}

setData([...arr]);
}
get();
}, [uris]);

return { data };
}
48 changes: 23 additions & 25 deletions packages/nextjs/components/nft-card/nftCard.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
interface Nft {
name?: string;
description?: string;
image?: string;
name?: string;
description?: string;
image?: string;
}

interface NftCardProps {
nft: Nft;
nft: Nft;
}

export function NftCard (props: NftCardProps) {
export function NftCard(props: NftCardProps) {
if (props.nft && props.nft.image) {
props.nft.image = props.nft.image.replace("ipfs://", "https://ipfs.io/ipfs/");
}

if (props.nft && props.nft.image){
props.nft.image = props.nft.image.replace("ipfs://", "https://ipfs.io/ipfs/");
}
//flex flex-col items-center justify-center text-center bg-black max-w-xs rounded-lg bg-sky-900 m-1
return (
<div className="flex flex-col items-center justify-center text-center bg-black rounded-lg bg-sky-900 m-5">
<div className="m-4">
<p className="m-0 font-bold">Name</p>
<p className="m-0 text-xl">{props.nft.name}</p>
</div>

//flex flex-col items-center justify-center text-center bg-black max-w-xs rounded-lg bg-sky-900 m-1
return (
<div className="flex flex-col items-center justify-center text-center bg-black rounded-lg bg-sky-900 m-5">

<div className="m-4">
<p className="m-0 font-bold">Name</p>
<p className="m-0 text-xl">{ props.nft.name}</p>
</div>

<img className="rounded-lg" src={props.nft.image} width={128} height={128}/>
<div className="m-4">
<p className="m-0 font-bold text-size-xl">Description</p>
<p className="m-0 text-xs"> { props.nft.description}</p>
</div>
</div>
)
}
<img className="rounded-lg" src={props.nft.image} width={128} height={128} />
<div className="m-4">
<p className="m-0 font-bold text-size-xl">Description</p>
<p className="m-0 text-xs"> {props.nft.description}</p>
</div>
</div>
);
}

0 comments on commit 7310c2e

Please sign in to comment.