From 3a2c635412f906833b03e81c55f7ffe02c961cdb Mon Sep 17 00:00:00 2001 From: pabl0cks Date: Tue, 5 Nov 2024 16:04:33 +0100 Subject: [PATCH 1/8] Initial commit to fetch data dynamically --- packages/nextjs/pages/batches/index.tsx | 201 +++++++++++++----------- 1 file changed, 111 insertions(+), 90 deletions(-) diff --git a/packages/nextjs/pages/batches/index.tsx b/packages/nextjs/pages/batches/index.tsx index 3affd7f..dcfbadd 100644 --- a/packages/nextjs/pages/batches/index.tsx +++ b/packages/nextjs/pages/batches/index.tsx @@ -1,98 +1,49 @@ import { useState } from "react"; import Image from "next/image"; import Link from "next/link"; +import type { GetStaticProps } from "next"; import { Footer } from "~~/components/Footer"; import { MetaHeader } from "~~/components/MetaHeader"; import TrackedLink from "~~/components/TrackedLink"; -const NEXT_BATCH_NUMBER = 11; +interface Builder { + id: string; + batch?: { + number: string; + status: "open" | "closed"; + }; +} + +interface BatchData { + id: string; + name: string; + status: "open" | "closed"; + telegramLink: string; + startDate: number; + contractAddress: string; + participants?: number; + batchPageLink?: string; + githubRepoLink?: string; + openseaLink?: string; +} -// TODO: We can probably get rid of this when we grab the info from the BG app API function getBatchNumber(batchName: string): number { const number = parseInt(batchName.replace("#", ""), 10); return isNaN(number) ? -1 : number; } -const BATCH_CARDS_INFO = [ - { - name: "#0", - participants: 12, - startDate: "12 Dec 23", - batchPageLink: "https://batch0.buidlguidl.com/", - githubRepoLink: "https://github.com/BuidlGuidl/batch0.buidlguidl.com", - }, - { - name: "#1", - participants: 15, - startDate: "15 Jan 24", - batchPageLink: "https://batch1.buidlguidl.com/", - githubRepoLink: "https://github.com/BuidlGuidl/batch1.buidlguidl.com", - }, - { - name: "#2", - participants: 9, - startDate: "13 Feb 24", - batchPageLink: "https://batch2.buidlguidl.com/", - githubRepoLink: "https://github.com/BuidlGuidl/batch2.buidlguidl.com", - }, - { - name: "#3", - participants: 9, - startDate: "05 Mar 24", - batchPageLink: "https://batch3.buidlguidl.com/", - githubRepoLink: "https://github.com/BuidlGuidl/batch3.buidlguidl.com", - }, - { - name: "#4", - participants: 17, - startDate: "08 Apr 24", - batchPageLink: "https://batch4.buidlguidl.com/", - githubRepoLink: "https://github.com/BuidlGuidl/batch4.buidlguidl.com", - }, - { - name: "#5", - participants: 8, - startDate: "06 May 24", - batchPageLink: "https://batch5.buidlguidl.com/", - githubRepoLink: "https://github.com/BuidlGuidl/batch5.buidlguidl.com", - }, - { - name: "#6", - participants: 9, - startDate: "03 Jun 24", - batchPageLink: "https://batch6.buidlguidl.com/", - githubRepoLink: "https://github.com/BuidlGuidl/batch6.buidlguidl.com", - }, - { - name: "#7", - participants: 7, - startDate: "08 Jul 24", - batchPageLink: "https://batch7.buidlguidl.com/", - githubRepoLink: "https://github.com/BuidlGuidl/batch7.buidlguidl.com", - }, - { - name: "#8", - participants: 10, - startDate: "06 Aug 24", - batchPageLink: "https://batch8.buidlguidl.com/", - githubRepoLink: "https://github.com/BuidlGuidl/batch8.buidlguidl.com", - }, - { - name: "#9", - participants: 14, - startDate: "09 Sep 24", - batchPageLink: "https://batch9.buidlguidl.com/", - githubRepoLink: "https://github.com/BuidlGuidl/batch9.buidlguidl.com", - openseaLink: "https://opensea.io/collection/batchgraduate-1", - }, - { - name: "#10", - participants: 11, - startDate: "14 Oct 24", - batchPageLink: "https://batch10.buidlguidl.com/", - githubRepoLink: "https://github.com/BuidlGuidl/batch10.buidlguidl.com", - }, -].sort((a, b) => getBatchNumber(b.name) - getBatchNumber(a.name)); +interface PageProps { + initialBatchData: BatchData[]; + initialOpenBatchNumber: number | null; +} + +const formatDate = (timestamp: number): string => { + return new Date(timestamp).toLocaleDateString("en-US", { + year: "numeric", + month: "short", + day: "numeric", + }); +}; // Custom header for the batches pagesince the "Go to app" button is different const BatchesHeader = () => { @@ -118,18 +69,18 @@ const BatchesHeader = () => { ); }; -const Batches = () => { +const Batches = ({ initialBatchData, initialOpenBatchNumber }: PageProps) => { const [currentPage, setCurrentPage] = useState(1); const itemsPerPage = 10; // Calculate pagination const indexOfLastItem = currentPage * itemsPerPage; const indexOfFirstItem = indexOfLastItem - itemsPerPage; - const currentItems = BATCH_CARDS_INFO.slice(indexOfFirstItem, indexOfLastItem); + const currentItems = initialBatchData.slice(indexOfFirstItem, indexOfLastItem); const paginate = (pageNumber: number) => setCurrentPage(pageNumber); - const totalPages = Math.ceil(BATCH_CARDS_INFO.length / itemsPerPage); + const totalPages = Math.ceil(initialBatchData.length / itemsPerPage); return ( <> @@ -229,7 +180,7 @@ const Batches = () => {

