Skip to content

Commit 0df4275

Browse files
authored
monad-faucet-starter+-only (#6351)
1 parent 959712d commit 0df4275

File tree

4 files changed

+83
-30
lines changed

4 files changed

+83
-30
lines changed

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/(chainPage)/components/client/FaucetButton.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ export function FaucetButton({
237237

238238
{canClaimFaucetQuery.data.type === "unsupported-chain" &&
239239
"Faucet is empty right now"}
240+
241+
{canClaimFaucetQuery.data.type === "paid-plan-required" &&
242+
"Faucet is only available on Starter, Growth and Pro plans."}
240243
</Button>
241244
);
242245
}

apps/dashboard/src/app/api/testnet-faucet/can-claim/CanClaimResponseType.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ export type CanClaimResponseType =
77
| {
88
canClaim: false;
99
type: "unsupported-chain";
10+
}
11+
| {
12+
canClaim: false;
13+
type: "paid-plan-required";
1014
};

apps/dashboard/src/app/api/testnet-faucet/can-claim/route.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getTeams } from "@/api/team";
12
import {
23
DISABLE_FAUCET_CHAIN_IDS,
34
THIRDWEB_ACCESS_TOKEN,
@@ -46,6 +47,25 @@ export const GET = async (req: NextRequest) => {
4647
} catch {}
4748
}
4849

50+
// get the teams for the account
51+
const teams = await getTeams();
52+
if (!teams) {
53+
const res: CanClaimResponseType = {
54+
canClaim: false,
55+
type: "paid-plan-required",
56+
};
57+
return NextResponse.json(res);
58+
}
59+
60+
const hasPaidPlan = teams.some((team) => team.billingPlan !== "free");
61+
if (!hasPaidPlan) {
62+
const res: CanClaimResponseType = {
63+
canClaim: false,
64+
type: "paid-plan-required",
65+
};
66+
return NextResponse.json(res);
67+
}
68+
4969
if (
5070
!THIRDWEB_ENGINE_URL ||
5171
!THIRDWEB_ENGINE_FAUCET_WALLET ||

apps/dashboard/src/app/api/testnet-faucet/claim/route.ts

Lines changed: 56 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getTeams } from "@/api/team";
12
import { COOKIE_ACTIVE_ACCOUNT, COOKIE_PREFIX_TOKEN } from "@/constants/cookie";
23
import {
34
API_SERVER_URL,
@@ -53,36 +54,6 @@ export const POST = async (req: NextRequest) => {
5354
);
5455
}
5556

56-
// Make sure the connected wallet has a thirdweb account
57-
const accountRes = await fetch(`${API_SERVER_URL}/v1/account/me`, {
58-
method: "GET",
59-
headers: {
60-
Authorization: `Bearer ${authCookie.value}`,
61-
},
62-
});
63-
64-
if (accountRes.status !== 200) {
65-
// Account not found on this connected address
66-
return NextResponse.json(
67-
{
68-
error: "thirdweb account not found",
69-
},
70-
{ status: 400 },
71-
);
72-
}
73-
74-
const account: { data: Account } = await accountRes.json();
75-
76-
// Make sure the logged-in account has verified its email
77-
if (!account.data.email) {
78-
return NextResponse.json(
79-
{
80-
error: "Account owner hasn't verified email",
81-
},
82-
{ status: 400 },
83-
);
84-
}
85-
8657
const requestBody = (await req.json()) as RequestTestnetFundsPayload;
8758
const { chainId, toAddress, turnstileToken } = requestBody;
8859
if (Number.isNaN(chainId)) {
@@ -150,6 +121,61 @@ export const POST = async (req: NextRequest) => {
150121
);
151122
}
152123

124+
// Make sure the connected wallet has a thirdweb account
125+
const accountRes = await fetch(`${API_SERVER_URL}/v1/account/me`, {
126+
method: "GET",
127+
headers: {
128+
Authorization: `Bearer ${authCookie.value}`,
129+
},
130+
});
131+
132+
if (accountRes.status !== 200) {
133+
// Account not found on this connected address
134+
return NextResponse.json(
135+
{
136+
error: "thirdweb account not found",
137+
},
138+
{ status: 400 },
139+
);
140+
}
141+
142+
const account: { data: Account } = await accountRes.json();
143+
144+
// Make sure the logged-in account has verified its email
145+
if (!account.data.email) {
146+
return NextResponse.json(
147+
{
148+
error: "Account owner hasn't verified email",
149+
},
150+
{ status: 400 },
151+
);
152+
}
153+
154+
// get the teams for the account
155+
const teams = await getTeams();
156+
if (!teams) {
157+
return NextResponse.json(
158+
{
159+
error: "No teams found for this account.",
160+
},
161+
{
162+
status: 500,
163+
},
164+
);
165+
}
166+
// check if ANY of the customer's teams has "growth" or "pro" plan
167+
const hasPaidPlan = teams.some((team) => team.billingPlan !== "free");
168+
if (!hasPaidPlan) {
169+
return NextResponse.json(
170+
{
171+
error: "Free plan cannot claim on this chain.",
172+
},
173+
{
174+
status: 402,
175+
},
176+
);
177+
}
178+
153179
const ipCacheKey = `testnet-faucet:${chainId}:${ip}`;
154180
const addressCacheKey = `testnet-faucet:${chainId}:${toAddress}`;
155181
const accountCacheKey = `testnet-faucet:${chainId}:${account.data.id}`;

0 commit comments

Comments
 (0)