From bd87fff9f8549a7b1b3b179b271a17320d23f596 Mon Sep 17 00:00:00 2001 From: "ilge.ustun" Date: Mon, 11 Mar 2024 12:49:57 +0100 Subject: [PATCH] pre-filled form --- app/src/components/FaucetForm/Faucet.tsx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/src/components/FaucetForm/Faucet.tsx b/app/src/components/FaucetForm/Faucet.tsx index 4908ac0..6a9dd74 100644 --- a/app/src/components/FaucetForm/Faucet.tsx +++ b/app/src/components/FaucetForm/Faucet.tsx @@ -29,6 +29,13 @@ function Faucet({ enabledTokens, chainId, setLoading }: FaucetProps): JSX.Elemen useEffect(() => { const handleResize = () => setWindowWidth(window.innerWidth) window.addEventListener("resize", handleResize) + + const searchParams = new URLSearchParams(window.location.search) + const addressFromURL = searchParams.get("address") + if (addressFromURL) { + setWalletAddress(addressFromURL) + } + return () => window.removeEventListener("resize", handleResize) }, []) @@ -40,7 +47,16 @@ function Faucet({ enabledTokens, chainId, setLoading }: FaucetProps): JSX.Elemen name: enabledTokens[0].name, maximumAmount: Number(enabledTokens[0].maximumAmount) }) - } + } else { + const defaultToken = enabledTokens.find(token => token.address === "0x0000000000000000000000000000000000000000") + if (defaultToken !== undefined) { + setToken({ + address: defaultToken.address, + name: defaultToken.name, + maximumAmount: Number(defaultToken.maximumAmount) + }) + } + } }, [enabledTokens.length]) function formatErrors(errors: string[]) {