Skip to content

Commit d580fe0

Browse files
committed
Customize faucet claim amount for various chains (#5143)
<!-- start pr-codex --> ## PR-Codex overview This PR focuses on updating the `FaucetButton` and related components to use dynamic claim amounts based on the `chainId`, replacing hardcoded values with a function that retrieves the appropriate amount. ### Detailed summary - Changed `amount` type from `string` to `number` in `FaucetButton.tsx`. - Introduced `customClaimAmounts` and `defaultClaimAmount` in `claim-amount.ts`. - Updated `FaucetSection` and `GetFundsFromFaucet` to use `getFaucetClaimAmount`. - Modified API response in `route.ts` to return dynamic claim amounts. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 7a1099b commit d580fe0

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function FaucetButton({
4747
amount,
4848
}: {
4949
chain: ChainMetadata;
50-
amount: string;
50+
amount: number;
5151
}) {
5252
const client = useThirdwebClient();
5353
const address = useActiveAccount()?.address;

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/(chainPage)/components/server/FaucetSection.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import type { ChainMetadata } from "thirdweb/chains";
2+
import { getFaucetClaimAmount } from "../../../../../../api/testnet-faucet/claim/claim-amount";
23
import { ChainIcon } from "../../../../components/server/chain-icon";
34
import { FaucetButton } from "../client/FaucetButton";
45
import { GiftIcon } from "../icons/GiftIcon";
56
import { SectionTitle } from "./SectionTitle";
67

7-
const amountToGive = "0.01";
8-
98
export async function FaucetSection(props: { chain: ChainMetadata }) {
109
const { chain } = props;
1110

1211
// Check eligibilty.
1312
const sanitizedChainName = chain.name.replace("Mainnet", "").trim();
13+
const amountToGive = getFaucetClaimAmount(props.chain.chainId);
1414

1515
return (
1616
<section>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const customClaimAmounts: Record<number, number> = {
2+
// Aavegotchi Polter
3+
631571: 0.1,
4+
// Aleph Zero
5+
2039: 0.1,
6+
};
7+
8+
const defaultClaimAmount = 0.01;
9+
10+
export function getFaucetClaimAmount(chainId: number) {
11+
return customClaimAmounts[chainId] || defaultClaimAmount;
12+
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { startOfToday } from "date-fns";
22
import { cacheGet, cacheSet } from "lib/redis";
33
import { type NextRequest, NextResponse } from "next/server";
44
import { ZERO_ADDRESS } from "thirdweb";
5+
import { getFaucetClaimAmount } from "./claim-amount";
56

67
const THIRDWEB_ENGINE_URL = process.env.THIRDWEB_ENGINE_URL;
78
const NEXT_PUBLIC_THIRDWEB_ENGINE_FAUCET_WALLET =
@@ -109,6 +110,7 @@ export const POST = async (req: NextRequest) => {
109110
);
110111
const todayUTCSeconds = Math.floor(todayUTC.getTime() / 1000);
111112
const idempotencyKey = `${ipCacheKey}:${todayUTCSeconds}`;
113+
const amountToClaim = getFaucetClaimAmount(chainId).toString();
112114

113115
try {
114116
// Store the claim request for 24 hours.
@@ -129,7 +131,7 @@ export const POST = async (req: NextRequest) => {
129131
body: JSON.stringify({
130132
to: toAddress,
131133
currencyAddress: ZERO_ADDRESS,
132-
amount: "0.01",
134+
amount: amountToClaim,
133135
}),
134136
});
135137

@@ -144,5 +146,5 @@ export const POST = async (req: NextRequest) => {
144146
);
145147
}
146148

147-
return NextResponse.json({ amount: "0.01" }, { status: 200 });
149+
return NextResponse.json({ amount: amountToClaim }, { status: 200 });
148150
};

apps/dashboard/src/components/buttons/MismatchButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {
5151
} from "thirdweb/react";
5252
import { privateKeyToAccount } from "thirdweb/wallets";
5353
import { Button, type ButtonProps, Card, Heading, Text } from "tw-components";
54+
import { getFaucetClaimAmount } from "../../app/api/testnet-faucet/claim/claim-amount";
5455
import { THIRDWEB_API_HOST } from "../../constants/urls";
5556
import { useAllChainsData } from "../../hooks/chains/allChains";
5657
import { useV5DashboardChain } from "../../lib/v5-adapter";
@@ -354,8 +355,7 @@ function NoFundsDialogContent(props: {
354355
function GetFundsFromFaucet(props: {
355356
chain: ChainMetadata;
356357
}) {
357-
// TODO - improvement for later -> estimate gas required for transaction, and use that as the amount to give
358-
const amountToGive = "0.01";
358+
const amountToGive = getFaucetClaimAmount(props.chain.chainId);
359359

360360
return (
361361
<div className="flex justify-center rounded-lg border border-border px-4 py-6">

0 commit comments

Comments
 (0)