Skip to content

Commit

Permalink
add PreWrap component
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusmolchany committed Oct 15, 2022
1 parent c88e887 commit 3e48285
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 23 deletions.
9 changes: 9 additions & 0 deletions src/components/PreWrap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ReactElement } from "react";

type Props = {
children: string;
};

export function PreWrap({ children }: Props): ReactElement {
return <pre style={{ whiteSpace: "pre-wrap" }}>{children}</pre>;
}
5 changes: 3 additions & 2 deletions src/components/SignatureForm.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@
margin-top: 2rem;
}

.signatureForm_code {
.signatureForm_pre {
word-break: break-all;
word-wrap: break-word;
}

.signatureForm_code,
.signatureForm_pre,
.signatureForm_summary {
margin-bottom: 1rem;
}
44 changes: 24 additions & 20 deletions src/components/SignatureForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ChangeEvent, ReactElement, useMemo, useState } from "react";
import { useAccount, useSignMessage } from "wagmi";
import { CopyButton } from "./CopyButton";
import { EmailButton } from "./EmailButton";
import { PreWrap } from "./PreWrap";
import "./SignatureForm.css";
import { TweetButton } from "./TweetButton";

Expand All @@ -23,22 +24,25 @@ const getRandomName = (): string => {
};
const RANDOM_NAME = getRandomName();

const getPremessage = ({
const getPostmessage = ({
address,
name,
}: {
address?: string;
name?: string;
}): string => {
const addressAndOrName =
address || name
? `(${address && name ? `${address} ${name}` : address ? address : name})`
: "";
return `I ${addressAndOrName}`;
let postMessage = "";
if (address) {
postMessage += `\n\naddress: ${address}`;
}
if (name) {
postMessage += `\nname: ${name}`;
}
return postMessage;
};

const INITIAL_MESSAGE =
"hereby decree that this message has been signed by me.\n\nSigned using Wallet Sign";
"I hereby decree that this message has been signed by me.\n\nSigned using Wallet Sign";

type Props = {
initialMessage?: string;
Expand All @@ -55,12 +59,12 @@ export function SignatureForm({
const [signedMessage, setSignedMessage] = useState<string>("");
const [hashedMessage, setHashedMessage] = useState<string>("");

const preMessage = useMemo(
() => getPremessage({ address, name }),
const postMessage = useMemo(
() => getPostmessage({ address, name }),
[address, name]
);
const messageToSign = useMemo(
() => `${preMessage} ${message}`,
() => `${message}${postMessage}`,
[address, name, message]
);
const combinedMessages = useMemo(
Expand Down Expand Up @@ -128,8 +132,8 @@ export function SignatureForm({
value={message}
></textarea>
<h3>Message to sign</h3>
<div className="signatureForm_code">
<code>{messageToSign}</code>
<div className="signatureForm_pre">
<PreWrap>{messageToSign}</PreWrap>
</div>
<div className="signatureForm_buttonGroup flexEnd">
<button disabled={!signedMessage} onClick={onResetClick}>
Expand All @@ -150,8 +154,8 @@ export function SignatureForm({
<hr className="signatureForm_hr" />
<div>
<h3>Message:</h3>
<div className="signatureForm_code">
<code>{messageThatWasSigned}</code>
<div className="signatureForm_pre">
<PreWrap>{messageThatWasSigned}</PreWrap>
</div>
<div className="signatureForm_buttonGroup">
<CopyButton text={messageThatWasSigned} />
Expand All @@ -163,8 +167,8 @@ export function SignatureForm({
ℹ️ This is your wallet’s signature of the original message. This
proves that you signed the original message.
</p>
<div className="signatureForm_code">
<code>{signedMessage}</code>
<div className="signatureForm_pre">
<PreWrap>{signedMessage}</PreWrap>
</div>
<div className="signatureForm_buttonGroup">
<CopyButton text={signedMessage} />
Expand All @@ -186,8 +190,8 @@ export function SignatureForm({
message text string. It <i>does not</i> prove that you signed the
original message.
</p>
<div className="signatureForm_code">
<code>{hashedMessage}</code>
<div className="signatureForm_pre">
<PreWrap>{hashedMessage}</PreWrap>
</div>
<div className="signatureForm_buttonGroup">
<CopyButton text={hashedMessage} />
Expand All @@ -205,8 +209,8 @@ export function SignatureForm({
<h3>Message, signed message, and hashed unsigned message:</h3>
<details>
<summary className="signatureForm_summary">Expand</summary>
<div className="signatureForm_code">
<code>{combinedMessages}</code>
<div className="signatureForm_pre">
<PreWrap>{combinedMessages}</PreWrap>
</div>
</details>
<div className="signatureForm_buttonGroup">
Expand Down
2 changes: 1 addition & 1 deletion src/routes/Verify.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function Verify() {
return <h1>Verify</h1>;
return <p>Coming soon</p>;
}

0 comments on commit 3e48285

Please sign in to comment.