Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dashboard] Improve faucet claim #5226

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion apps/dashboard/src/app/api/testnet-faucet/claim/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { COOKIE_ACTIVE_ACCOUNT, COOKIE_PREFIX_TOKEN } from "@/constants/cookie";
import { startOfToday } from "date-fns";
import { cacheGet, cacheSet } from "lib/redis";
import { type NextRequest, NextResponse } from "next/server";
import { ZERO_ADDRESS } from "thirdweb";
import { ZERO_ADDRESS, getAddress } from "thirdweb";
import { getFaucetClaimAmount } from "./claim-amount";

const THIRDWEB_ENGINE_URL = process.env.THIRDWEB_ENGINE_URL;
Expand All @@ -19,6 +20,20 @@ interface RequestTestnetFundsPayload {

// Note: This handler cannot use "edge" runtime because of Redis usage.
export const POST = async (req: NextRequest) => {
// Make sure user's connected to the site
const activeAccount = req.cookies.get(COOKIE_ACTIVE_ACCOUNT)?.value;
const authCookie = activeAccount
? req.cookies.get(COOKIE_PREFIX_TOKEN + getAddress(activeAccount))
: null;
if (!authCookie) {
return NextResponse.json(
{
error: "No wallet connected",
},
{ status: 400 },
);
}

const requestBody = (await req.json()) as RequestTestnetFundsPayload;
const { chainId, toAddress, turnstileToken } = requestBody;
if (Number.isNaN(chainId)) {
Expand Down