From 8517431e700e9504e5a54a4d4047c902eb5d46ea Mon Sep 17 00:00:00 2001 From: malteish Date: Sun, 5 Mar 2023 02:12:29 -0700 Subject: [PATCH 1/5] add logging --- webApp/pages/api/claim.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/webApp/pages/api/claim.ts b/webApp/pages/api/claim.ts index 8ebcadf..880e8e3 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,6 +79,21 @@ 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(","); if (!addressesArray.includes(address)) { return res From 644f5e06b3511ae77df03cafb36cea354e537d02 Mon Sep 17 00:00:00 2001 From: malteish Date: Sun, 5 Mar 2023 02:19:54 -0700 Subject: [PATCH 2/5] log --- webApp/pages/api/claim.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/webApp/pages/api/claim.ts b/webApp/pages/api/claim.ts index 880e8e3..79b8f7b 100644 --- a/webApp/pages/api/claim.ts +++ b/webApp/pages/api/claim.ts @@ -95,6 +95,7 @@ export default function handler( }); let addressesArray = readFileSync(fullPath).toString().split(","); + console.log("Loaded file: ", addressesArray.length, " addresses."); if (!addressesArray.includes(address)) { return res .status(400) From f86d39cd65823ec615c700ca30fbc961b2c08a22 Mon Sep 17 00:00:00 2001 From: malteish Date: Sun, 5 Mar 2023 02:30:23 -0700 Subject: [PATCH 3/5] more logs --- webApp/pages/api/claim.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/webApp/pages/api/claim.ts b/webApp/pages/api/claim.ts index 79b8f7b..b6f968f 100644 --- a/webApp/pages/api/claim.ts +++ b/webApp/pages/api/claim.ts @@ -101,9 +101,12 @@ export default function handler( .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; From 6757a06a495c8260ede6a23e96da8f44276b5558 Mon Sep 17 00:00:00 2001 From: malteish Date: Sun, 5 Mar 2023 02:46:21 -0700 Subject: [PATCH 4/5] rename form --- .../{Form.tsx => ProofGenerator.tsx} | 3 +- webApp/pages/Claimed_Before.tsx | 2 +- webApp/pages/Declined.tsx | 2 +- webApp/pages/index.tsx | 117 ++++++++++-------- 4 files changed, 70 insertions(+), 54 deletions(-) rename webApp/components/{Form.tsx => ProofGenerator.tsx} (95%) diff --git a/webApp/components/Form.tsx b/webApp/components/ProofGenerator.tsx similarity index 95% rename from webApp/components/Form.tsx rename to webApp/components/ProofGenerator.tsx index 6541ea6..152a0e8 100644 --- a/webApp/components/Form.tsx +++ b/webApp/components/ProofGenerator.tsx @@ -19,7 +19,8 @@ export default function Form() {
Claim with address:
- {loading &&
Loading ... (it might take a minute)
}
+ {loading &&
Loading ... (it might take a minute)
} +
diff --git a/webApp/pages/Claimed_Before.tsx b/webApp/pages/Claimed_Before.tsx index 2420d46..bff06ab 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 Form from "../components/ProofGenerator"; import type { NextPage } from "next"; // import Router, { useRouter } from "next/router"; diff --git a/webApp/pages/Declined.tsx b/webApp/pages/Declined.tsx index 667d6b6..3628c74 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 Form from "../components/ProofGenerator"; import type { NextPage } from "next"; // import Router, { useRouter } from "next/router"; diff --git a/webApp/pages/index.tsx b/webApp/pages/index.tsx index 3321aad..72a32e1 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 Form 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; From ea6ae4ce6d5292afed93f071114eddfe7cf4e7c8 Mon Sep 17 00:00:00 2001 From: malteish Date: Sun, 5 Mar 2023 02:59:24 -0700 Subject: [PATCH 5/5] rename, move code --- webApp/components/ProofGenerator.tsx | 72 +++++++++++++++------------- webApp/pages/Claimed_Before.tsx | 4 +- webApp/pages/Declined.tsx | 4 +- webApp/pages/index.tsx | 4 +- 4 files changed, 45 insertions(+), 39 deletions(-) diff --git a/webApp/components/ProofGenerator.tsx b/webApp/components/ProofGenerator.tsx index 152a0e8..633cba3 100644 --- a/webApp/components/ProofGenerator.tsx +++ b/webApp/components/ProofGenerator.tsx @@ -2,19 +2,44 @@ import React from "react"; import Router from "next/router"; import styles from "../styles/Home.module.css"; -export default function Form() { - // return ( - // - //
- // - // - // - //
- // - // ) - // } +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:
@@ -28,28 +53,9 @@ export default function Form() { className={styles.formButton} type="submit" disabled={loading || (inputRef.current as any)?.value === ""} - onClick={async () => { - setLoading(true); - try { - 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); - } - }} + onClick={() => + checkAndGenerateProof((inputRef.current as any)?.value) + } > Claim diff --git a/webApp/pages/Claimed_Before.tsx b/webApp/pages/Claimed_Before.tsx index bff06ab..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/ProofGenerator"; +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 3628c74..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/ProofGenerator"; +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/index.tsx b/webApp/pages/index.tsx index 72a32e1..0adb8f0 100644 --- a/webApp/pages/index.tsx +++ b/webApp/pages/index.tsx @@ -5,7 +5,7 @@ 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/ProofGenerator"; +import ProofGenerator from "../components/ProofGenerator"; import styles from "../styles/Home.module.css"; import { MerkleProof } from "../components/MerkleProof"; @@ -74,7 +74,7 @@ const Home: NextPage = () => { for a one-time 50 GoerliETH claim.
- +