Skip to content

Commit f092b2a

Browse files
committed
chore: allow disabling a chain's faucet (#4556)
<!-- start pr-codex --> ## PR-Codex overview The focus of this PR is to add functionality to disable the faucet for specific chain IDs in the testnet-faucet API route. ### Detailed summary - Added `DISABLE_FAUCET_CHAIN_IDS` environment variable for comma-separated list of chain IDs to disable the faucet. - Implemented logic to check if the faucet is disabled for a specific chain ID before allowing claims. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent df42167 commit f092b2a

File tree

1 file changed

+16
-1
lines changed
  • apps/dashboard/src/app/api/testnet-faucet/can-claim

1 file changed

+16
-1
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const NEXT_PUBLIC_THIRDWEB_ENGINE_FAUCET_WALLET =
88
process.env.NEXT_PUBLIC_THIRDWEB_ENGINE_FAUCET_WALLET;
99
const THIRDWEB_ACCESS_TOKEN = process.env.THIRDWEB_ACCESS_TOKEN;
1010

11+
// Comma-separated list of chain IDs to disable faucet for.
12+
const DISABLE_FAUCET_CHAIN_IDS = process.env.DISABLE_FAUCET_CHAIN_IDS;
13+
1114
// Note: This handler cannot use "edge" runtime because of Redis usage.
1215
export const GET = async (req: NextRequest) => {
1316
const searchParams = req.nextUrl.searchParams;
@@ -33,10 +36,22 @@ export const GET = async (req: NextRequest) => {
3336
);
3437
}
3538

39+
// Check if faucet is disabled for this chain.
40+
let isFaucetDisabled = false;
41+
if (DISABLE_FAUCET_CHAIN_IDS) {
42+
try {
43+
const disableFaucetChainIds = DISABLE_FAUCET_CHAIN_IDS.split(",").map(
44+
(chainId) => Number.parseInt(chainId.trim()),
45+
);
46+
isFaucetDisabled = disableFaucetChainIds.includes(chainId);
47+
} catch {}
48+
}
49+
3650
if (
3751
!THIRDWEB_ENGINE_URL ||
3852
!NEXT_PUBLIC_THIRDWEB_ENGINE_FAUCET_WALLET ||
39-
!THIRDWEB_ACCESS_TOKEN
53+
!THIRDWEB_ACCESS_TOKEN ||
54+
isFaucetDisabled
4055
) {
4156
const res: CanClaimResponseType = {
4257
canClaim: false,

0 commit comments

Comments
 (0)