Skip to content

Commit

Permalink
Hardcode askAmount in the backend
Browse files Browse the repository at this point in the history
  • Loading branch information
carletex committed Mar 22, 2024
1 parent 97cf564 commit 346ad39
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
15 changes: 6 additions & 9 deletions packages/nextjs/app/api/grants/new/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
});

Expand Down
6 changes: 2 additions & 4 deletions packages/nextjs/app/apply/_component/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { postMutationFetcher } from "~~/utils/swr";
type ReqBody = {
title?: string;
description?: string;
askAmount?: string;
signature?: `0x${string}`;
signer?: string;
};
Expand All @@ -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;
}
Expand All @@ -48,7 +46,7 @@ const Form = () => {
},
});

await postNewGrant({ title, description, askAmount, signature, signer: connectedAddress });
await postNewGrant({ title, description, signature, signer: connectedAddress });

notification.success("Proposal submitted successfully!");
router.push("/");
Expand Down

0 comments on commit 346ad39

Please sign in to comment.