11"use client" ;
22
3+ import { useEffect , useState } from "react" ;
34import { GraduateCard } from "./_components/GraduateCard" ;
5+ import { parseAbiItem } from "viem" ;
6+ import { usePublicClient } from "wagmi" ;
47import { TrophyIcon } from "@heroicons/react/24/outline" ;
5- import { useScaffoldEventHistory } from "~~/hooks/scaffold-eth" ;
8+ import { useScaffoldReadContract } from "~~/hooks/scaffold-eth" ;
69
710export default function HallOfFame ( ) {
8- const { data : transferEvents , isLoading } = useScaffoldEventHistory ( {
9- contractName : "BatchGraduationNFT" ,
10- eventName : "Transfer" ,
11- fromBlock : 0n ,
12- filters : { from : "0x0000000000000000000000000000000000000000" } ,
11+ const { data : nftAddress } = useScaffoldReadContract ( {
12+ contractName : "BatchRegistry" ,
13+ functionName : "batchGraduationNFT" ,
1314 } ) ;
1415
16+ const publicClient = usePublicClient ( ) ;
17+ const [ transferEvents , setTransferEvents ] = useState < any [ ] > ( [ ] ) ;
18+ const [ isLoading , setIsLoading ] = useState ( true ) ;
19+
20+ useEffect ( ( ) => {
21+ const fetchEvents = async ( ) => {
22+ if ( ! nftAddress || ! publicClient ) return ;
23+
24+ setIsLoading ( true ) ;
25+ try {
26+ const logs = await publicClient . getLogs ( {
27+ address : nftAddress ,
28+ event : parseAbiItem ( "event Transfer(address indexed from, address indexed to, uint256 indexed tokenId)" ) ,
29+ args : { from : "0x0000000000000000000000000000000000000000" } ,
30+ fromBlock : 0n ,
31+ toBlock : "latest" ,
32+ } ) ;
33+ setTransferEvents ( logs ) ;
34+ } catch ( e ) {
35+ console . error ( e ) ;
36+ } finally {
37+ setIsLoading ( false ) ;
38+ }
39+ } ;
40+
41+ fetchEvents ( ) ;
42+ } , [ nftAddress , publicClient ] ) ;
43+
1544 // I use this to sort events by tokenId (descending) to show newest graduates first
16- const sortedEvents = transferEvents ?. slice ( ) . sort ( ( a , b ) => {
45+ const sortedEvents = transferEvents ?. slice ( ) . sort ( ( a : any , b : any ) => {
1746 const tokenIdA = a . args . tokenId || 0n ;
1847 const tokenIdB = b . args . tokenId || 0n ;
1948 return Number ( tokenIdB - tokenIdA ) ;
@@ -36,7 +65,7 @@ export default function HallOfFame() {
3665 < span className = "loading loading-spinner loading-lg text-primary" > </ span >
3766 </ div >
3867 ) : (
39- < div className = "grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-8 p-6 max-w-7xl w-full" >
68+ < div className = "grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-8 p-6 max-w-7xl w-full" >
4069 { sortedEvents ?. map ( ( event : any ) => (
4170 < GraduateCard
4271 key = { event . args . tokenId ?. toString ( ) }
0 commit comments