From 6d17bc3572ad2db4f6ac3737d7b869a85ddf5e5a Mon Sep 17 00:00:00 2001 From: Pablo Alayeto <55535804+Pabl0cks@users.noreply.github.com> Date: Fri, 22 Mar 2024 17:14:14 +0100 Subject: [PATCH] /apply on any network. Remove ask amount from signature + display only on approved grants (#90) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Carlos Sánchez --- packages/nextjs/app/api/grants/new/route.ts | 17 +++++++---------- packages/nextjs/app/apply/_component/Form.tsx | 7 ++----- packages/nextjs/app/my-grants/page.tsx | 14 ++++++++------ packages/nextjs/utils/eip712.ts | 4 ---- 4 files changed, 17 insertions(+), 25 deletions(-) diff --git a/packages/nextjs/app/api/grants/new/route.ts b/packages/nextjs/app/api/grants/new/route.ts index 31dbb8cc..3cdd18f1 100644 --- a/packages/nextjs/app/api/grants/new/route.ts +++ b/packages/nextjs/app/api/grants/new/route.ts @@ -12,20 +12,17 @@ type ReqBody = { signer?: string; }; -// TODO: We could also add extra validtion of nonce +// Hardcoded default ask amount +const askAmount = 0.25; +// TODO: We could also add extra validation of nonce export async function POST(req: Request) { try { - const { title, description, askAmount, signature, signer } = (await req.json()) as ReqBody; + const { title, description, signature, signer } = (await req.json()) as ReqBody; - if (!title || !description || !askAmount || isNaN(Number(askAmount)) || !signature || !signer) { + if (!title || !description || !signature || !signer) { return NextResponse.json({ error: "Invalid form details submited" }, { status: 400 }); } - // Check to see if the askAmount === 0.25 - if (Number(askAmount) !== 0.25) { - return NextResponse.json({ error: "Invalid askAmount" }, { status: 400 }); - } - // Verif if the builder is present const builder = await findUserByAddress(signer); if (!builder.exists) { @@ -36,7 +33,7 @@ export async function POST(req: Request) { domain: EIP_712_DOMAIN, types: EIP_712_TYPES__APPLY_FOR_GRANT, primaryType: "Message", - message: { title, description, askAmount }, + message: { title, description }, signature: signature, }); @@ -47,7 +44,7 @@ export async function POST(req: Request) { const grant = await createGrant({ title: title, description: description, - askAmount: Number(askAmount), + askAmount: askAmount, builder: signer, }); diff --git a/packages/nextjs/app/apply/_component/Form.tsx b/packages/nextjs/app/apply/_component/Form.tsx index cce4e2d9..2205abf8 100644 --- a/packages/nextjs/app/apply/_component/Form.tsx +++ b/packages/nextjs/app/apply/_component/Form.tsx @@ -12,7 +12,6 @@ import { postMutationFetcher } from "~~/utils/swr"; type ReqBody = { title?: string; description?: string; - askAmount?: string; signature?: `0x${string}`; signer?: string; }; @@ -32,8 +31,7 @@ const Form = () => { try { const title = formData.get("title") as string; const description = formData.get("description") as string; - const askAmount = "0.25"; - if (!title || !description || !askAmount) { + if (!title || !description) { notification.error("Please fill all the fields"); return; } @@ -45,11 +43,10 @@ const Form = () => { message: { title: title, description: description, - askAmount: askAmount, }, }); - await postNewGrant({ title, description, askAmount, signature, signer: connectedAddress }); + await postNewGrant({ title, description, signature, signer: connectedAddress }); notification.success("Proposal submitted successfully!"); router.push("/"); diff --git a/packages/nextjs/app/my-grants/page.tsx b/packages/nextjs/app/my-grants/page.tsx index 19565aad..070a5f44 100644 --- a/packages/nextjs/app/my-grants/page.tsx +++ b/packages/nextjs/app/my-grants/page.tsx @@ -40,12 +40,14 @@ const MyGrants: NextPage = () => { {grant.title} ({grant.id}) -
- ETH Icon - - {grant.askAmount} ETH - -
+ {grant.status !== PROPOSAL_STATUS.PROPOSED && ( +
+ ETH Icon + + {grant.askAmount} ETH + +
+ )}

{grant.description}

{grant.status}

{grant.status === PROPOSAL_STATUS.APPROVED && ( diff --git a/packages/nextjs/utils/eip712.ts b/packages/nextjs/utils/eip712.ts index 7d03877c..86f1e3df 100644 --- a/packages/nextjs/utils/eip712.ts +++ b/packages/nextjs/utils/eip712.ts @@ -1,16 +1,12 @@ -import scaffoldConfig from "~~/scaffold.config"; - export const EIP_712_DOMAIN = { name: "BuidlGuidl Grants", version: "1", - chainId: scaffoldConfig.targetNetworks[0].id, } as const; export const EIP_712_TYPES__APPLY_FOR_GRANT = { Message: [ { name: "title", type: "string" }, { name: "description", type: "string" }, - { name: "askAmount", type: "string" }, ], } as const;