Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function FaucetButton({
amount,
}: {
chain: ChainMetadata;
amount: string;
amount: number;
}) {
const client = useThirdwebClient();
const address = useActiveAccount()?.address;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type { ChainMetadata } from "thirdweb/chains";
import { getFaucetClaimAmount } from "../../../../../../api/testnet-faucet/claim/claim-amount";
import { ChainIcon } from "../../../../components/server/chain-icon";
import { FaucetButton } from "../client/FaucetButton";
import { GiftIcon } from "../icons/GiftIcon";
import { SectionTitle } from "./SectionTitle";

const amountToGive = "0.01";

export async function FaucetSection(props: { chain: ChainMetadata }) {
const { chain } = props;

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

return (
<section>
Expand Down
12 changes: 12 additions & 0 deletions apps/dashboard/src/app/api/testnet-faucet/claim/claim-amount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const customClaimAmounts: Record<number, number> = {
// Aavegotchi Polter
631571: 0.1,
// Aleph Zero
2039: 0.1,
};

const defaultClaimAmount = 0.01;

export function getFaucetClaimAmount(chainId: number) {
return customClaimAmounts[chainId] || defaultClaimAmount;
}
6 changes: 4 additions & 2 deletions apps/dashboard/src/app/api/testnet-faucet/claim/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { startOfToday } from "date-fns";
import { cacheGet, cacheSet } from "lib/redis";
import { type NextRequest, NextResponse } from "next/server";
import { ZERO_ADDRESS } from "thirdweb";
import { getFaucetClaimAmount } from "./claim-amount";

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

try {
// Store the claim request for 24 hours.
Expand All @@ -129,7 +131,7 @@ export const POST = async (req: NextRequest) => {
body: JSON.stringify({
to: toAddress,
currencyAddress: ZERO_ADDRESS,
amount: "0.01",
amount: amountToClaim,
}),
});

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

return NextResponse.json({ amount: "0.01" }, { status: 200 });
return NextResponse.json({ amount: amountToClaim }, { status: 200 });
};
4 changes: 2 additions & 2 deletions apps/dashboard/src/components/buttons/MismatchButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
} from "thirdweb/react";
import { privateKeyToAccount } from "thirdweb/wallets";
import { Button, type ButtonProps, Card, Heading, Text } from "tw-components";
import { getFaucetClaimAmount } from "../../app/api/testnet-faucet/claim/claim-amount";
import { THIRDWEB_API_HOST } from "../../constants/urls";
import { useAllChainsData } from "../../hooks/chains/allChains";
import { useV5DashboardChain } from "../../lib/v5-adapter";
Expand Down Expand Up @@ -354,8 +355,7 @@ function NoFundsDialogContent(props: {
function GetFundsFromFaucet(props: {
chain: ChainMetadata;
}) {
// TODO - improvement for later -> estimate gas required for transaction, and use that as the amount to give
const amountToGive = "0.01";
const amountToGive = getFaucetClaimAmount(props.chain.chainId);

return (
<div className="flex justify-center rounded-lg border border-border px-4 py-6">
Expand Down
Loading