diff --git a/webApp/components/Form.tsx b/webApp/components/Form.tsx deleted file mode 100644 index 6541ea6..0000000 --- a/webApp/components/Form.tsx +++ /dev/null @@ -1,58 +0,0 @@ -import React from "react"; -import Router from "next/router"; -import styles from "../styles/Home.module.css"; - -export default function Form() { - // return ( - //
- //
- // - // - // - //
- //
- // ) - // } - const inputRef = React.useRef(null); - const [loading, setLoading] = React.useState(false); - return ( -
-
Claim with address:
-
- {loading &&
Loading ... (it might take a minute)
}
-
- - - -
-
- ); -} diff --git a/webApp/components/ProofGenerator.tsx b/webApp/components/ProofGenerator.tsx new file mode 100644 index 0000000..633cba3 --- /dev/null +++ b/webApp/components/ProofGenerator.tsx @@ -0,0 +1,65 @@ +import React from "react"; +import Router from "next/router"; +import styles from "../styles/Home.module.css"; + +export default function ProofGenerator() { + const inputRef = React.useRef(null); + const [loading, setLoading] = React.useState(false); + // let [leaves, setLeaves] = useState([] as string[]); + + const checkAndGenerateProof = async (address: string) => { + setLoading(true); + try { + // // Get the merkle leaves + // useEffect(() => { + // fetch(CurrentConfig.MerkleTreePath) + // .then((r) => r.text()) + // .then((text) => { + // let leaves = text.split(","); + // setLeaves(leaves); + // }); + // }, []); + + const response = await fetch("/api/claim", { + method: "POST", + body: JSON.stringify({ + address: (inputRef.current as any)?.value, + }), + }); + const resJson = await response.json(); + console.log(resJson); + if (resJson.error) { + throw new Error(resJson.error); + } + Router.push("/Claimed"); + } catch (e) { + console.error(e); + Router.push("/Declined"); + } finally { + setLoading(false); + } + }; + + return ( +
+
Claim with address:
+
+ {loading &&
Loading ... (it might take a minute)
} +
+
+ + + +
+
+ ); +} diff --git a/webApp/pages/Claimed_Before.tsx b/webApp/pages/Claimed_Before.tsx index 2420d46..02e4d6f 100644 --- a/webApp/pages/Claimed_Before.tsx +++ b/webApp/pages/Claimed_Before.tsx @@ -1,6 +1,6 @@ import styles from "../styles/Home.module.css"; import React from "react"; -import Form from "../components/Form"; +import ProofGenerator from "../components/ProofGenerator"; import type { NextPage } from "next"; // import Router, { useRouter } from "next/router"; @@ -18,7 +18,7 @@ const Home: NextPage = () => {


-
+ ); diff --git a/webApp/pages/Declined.tsx b/webApp/pages/Declined.tsx index 667d6b6..0317951 100644 --- a/webApp/pages/Declined.tsx +++ b/webApp/pages/Declined.tsx @@ -1,6 +1,6 @@ import styles from "../styles/Home.module.css"; import React from "react"; -import Form from "../components/Form"; +import ProofGenerator from "../components/ProofGenerator"; import type { NextPage } from "next"; // import Router, { useRouter } from "next/router"; @@ -19,7 +19,7 @@ const Home: NextPage = () => {


- + ); diff --git a/webApp/pages/api/claim.ts b/webApp/pages/api/claim.ts index 8ebcadf..b6f968f 100644 --- a/webApp/pages/api/claim.ts +++ b/webApp/pages/api/claim.ts @@ -14,7 +14,7 @@ import { } from "defender-relay-client/lib/ethers"; import MerkleTree from "merkletreejs"; import keccak256 from "keccak256"; -import { existsSync, readFileSync } from "fs"; +import { readdir, readFileSync } from "fs"; import CollectorAbi from "../../abi/Collector.json"; import { MerkleProof } from "../../components/MerkleProof"; @@ -79,15 +79,34 @@ export default function handler( console.log("fullPath: ", fullPath); + console.log("process.cwd(): ", process.cwd()); + console.log("files in current directory:"); + readdir(process.cwd(), (err, files) => { + files.forEach((file) => { + console.log(file); + }); + }); + + console.log("files in private directory:"); + readdir(path.join(process.cwd(), "private"), (err, files) => { + files.forEach((file) => { + console.log(file); + }); + }); + let addressesArray = readFileSync(fullPath).toString().split(","); + console.log("Loaded file: ", addressesArray.length, " addresses."); if (!addressesArray.includes(address)) { return res .status(400) .json({ data: `${address} is not in the merkle tree` }); } - + console.log("Address found in array."); // generate merkle proof let [proof, root] = generateMerkleProof(address, addressesArray); + console.log("Merkle proof generated."); + console.log("proof: ", proof); + console.log("root: ", root); // create signer let provider: providers.Provider; diff --git a/webApp/pages/index.tsx b/webApp/pages/index.tsx index 3321aad..0adb8f0 100644 --- a/webApp/pages/index.tsx +++ b/webApp/pages/index.tsx @@ -1,11 +1,11 @@ import { ConnectButton } from "@rainbow-me/rainbowkit"; import React, { useState, useEffect } from "react"; import type { NextPage } from "next"; -import Image from 'next/image' -import Link from "next/link" +import Image from "next/image"; +import Link from "next/link"; import Router, { useRouter } from "next/router"; import Head from "next/head"; -import Form from '../components/Form'; +import ProofGenerator from "../components/ProofGenerator"; import styles from "../styles/Home.module.css"; import { MerkleProof } from "../components/MerkleProof"; @@ -56,70 +56,85 @@ const Home: NextPage = () => { /> - +

GOERLINATOR

-

terminating your GoerliETH shortage

+

+ terminating your GoerliETH shortage +

Goerlinator {/* */}
- Addresses that had at least one POAP before March 1, 2023 are eligible for a one-time 50 GoerliETH claim. + Addresses that had at least one POAP before March 1, 2023 are eligible + for a one-time 50 GoerliETH claim.
- +
); }; - - export default Home;