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.
Admin page actions (approve / reject) + EIP712
- Loading branch information
Showing
6 changed files
with
128 additions
and
10 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import { recoverTypedDataAddress } from "viem"; | ||
import { reviewGrant } from "~~/services/database/grants"; | ||
import { EIP_712_DOMAIN, EIP_712_TYPES__REVIEW_GRANT } from "~~/utils/eip712"; | ||
|
||
export async function POST(req: NextRequest, { params }: { params: { grantId: string } }) { | ||
const { grantId } = params; | ||
const { signature, signer, action } = await req.json(); | ||
|
||
// Validate Signature | ||
const recoveredAddress = await recoverTypedDataAddress({ | ||
domain: EIP_712_DOMAIN, | ||
types: EIP_712_TYPES__REVIEW_GRANT, | ||
primaryType: "Message", | ||
message: { | ||
grantId: grantId, | ||
action: action, | ||
}, | ||
signature, | ||
}); | ||
|
||
if (recoveredAddress !== signer) { | ||
console.error("Signature error", recoveredAddress, signer); | ||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); | ||
} | ||
|
||
try { | ||
await reviewGrant(grantId, action); | ||
} catch (error) { | ||
console.error("Error approving grant", error); | ||
return NextResponse.json({ error: "Error approving grant" }, { status: 500 }); | ||
} | ||
|
||
return NextResponse.json({ success: true }); | ||
} |
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
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,13 @@ | ||
export const EIP_712_DOMAIN = { | ||
name: "BuidlGuidl Grants", | ||
version: "1", | ||
chainId: 1, | ||
} as const; | ||
|
||
// ToDo. We could add more fields (grant title, builder, etc) | ||
export const EIP_712_TYPES__REVIEW_GRANT = { | ||
Message: [ | ||
{ name: "grantId", type: "string" }, | ||
{ name: "action", type: "string" }, | ||
], | ||
} as const; |
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,9 @@ | ||
export const PROPOSAL_STATUS = { | ||
PROPOSED: "proposed", | ||
APPROVED: "approved", | ||
SUBMITTED: "submitted", | ||
COMPLETED: "completed", | ||
REJECTED: "rejected", | ||
} as const; | ||
|
||
export type ProposalStatusType = (typeof PROPOSAL_STATUS)[keyof typeof PROPOSAL_STATUS]; |