|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import Link from "next/link"; |
| 4 | +import { Address } from "~~/components/scaffold-eth"; |
| 5 | +import { useScaffoldEventHistory } from "~~/hooks/scaffold-eth"; |
| 6 | + |
| 7 | +type Props = { |
| 8 | + publishedBuilders: string[]; |
| 9 | +}; |
| 10 | + |
| 11 | +const CONTRACT_FROM_BLOCK: bigint = 355913556n; |
| 12 | + |
| 13 | +export default function BuildersGrid({ publishedBuilders }: Props) { |
| 14 | + const { data: checkedInEvents, isLoading: isEventsLoading } = useScaffoldEventHistory({ |
| 15 | + contractName: "BatchRegistry", |
| 16 | + eventName: "CheckedIn", |
| 17 | + fromBlock: CONTRACT_FROM_BLOCK, |
| 18 | + blocksBatchSize: 5000000, // default 500, so slowly. |
| 19 | + }); |
| 20 | + const filteredEvents = checkedInEvents?.filter(event => event?.args?.first); |
| 21 | + |
| 22 | + return isEventsLoading ? ( |
| 23 | + <p>Loading checked-in events...</p> |
| 24 | + ) : ( |
| 25 | + <div className="grid grid-cols-1 lg:grid-cols-3 px-6 lg:px-10 lg:gap-4 w-full max-w-7xl"> |
| 26 | + {filteredEvents?.map((event, index) => { |
| 27 | + return ( |
| 28 | + <div |
| 29 | + key={index} |
| 30 | + className="bg-base-100 border-base-300 border shadow-md shadow-secondary rounded-3xl px-6 lg:px-8 py-4" |
| 31 | + > |
| 32 | + <div className="flex"> |
| 33 | + <div className="flex flex-col gap-1 w-full"> |
| 34 | + <div className="flex gap-3 items-center"> |
| 35 | + <span className="font-bold w-1/4">Builder</span> |
| 36 | + <Address address={event.args.builder} onlyEnsOrAddress /> |
| 37 | + </div> |
| 38 | + <div className="flex gap-3 items-center"> |
| 39 | + <span className="font-bold w-1/4">Contract</span> |
| 40 | + <Address address={event.args.checkInContract} format="short" onlyEnsOrAddress /> |
| 41 | + </div> |
| 42 | + <div className="flex gap-3 items-center"> |
| 43 | + <span className="font-bold w-1/4">Profile</span> |
| 44 | + {publishedBuilders.includes(event.args.builder ?? "") ? ( |
| 45 | + <div className="flex gap-3 items-center"> |
| 46 | + <Link href={`builders/${event.args.builder}`} target="_blank"> |
| 47 | + <button className="btn btn-secondary btn-xs self-end md:self-start">View 🧑💻</button> |
| 48 | + </Link> |
| 49 | + </div> |
| 50 | + ) : ( |
| 51 | + <span className="text-sm">N/A</span> |
| 52 | + )} |
| 53 | + </div> |
| 54 | + </div> |
| 55 | + </div> |
| 56 | + </div> |
| 57 | + ); |
| 58 | + })} |
| 59 | + </div> |
| 60 | + ); |
| 61 | +} |
0 commit comments