From c88e887dad271c39c2494e3d70b9fb31d51bf4cc Mon Sep 17 00:00:00 2001 From: Marcus Molchany Date: Fri, 14 Oct 2022 21:03:49 -0700 Subject: [PATCH] add support for message query param --- src/components/SignatureForm.tsx | 12 +++++++++--- src/routes/Sign.tsx | 6 +++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/components/SignatureForm.tsx b/src/components/SignatureForm.tsx index 52e5527..4ce710a 100644 --- a/src/components/SignatureForm.tsx +++ b/src/components/SignatureForm.tsx @@ -1,5 +1,5 @@ import { utils as ethersUtils } from "ethers"; -import { ChangeEvent, useMemo, useState } from "react"; +import { ChangeEvent, ReactElement, useMemo, useState } from "react"; import { useAccount, useSignMessage } from "wagmi"; import { CopyButton } from "./CopyButton"; import { EmailButton } from "./EmailButton"; @@ -40,11 +40,17 @@ const getPremessage = ({ const INITIAL_MESSAGE = "hereby decree that this message has been signed by me.\n\nSigned using Wallet Sign"; -export function SignatureForm() { +type Props = { + initialMessage?: string; +}; + +export function SignatureForm({ + initialMessage = INITIAL_MESSAGE, +}: Props): ReactElement { const { address } = useAccount(); const { signMessageAsync } = useSignMessage(); const [name, setName] = useState(""); - const [message, setMessage] = useState(INITIAL_MESSAGE); + const [message, setMessage] = useState(initialMessage); const [messageThatWasSigned, setMessageThatWasSigned] = useState(""); const [signedMessage, setSignedMessage] = useState(""); const [hashedMessage, setHashedMessage] = useState(""); diff --git a/src/routes/Sign.tsx b/src/routes/Sign.tsx index aa918b6..372506c 100644 --- a/src/routes/Sign.tsx +++ b/src/routes/Sign.tsx @@ -1,5 +1,9 @@ +import { useSearchParams } from "react-router-dom"; import { SignatureForm } from "../components/SignatureForm"; export function Sign() { - return ; + const [searchParams] = useSearchParams(); + const message = searchParams.get("message") || undefined; + + return ; }