- Batch #{NEXT_BATCH_NUMBER} + Batch #{initialOpenBatchNumber}

Complete SpeedRunEthereum and join BuidlGuidl to participate in the next Batch! @@ -271,14 +222,14 @@ const Batches = () => { className="bg-white border-b border-base-100 text-center last:rounded-b-3xl last:border-none" > {batch.name} - {batch.startDate} + {formatDate(batch.startDate)} {batch.participants}

Website @@ -286,7 +237,7 @@ const Batches = () => {
GitHub @@ -294,7 +245,7 @@ const Batches = () => { {batch.openseaLink && ( OpenSea @@ -333,4 +284,74 @@ const Batches = () => { ); }; +export const getStaticProps: GetStaticProps = async () => { + try { + const [batchesResponse, buildersResponse] = await Promise.all([ + fetch(`${process.env.NEXT_PUBLIC_BG_BACKEND_API}/batches`), + fetch(`${process.env.NEXT_PUBLIC_BG_BACKEND_API}/builders`), + ]); + + if (!batchesResponse.ok || !buildersResponse.ok) { + throw new Error("Failed to fetch data"); + } + + const batchesData: BatchData[] = await batchesResponse.json(); + const buildersData: Builder[] = await buildersResponse.json(); + + // Count builders per batch + const buildersPerBatch: Record = {}; + buildersData.forEach(builder => { + if (builder.batch?.number) { + buildersPerBatch[builder.batch.number] = (buildersPerBatch[builder.batch.number] || 0) + 1; + } + }); + + // Find open batch number or calculate next batch number + const openBatch = batchesData.find(batch => batch.status === "open"); + let openBatchNumber: number | null = null; + + if (openBatch) { + openBatchNumber = parseInt(openBatch.name); + } else { + // Find the highest batch number and add 1 + const highestBatch = Math.max(...batchesData.map(batch => parseInt(batch.name))); + openBatchNumber = highestBatch + 1; + } + + // Convert to BatchData format + const batchCards: BatchData[] = batchesData.map(batch => ({ + ...batch, + name: `#${batch.name}`, + participants: buildersPerBatch[batch.name] || 0, + startDate: batch.startDate, + batchPageLink: `https://batch${batch.name}.buidlguidl.com/`, + githubRepoLink: `https://github.com/BuidlGuidl/batch${batch.name}.buidlguidl.com`, + ...(batch.name === "9" && { + openseaLink: "https://opensea.io/collection/batchgraduate-1", + }), + })); + + // Sort batches by number (newest first) + const sortedBatches = batchCards.sort((a, b) => getBatchNumber(b.name) - getBatchNumber(a.name)); + + return { + props: { + initialBatchData: sortedBatches, + initialOpenBatchNumber: openBatchNumber, + }, + // 6 hours refresh, matching index.tsx + revalidate: 21600, + }; + } catch (error) { + console.error("Error in getStaticProps:", error); + return { + props: { + initialBatchData: [], + initialOpenBatchNumber: null, + }, + revalidate: 21600, + }; + } +}; + export default Batches; From 3db30e49810a422f60d04f017c7836ba834886df Mon Sep 17 00:00:00 2001 From: pabl0cks Date: Wed, 6 Nov 2024 00:51:05 +0100 Subject: [PATCH 2/8] Cleanup --- packages/nextjs/pages/batches/index.tsx | 31 +++++++++++++------------ 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/packages/nextjs/pages/batches/index.tsx b/packages/nextjs/pages/batches/index.tsx index dcfbadd..71d7b3b 100644 --- a/packages/nextjs/pages/batches/index.tsx +++ b/packages/nextjs/pages/batches/index.tsx @@ -33,8 +33,8 @@ function getBatchNumber(batchName: string): number { } interface PageProps { - initialBatchData: BatchData[]; - initialOpenBatchNumber: number | null; + batchData: BatchData[]; + openBatchNumber: number | null; } const formatDate = (timestamp: number): string => { @@ -45,7 +45,7 @@ const formatDate = (timestamp: number): string => { }); }; -// Custom header for the batches pagesince the "Go to app" button is different +// Custom header for the batches page since the "Go to app" button is different const BatchesHeader = () => { return (
@@ -69,18 +69,18 @@ const BatchesHeader = () => { ); }; -const Batches = ({ initialBatchData, initialOpenBatchNumber }: PageProps) => { +const Batches = ({ batchData, openBatchNumber }: PageProps) => { const [currentPage, setCurrentPage] = useState(1); const itemsPerPage = 10; // Calculate pagination const indexOfLastItem = currentPage * itemsPerPage; const indexOfFirstItem = indexOfLastItem - itemsPerPage; - const currentItems = initialBatchData.slice(indexOfFirstItem, indexOfLastItem); + const currentItems = batchData.slice(indexOfFirstItem, indexOfLastItem); const paginate = (pageNumber: number) => setCurrentPage(pageNumber); - const totalPages = Math.ceil(initialBatchData.length / itemsPerPage); + const totalPages = Math.ceil(batchData.length / itemsPerPage); return ( <> @@ -180,7 +180,7 @@ const Batches = ({ initialBatchData, initialOpenBatchNumber }: PageProps) => {

- Batch #{initialOpenBatchNumber} + Batch #{openBatchNumber}

Complete SpeedRunEthereum and join BuidlGuidl to participate in the next Batch! @@ -318,36 +318,37 @@ export const getStaticProps: GetStaticProps = async () => { openBatchNumber = highestBatch + 1; } - // Convert to BatchData format - const batchCards: BatchData[] = batchesData.map(batch => ({ + // Enrich batch data with additional fields + const batches: BatchData[] = batchesData.map(batch => ({ ...batch, name: `#${batch.name}`, participants: buildersPerBatch[batch.name] || 0, startDate: batch.startDate, batchPageLink: `https://batch${batch.name}.buidlguidl.com/`, githubRepoLink: `https://github.com/BuidlGuidl/batch${batch.name}.buidlguidl.com`, + // TODO: Remove this once we have opensea data in API endpoint ...(batch.name === "9" && { openseaLink: "https://opensea.io/collection/batchgraduate-1", }), })); // Sort batches by number (newest first) - const sortedBatches = batchCards.sort((a, b) => getBatchNumber(b.name) - getBatchNumber(a.name)); + const sortedBatches = batches.sort((a, b) => getBatchNumber(b.name) - getBatchNumber(a.name)); return { props: { - initialBatchData: sortedBatches, - initialOpenBatchNumber: openBatchNumber, + batchData: sortedBatches, + openBatchNumber: openBatchNumber, }, - // 6 hours refresh, matching index.tsx + // 6 hours refresh revalidate: 21600, }; } catch (error) { console.error("Error in getStaticProps:", error); return { props: { - initialBatchData: [], - initialOpenBatchNumber: null, + batchData: [], + openBatchNumber: null, }, revalidate: 21600, }; From 41a8c71b5401976f7bf588c3e495735b446d4ea0 Mon Sep 17 00:00:00 2001 From: pabl0cks Date: Wed, 27 Nov 2024 14:56:24 +0100 Subject: [PATCH 3/8] Read participants from new api endpoint --- packages/nextjs/pages/batches/index.tsx | 30 +++++-------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/packages/nextjs/pages/batches/index.tsx b/packages/nextjs/pages/batches/index.tsx index 71d7b3b..eb5918a 100644 --- a/packages/nextjs/pages/batches/index.tsx +++ b/packages/nextjs/pages/batches/index.tsx @@ -6,14 +6,6 @@ import { Footer } from "~~/components/Footer"; import { MetaHeader } from "~~/components/MetaHeader"; import TrackedLink from "~~/components/TrackedLink"; -interface Builder { - id: string; - batch?: { - number: string; - status: "open" | "closed"; - }; -} - interface BatchData { id: string; name: string; @@ -21,7 +13,7 @@ interface BatchData { telegramLink: string; startDate: number; contractAddress: string; - participants?: number; + totalParticipants: number; batchPageLink?: string; githubRepoLink?: string; openseaLink?: string; @@ -223,7 +215,7 @@ const Batches = ({ batchData, openBatchNumber }: PageProps) => { > {batch.name} {formatDate(batch.startDate)} - {batch.participants} + {batch.totalParticipants}

@@ -286,25 +278,13 @@ const Batches = ({ batchData, openBatchNumber }: PageProps) => { export const getStaticProps: GetStaticProps = async () => { try { - const [batchesResponse, buildersResponse] = await Promise.all([ - fetch(`${process.env.NEXT_PUBLIC_BG_BACKEND_API}/batches`), - fetch(`${process.env.NEXT_PUBLIC_BG_BACKEND_API}/builders`), - ]); + const batchesResponse = await fetch(`${process.env.NEXT_PUBLIC_BG_BACKEND_API}/batches`); - if (!batchesResponse.ok || !buildersResponse.ok) { + if (!batchesResponse.ok) { throw new Error("Failed to fetch data"); } const batchesData: BatchData[] = await batchesResponse.json(); - const buildersData: Builder[] = await buildersResponse.json(); - - // Count builders per batch - const buildersPerBatch: Record = {}; - buildersData.forEach(builder => { - if (builder.batch?.number) { - buildersPerBatch[builder.batch.number] = (buildersPerBatch[builder.batch.number] || 0) + 1; - } - }); // Find open batch number or calculate next batch number const openBatch = batchesData.find(batch => batch.status === "open"); @@ -322,7 +302,7 @@ export const getStaticProps: GetStaticProps = async () => { const batches: BatchData[] = batchesData.map(batch => ({ ...batch, name: `#${batch.name}`, - participants: buildersPerBatch[batch.name] || 0, + totalParticipants: batch.totalParticipants || 0, startDate: batch.startDate, batchPageLink: `https://batch${batch.name}.buidlguidl.com/`, githubRepoLink: `https://github.com/BuidlGuidl/batch${batch.name}.buidlguidl.com`, From 44247448b71a667f47124c6a03469d835c015758 Mon Sep 17 00:00:00 2001 From: pabl0cks Date: Wed, 27 Nov 2024 14:57:14 +0100 Subject: [PATCH 4/8] Hardcode batch 10 opensea link --- packages/nextjs/pages/batches/index.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/nextjs/pages/batches/index.tsx b/packages/nextjs/pages/batches/index.tsx index eb5918a..ddd386c 100644 --- a/packages/nextjs/pages/batches/index.tsx +++ b/packages/nextjs/pages/batches/index.tsx @@ -310,6 +310,9 @@ export const getStaticProps: GetStaticProps = async () => { ...(batch.name === "9" && { openseaLink: "https://opensea.io/collection/batchgraduate-1", }), + ...(batch.name === "10" && { + openseaLink: "https://opensea.io/collection/batchgraduate-2", + }), })); // Sort batches by number (newest first) From 7409c2d40fca02522971150ce79effed8680a77f Mon Sep 17 00:00:00 2001 From: pabl0cks Date: Thu, 28 Nov 2024 13:41:44 +0100 Subject: [PATCH 5/8] Add logic to fetch nftcontract from batch contract --- packages/nextjs/pages/batches/index.tsx | 89 ++++++++++++++++++------- 1 file changed, 65 insertions(+), 24 deletions(-) diff --git a/packages/nextjs/pages/batches/index.tsx b/packages/nextjs/pages/batches/index.tsx index ddd386c..06a8dbc 100644 --- a/packages/nextjs/pages/batches/index.tsx +++ b/packages/nextjs/pages/batches/index.tsx @@ -2,6 +2,8 @@ import { useState } from "react"; import Image from "next/image"; import Link from "next/link"; import type { GetStaticProps } from "next"; +import { createPublicClient, http } from "viem"; +import { optimism } from "viem/chains"; import { Footer } from "~~/components/Footer"; import { MetaHeader } from "~~/components/MetaHeader"; import TrackedLink from "~~/components/TrackedLink"; @@ -16,12 +18,7 @@ interface BatchData { totalParticipants: number; batchPageLink?: string; githubRepoLink?: string; - openseaLink?: string; -} - -function getBatchNumber(batchName: string): number { - const number = parseInt(batchName.replace("#", ""), 10); - return isNaN(number) ? -1 : number; + openseaLink?: string | null; } interface PageProps { @@ -276,6 +273,48 @@ const Batches = ({ batchData, openBatchNumber }: PageProps) => { ); }; +const publicClient = createPublicClient({ + chain: optimism, + transport: http(), +}); + +export async function readBatchGraduationNFT(contractAddress: string) { + try { + const bytecode = await publicClient.getBytecode({ + address: contractAddress as `0x${string}`, + }); + + if (!bytecode) { + return null; + } + + // Check if the batchGraduationNFT function exists in the bytecode + const functionSignature = "bb9da723"; + if (!bytecode.includes(functionSignature)) { + return null; + } + + const data = await publicClient.readContract({ + address: contractAddress as `0x${string}`, + abi: [ + { + inputs: [], + name: "batchGraduationNFT", + outputs: [{ type: "address", name: "nftAddress" }], + stateMutability: "view", + type: "function", + }, + ], + functionName: "batchGraduationNFT", + }); + + return data as `0x${string}`; + } catch (error) { + console.error("Error reading batchGraduationNFT:", error); + return null; + } +} + export const getStaticProps: GetStaticProps = async () => { try { const batchesResponse = await fetch(`${process.env.NEXT_PUBLIC_BG_BACKEND_API}/batches`); @@ -284,7 +323,7 @@ export const getStaticProps: GetStaticProps = async () => { throw new Error("Failed to fetch data"); } - const batchesData: BatchData[] = await batchesResponse.json(); + const batchesData = (await batchesResponse.json()) as BatchData[]; // Find open batch number or calculate next batch number const openBatch = batchesData.find(batch => batch.status === "open"); @@ -293,30 +332,32 @@ export const getStaticProps: GetStaticProps = async () => { if (openBatch) { openBatchNumber = parseInt(openBatch.name); } else { - // Find the highest batch number and add 1 const highestBatch = Math.max(...batchesData.map(batch => parseInt(batch.name))); openBatchNumber = highestBatch + 1; } - // Enrich batch data with additional fields - const batches: BatchData[] = batchesData.map(batch => ({ - ...batch, - name: `#${batch.name}`, - totalParticipants: batch.totalParticipants || 0, - startDate: batch.startDate, - batchPageLink: `https://batch${batch.name}.buidlguidl.com/`, - githubRepoLink: `https://github.com/BuidlGuidl/batch${batch.name}.buidlguidl.com`, - // TODO: Remove this once we have opensea data in API endpoint - ...(batch.name === "9" && { - openseaLink: "https://opensea.io/collection/batchgraduate-1", - }), - ...(batch.name === "10" && { - openseaLink: "https://opensea.io/collection/batchgraduate-2", + // Fetch and enrich batch data with NFT addresses and formatted fields + const batches: BatchData[] = await Promise.all( + batchesData.map(async batch => { + let nftAddress = null; + if (batch.contractAddress) { + nftAddress = await readBatchGraduationNFT(batch.contractAddress); + } + + return { + ...batch, + name: `#${batch.name}`, + totalParticipants: batch.totalParticipants || 0, + startDate: batch.startDate, + batchPageLink: `https://batch${batch.name}.buidlguidl.com/`, + githubRepoLink: `https://github.com/BuidlGuidl/batch${batch.name}.buidlguidl.com`, + openseaLink: nftAddress ? `https://opensea.io/assets/optimism/${nftAddress}` : null, + }; }), - })); + ); // Sort batches by number (newest first) - const sortedBatches = batches.sort((a, b) => getBatchNumber(b.name) - getBatchNumber(a.name)); + const sortedBatches = batches.sort((a, b) => b.name.localeCompare(a.name, undefined, { numeric: true })); return { props: { From a1257053e8efea400414acc8c5b0f3c48023cd70 Mon Sep 17 00:00:00 2001 From: pabl0cks Date: Thu, 28 Nov 2024 13:51:08 +0100 Subject: [PATCH 6/8] Add graduates to the table, hide opensea link if 0 --- packages/nextjs/pages/batches/index.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/nextjs/pages/batches/index.tsx b/packages/nextjs/pages/batches/index.tsx index 06a8dbc..a167a65 100644 --- a/packages/nextjs/pages/batches/index.tsx +++ b/packages/nextjs/pages/batches/index.tsx @@ -16,6 +16,7 @@ interface BatchData { startDate: number; contractAddress: string; totalParticipants: number; + graduates: number; batchPageLink?: string; githubRepoLink?: string; openseaLink?: string | null; @@ -201,6 +202,7 @@ const Batches = ({ batchData, openBatchNumber }: PageProps) => { Batch Start Date Participants + Graduates Links @@ -213,6 +215,7 @@ const Batches = ({ batchData, openBatchNumber }: PageProps) => { {batch.name} {formatDate(batch.startDate)} {batch.totalParticipants} + {batch.graduates || "-"}
@@ -231,7 +234,7 @@ const Batches = ({ batchData, openBatchNumber }: PageProps) => { > GitHub - {batch.openseaLink && ( + {batch.openseaLink && batch.graduates > 0 && ( Date: Sat, 30 Nov 2024 00:10:49 +0100 Subject: [PATCH 7/8] Revert "Add logic to fetch nftcontract from batch contract" This reverts commit 7409c2d40fca02522971150ce79effed8680a77f. --- packages/nextjs/pages/batches/index.tsx | 89 +++++++------------------ 1 file changed, 24 insertions(+), 65 deletions(-) diff --git a/packages/nextjs/pages/batches/index.tsx b/packages/nextjs/pages/batches/index.tsx index a167a65..d208dbf 100644 --- a/packages/nextjs/pages/batches/index.tsx +++ b/packages/nextjs/pages/batches/index.tsx @@ -2,8 +2,6 @@ import { useState } from "react"; import Image from "next/image"; import Link from "next/link"; import type { GetStaticProps } from "next"; -import { createPublicClient, http } from "viem"; -import { optimism } from "viem/chains"; import { Footer } from "~~/components/Footer"; import { MetaHeader } from "~~/components/MetaHeader"; import TrackedLink from "~~/components/TrackedLink"; @@ -19,7 +17,12 @@ interface BatchData { graduates: number; batchPageLink?: string; githubRepoLink?: string; - openseaLink?: string | null; + openseaLink?: string; +} + +function getBatchNumber(batchName: string): number { + const number = parseInt(batchName.replace("#", ""), 10); + return isNaN(number) ? -1 : number; } interface PageProps { @@ -276,48 +279,6 @@ const Batches = ({ batchData, openBatchNumber }: PageProps) => { ); }; -const publicClient = createPublicClient({ - chain: optimism, - transport: http(), -}); - -export async function readBatchGraduationNFT(contractAddress: string) { - try { - const bytecode = await publicClient.getBytecode({ - address: contractAddress as `0x${string}`, - }); - - if (!bytecode) { - return null; - } - - // Check if the batchGraduationNFT function exists in the bytecode - const functionSignature = "bb9da723"; - if (!bytecode.includes(functionSignature)) { - return null; - } - - const data = await publicClient.readContract({ - address: contractAddress as `0x${string}`, - abi: [ - { - inputs: [], - name: "batchGraduationNFT", - outputs: [{ type: "address", name: "nftAddress" }], - stateMutability: "view", - type: "function", - }, - ], - functionName: "batchGraduationNFT", - }); - - return data as `0x${string}`; - } catch (error) { - console.error("Error reading batchGraduationNFT:", error); - return null; - } -} - export const getStaticProps: GetStaticProps = async () => { try { const batchesResponse = await fetch(`${process.env.NEXT_PUBLIC_BG_BACKEND_API}/batches`); @@ -326,7 +287,7 @@ export const getStaticProps: GetStaticProps = async () => { throw new Error("Failed to fetch data"); } - const batchesData = (await batchesResponse.json()) as BatchData[]; + const batchesData: BatchData[] = await batchesResponse.json(); // Find open batch number or calculate next batch number const openBatch = batchesData.find(batch => batch.status === "open"); @@ -335,32 +296,30 @@ export const getStaticProps: GetStaticProps = async () => { if (openBatch) { openBatchNumber = parseInt(openBatch.name); } else { + // Find the highest batch number and add 1 const highestBatch = Math.max(...batchesData.map(batch => parseInt(batch.name))); openBatchNumber = highestBatch + 1; } - // Fetch and enrich batch data with NFT addresses and formatted fields - const batches: BatchData[] = await Promise.all( - batchesData.map(async batch => { - let nftAddress = null; - if (batch.contractAddress) { - nftAddress = await readBatchGraduationNFT(batch.contractAddress); - } - - return { - ...batch, - name: `#${batch.name}`, - totalParticipants: batch.totalParticipants || 0, - startDate: batch.startDate, - batchPageLink: `https://batch${batch.name}.buidlguidl.com/`, - githubRepoLink: `https://github.com/BuidlGuidl/batch${batch.name}.buidlguidl.com`, - openseaLink: nftAddress ? `https://opensea.io/assets/optimism/${nftAddress}` : null, - }; + // Enrich batch data with additional fields + const batches: BatchData[] = batchesData.map(batch => ({ + ...batch, + name: `#${batch.name}`, + totalParticipants: batch.totalParticipants || 0, + startDate: batch.startDate, + batchPageLink: `https://batch${batch.name}.buidlguidl.com/`, + githubRepoLink: `https://github.com/BuidlGuidl/batch${batch.name}.buidlguidl.com`, + // TODO: Remove this once we have opensea data in API endpoint + ...(batch.name === "9" && { + openseaLink: "https://opensea.io/collection/batchgraduate-1", + }), + ...(batch.name === "10" && { + openseaLink: "https://opensea.io/collection/batchgraduate-2", }), - ); + })); // Sort batches by number (newest first) - const sortedBatches = batches.sort((a, b) => b.name.localeCompare(a.name, undefined, { numeric: true })); + const sortedBatches = batches.sort((a, b) => getBatchNumber(b.name) - getBatchNumber(a.name)); return { props: { From 93b13257ac246f28797b37c1f5129023db1604fc Mon Sep 17 00:00:00 2001 From: pabl0cks Date: Sat, 30 Nov 2024 00:20:02 +0100 Subject: [PATCH 8/8] Remove opensea column until inclusion in bg3.5 api --- packages/nextjs/pages/batches/index.tsx | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/packages/nextjs/pages/batches/index.tsx b/packages/nextjs/pages/batches/index.tsx index d208dbf..58016b4 100644 --- a/packages/nextjs/pages/batches/index.tsx +++ b/packages/nextjs/pages/batches/index.tsx @@ -17,7 +17,6 @@ interface BatchData { graduates: number; batchPageLink?: string; githubRepoLink?: string; - openseaLink?: string; } function getBatchNumber(batchName: string): number { @@ -237,15 +236,6 @@ const Batches = ({ batchData, openBatchNumber }: PageProps) => { > GitHub - {batch.openseaLink && batch.graduates > 0 && ( - - OpenSea - - )}
@@ -309,13 +299,6 @@ export const getStaticProps: GetStaticProps = async () => { startDate: batch.startDate, batchPageLink: `https://batch${batch.name}.buidlguidl.com/`, githubRepoLink: `https://github.com/BuidlGuidl/batch${batch.name}.buidlguidl.com`, - // TODO: Remove this once we have opensea data in API endpoint - ...(batch.name === "9" && { - openseaLink: "https://opensea.io/collection/batchgraduate-1", - }), - ...(batch.name === "10" && { - openseaLink: "https://opensea.io/collection/batchgraduate-2", - }), })); // Sort batches by number (newest first)