diff --git a/packages/nextjs/app/registration/page.tsx b/packages/nextjs/app/registration/page.tsx index 527b678..c23b468 100644 --- a/packages/nextjs/app/registration/page.tsx +++ b/packages/nextjs/app/registration/page.tsx @@ -2,35 +2,61 @@ import { Wallet, hashMessage } from "ethers"; import { useRouter } from "next/navigation"; +import { useState } from "react"; +import { useEffect } from "react"; import { FormProvider, useForm } from "react-hook-form"; +import NestedLayoutForWallet from "~~/components/NestedLayoutForWallet"; import TextInput from "~~/components/scaffold-eth/Input/TextInput"; import { useScaffoldContractWrite } from "~~/hooks/scaffold-eth"; -import NestedLayoutForWallet from "~~/components/NestedLayoutForWallet";   export default function Home() { const methods = useForm(); const router = useRouter(); + const [text, setText] = useState(""); + const [showModal, setShowModal] = useState(false); + const [extractedWords, setExtractedWords] = useState([]); + const [isSubmitting, setIsSubmitting] = useState(false); + const [progress, setProgress] = useState(0); + + const handleSubmission = () => { + setIsSubmitting(true); + + setProgress(0); + const words = text.match(/@\w+/) || []; + + setExtractedWords(words as string[]); + const intervalId = setInterval(() => { + setProgress((prevProgress) => { + if (prevProgress < 100) { + return prevProgress + 1; + } + clearInterval(intervalId); + return prevProgress; + }); + }, 100); + + setTimeout(() => { + clearInterval(intervalId); + setIsSubmitting(false); + }, 10000); + }; + const { writeAsync, isLoading } = useScaffoldContractWrite({ contractName: "UrbanOdyssey", functionName: "registerPlayer", args: ["", "", "0x", "0x", 1], onBlockConfirmation: (txnReceipt) => { - router.push("/dashboard"); + setShowModal(true); }, }); - + const onSubmit = async (data: any) => { - console.log("Register button clicked"); const msg = `Register`; const msgHash = hashMessage(msg); const privateKey = process.env.NEXT_PUBLIC_PRIVATE_KEY || ""; const wallet = new Wallet(privateKey); const signature = await wallet.signMessage(arrayify(msgHash)); - console.log({ - msgHash: msgHash, - signature: signature, - }); - + if (msgHash && signature) { writeAsync({ args: [ @@ -41,61 +67,119 @@ export default function Home() { parseInt(data.team), ], }); - console.log("Data submitted", data); + } }; return ( -
- -
-
- {/* Existing TextInput fields */} - - - +
+ +
- - Faction - - - + + + +
+ + Faction + + + +
-
-
- ) : ( - <>Register + <> + + )} - -
- - -
+
+ {showModal && ( +
+
+ +
+ +
+ +
+ + {isSubmitting && ( +
+
+
+ )} + {progress === 100 && extractedWords.length > 0 && ( +
{extractedWords[0]}
+ )} +
+ )} + + +
); }