generated from scaffold-eth/scaffold-eth-2
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
92 additions
and
3 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
packages/nextjs/app/api/builders/[builderAddress]/grants/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { NextResponse } from "next/server"; | ||
import { getAllGrantsForUser } from "~~/services/database/grants"; | ||
|
||
export async function GET(_request: Request, { params }: { params: { builderAddress: string } }) { | ||
try { | ||
const builderAddress = params.builderAddress; | ||
const grants = await getAllGrantsForUser(builderAddress); | ||
return NextResponse.json(grants); | ||
} catch (error) { | ||
return NextResponse.json( | ||
{ message: "Internal Server Error" }, | ||
{ | ||
status: 500, | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"use client"; | ||
|
||
import { useEffect, useState } from "react"; | ||
import { NextPage } from "next"; | ||
import { useAccount } from "wagmi"; | ||
import { GrantData } from "~~/services/database/schema"; | ||
import { PROPOSAL_STATUS } from "~~/utils/grants"; | ||
|
||
const badgeBgColor = { | ||
[PROPOSAL_STATUS.PROPOSED]: "bg-warning", | ||
[PROPOSAL_STATUS.APPROVED]: "bg-success", | ||
[PROPOSAL_STATUS.SUBMITTED]: "bg-warning", | ||
[PROPOSAL_STATUS.COMPLETED]: "bg-success", | ||
[PROPOSAL_STATUS.REJECTED]: "bg-error", | ||
}; | ||
|
||
// ToDo. Action (v1.0 = submit grant after completion) | ||
// ToDo. Loading states | ||
const MyGrants: NextPage = () => { | ||
const { address } = useAccount(); | ||
const [builderGrants, setBuilderGrants] = useState<GrantData[]>([]); | ||
|
||
useEffect(() => { | ||
const fetchBuilderGrants = async () => { | ||
try { | ||
const response = await fetch(`/api/builders/${address}/grants`); | ||
const data = await response.json(); | ||
setBuilderGrants(data); | ||
} catch (error) { | ||
console.error("Failed to fetch builder grants", error); | ||
} | ||
}; | ||
|
||
if (address) { | ||
fetchBuilderGrants(); | ||
} | ||
}, [address]); | ||
|
||
return ( | ||
<div className="container mx-auto max-w-screen-md mt-12"> | ||
<h1 className="text-4xl font-bold">My grants</h1> | ||
{builderGrants.map(grant => ( | ||
<div key={grant.id} className="border p-4 my-4"> | ||
<h3 className="font-bold"> | ||
{grant.title} | ||
<span className="text-sm text-gray-500 ml-2">({grant.id})</span> | ||
</h3> | ||
<p>{grant.description}</p> | ||
<p className={`badge ${badgeBgColor[grant.status]}`}>{grant.status}</p> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default MyGrants; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters