Skip to content

Commit

Permalink
Merge pull request #35 from ludmila-omlopes/issue7
Browse files Browse the repository at this point in the history
New "builders" page, with new Header link and json reference file.
  • Loading branch information
phipsae authored Jan 27, 2025
2 parents b5b0967 + ec370ea commit d14e1ec
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 2 deletions.
17 changes: 17 additions & 0 deletions packages/nextjs/app/api/builders/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { NextResponse } from "next/server";
import { readdir } from "fs/promises";
import path from "path";

export async function GET() {
const buildersPath = path.join(process.cwd(), "app/builders");

try {
const directories = await readdir(buildersPath, { withFileTypes: true });
const addresses = directories.filter(dirent => dirent.isDirectory() && dirent.name.startsWith("0x"));

return NextResponse.json(addresses.map(dirent => dirent.name));
} catch (error) {
console.error("Error reading builders directory:", error);
return NextResponse.json({ error: "Failed to fetch builders" }, { status: 500 });
}
}
92 changes: 92 additions & 0 deletions packages/nextjs/app/builders/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
"use client";

import { useEffect, useMemo, useState } from "react";
import { HiOutlineUserCircle } from "react-icons/hi";
import { Address } from "~~/components/scaffold-eth";
import { useScaffoldEventHistory } from "~~/hooks/scaffold-eth";

const BuildersPage = () => {
const [validProfiles, setValidProfiles] = useState<string[]>([]);
const { data: events, isLoading } = useScaffoldEventHistory({
contractName: "BatchRegistry",
eventName: "CheckedIn",
fromBlock: 130068488n,
watch: true,
});

const uniqueBuilders = useMemo(() => {
return Array.from(new Set(events?.map(event => event.args.builder).filter(Boolean) || [])) as string[];
}, [events]);

const sortedBuilders = useMemo(() => {
return [...uniqueBuilders].sort((a, b) => {
const aHasProfile = validProfiles.includes(a) ? 1 : 0;
const bHasProfile = validProfiles.includes(b) ? 1 : 0;
return bHasProfile - aHasProfile;
});
}, [uniqueBuilders, validProfiles]);

useEffect(() => {
const checkProfiles = async () => {
try {
const response = await fetch("/api/builders");
if (!response.ok) {
throw new Error("Failed to fetch builder profiles");
}
const profiles = await response.json();
setValidProfiles(profiles);
} catch (error) {
console.error("Error checking builder profiles:", error);
setValidProfiles([]);
}
};

if (uniqueBuilders.length > 0) {
checkProfiles();
}
}, [uniqueBuilders]);

if (isLoading) {
return (
<div className="min-h-screen flex justify-center items-center">
<div className="text-lg font-medium">Loading builders...</div>
</div>
);
}

return (
<div className="min-h-screen flex flex-col items-center">
<div className="w-full max-w-4xl bg-base-100 shadow-lg rounded-[22px] p-6 mt-10">
<h1 className="text-3xl font-bold mb-4">Builders in Batch 12</h1>
<p className="mb-6">
Welcome to the list of builders who have successfully checked in for Batch 12. Below, you will find a list of
all builders and their Ethereum addresses. If a builder has a profile page, you&#39;ll see a{" "}
<HiOutlineUserCircle className="text-blue-600 dark:text-blue-400 inline w-6 h-6" /> icon next to their
address.
</p>
<div className="gap-3 grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3">
{sortedBuilders.map(builder => (
<div key={builder} className="bg-base-200 rounded-[22px] py-2 px-2 hover:bg-base-300 transition-all h-full">
<div className="flex justify-between items-center h-full">
<div>
<Address address={builder} />
</div>
{builder && validProfiles.includes(builder) && (
<a
href={`/builders/${builder}`}
className="text-blue-600 dark:text-blue-400 hover:text-blue-800 dark:hover:text-blue-300"
title="View Profile"
>
<HiOutlineUserCircle className="w-6 h-6" />
</a>
)}
</div>
</div>
))}
</div>
</div>
</div>
);
};

export default BuildersPage;
4 changes: 4 additions & 0 deletions packages/nextjs/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export const menuLinks: HeaderMenuLink[] = [
label: "Home",
href: "/",
},
{
label: "Builders",
href: "/builders",
},
{
label: "Debug Contracts",
href: "/debug",
Expand Down
4 changes: 2 additions & 2 deletions packages/nextjs/components/assets/LogoSvg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export const LogoSvg = ({ className = "" }: { className?: string }) => {
d="M292.215 343.998V433.105H307.826V393.155C307.826 393.155 311.815 384.95 326.358 388.57C345.602 393.36 369.311 390.114 384.532 362.567C338.41 377.757 337.174 325.556 292.215 343.998Z"
fill="currentColor"
/>
<circle cx="300" cy="300" r="281" stroke="currentColor" stroke-width="18" />
<circle cx="300" cy="300" r="281" stroke="currentColor" strokeWidth="18" />
<circle cx="300" cy="300" r="20" fill="currentColor" />
<path d="M300 291V199" stroke="currentColor" stroke-width="26" stroke-linecap="round" />
<path d="M300 291V199" stroke="currentColor" strokeWidth="26" strokeLinecap="round" />
<path
d="M262.398 165.44C258.318 165.44 255.198 164.36 253.038 162.2C250.878 159.92 249.798 156.68 249.798 152.48V63.92H260.958L236.838 85.52C233.718 88.4 230.358 89.36 226.758 88.4C223.278 87.32 221.118 85.04 220.278 81.56C219.558 78.08 220.998 74.72 224.598 71.48L251.778 46.28C253.698 44.6 255.618 43.46 257.538 42.86C259.458 42.26 261.678 41.96 264.198 41.96C267.558 41.96 270.198 42.92 272.118 44.84C274.038 46.76 274.998 49.46 274.998 52.94V152.48C274.998 156.68 273.918 159.92 271.758 162.2C269.598 164.36 266.478 165.44 262.398 165.44ZM303.303 164C299.103 164 296.043 163.04 294.123 161.12C292.323 159.2 291.423 156.44 291.423 152.84C291.423 150.56 291.963 148.4 293.043 146.36C294.123 144.32 295.803 142.1 298.083 139.7L333.183 102.44L338.223 97.22C342.423 93.02 345.303 89.78 346.863 87.5C348.423 85.22 349.203 82.58 349.203 79.58C349.203 74.06 347.223 69.86 343.263 66.98C339.423 64.1 334.023 62.66 327.063 62.66C323.583 62.66 319.863 63.44 315.903 65C311.943 66.44 308.283 68.66 304.923 71.66C301.563 74.3 298.263 74.84 295.023 73.28C291.783 71.6 289.803 68.9 289.083 65.18C288.483 61.34 289.803 57.98 293.043 55.1C297.723 51.14 303.483 47.9 310.323 45.38C317.283 42.86 323.943 41.6 330.303 41.6C339.423 41.6 347.163 43.1 353.523 46.1C359.883 49.1 364.743 53.3 368.103 58.7C371.463 63.98 373.143 70.22 373.143 77.42C373.143 81.38 372.363 85.28 370.803 89.12C369.243 92.84 366.843 96.86 363.603 101.18C360.363 105.38 355.983 110.3 350.463 115.94L317.703 149.78V143.12H368.643C372.123 143.12 374.763 144.02 376.563 145.82C378.363 147.5 379.263 150.02 379.263 153.38C379.263 156.86 378.363 159.5 376.563 161.3C374.763 163.1 372.123 164 368.643 164H303.303Z"
fill="currentColor"
Expand Down

0 comments on commit d14e1ec

Please sign in to comment.