Page MenuHomePhabricator

D5978.id19978.diff
No OneTemporary

D5978.id19978.diff

diff --git a/landing/siwe.react.js b/landing/siwe.react.js
--- a/landing/siwe.react.js
+++ b/landing/siwe.react.js
@@ -5,6 +5,7 @@
getDefaultWallets,
RainbowKitProvider,
} from '@rainbow-me/rainbowkit';
+import invariant from 'invariant';
import * as React from 'react';
import { SiweMessage } from 'siwe';
import '@rainbow-me/rainbowkit/dist/index.css';
@@ -18,6 +19,7 @@
} from 'wagmi';
import { publicProvider } from 'wagmi/providers/public';
+import { SIWENonceContext } from './siwe-nonce-context.js';
import css from './siwe.css';
// details can be found https://wagmi.sh/docs/providers/configuring-chains
@@ -37,7 +39,8 @@
provider,
});
-function createSiweMessage(address, statement) {
+function createSiweMessage(address, statement, nonce) {
+ invariant(nonce, 'nonce must be present in createSiweMessage');
const domain = window.location.host;
const origin = window.location.origin;
const message = new SiweMessage({
@@ -47,14 +50,17 @@
uri: origin,
version: '1',
chainId: '1',
+ nonce,
});
return message.prepareMessage();
}
-async function signInWithEthereum(address, signer) {
+async function signInWithEthereum(address, signer, nonce) {
+ invariant(nonce, 'nonce must be present in signInWithEthereum');
const message = createSiweMessage(
address,
'By continuing, I accept the Comm Terms of Service: https://comm.app/terms',
+ nonce,
);
const signature = await signer.signMessage(message);
const messageToPost = JSON.stringify({ address, message, signature });
@@ -65,10 +71,20 @@
function SIWE(): React.Node {
const { address } = useAccount();
const { data: signer } = useSigner();
- const onClick = React.useCallback(() => signInWithEthereum(address, signer), [
- address,
- signer,
- ]);
+ const { siweNonce } = React.useContext(SIWENonceContext);
+ const onClick = React.useCallback(
+ () => signInWithEthereum(address, signer, siweNonce),
+ [address, signer, siweNonce],
+ );
+
+ if (siweNonce === null || siweNonce === undefined) {
+ return (
+ <div className={css.wrapper}>
+ <h1 className={css.h1}>Unable to proceed: nonce not found.</h1>
+ </div>
+ );
+ }
+
const SignInButton = !signer ? null : (
<div className={css.button} onClick={onClick}>
<img src="images/ethereum_icon.svg" style={ethIconStyle} />

File Metadata

Mime Type
text/plain
Expires
Fri, Dec 20, 1:47 AM (21 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2678412
Default Alt Text
D5978.id19978.diff (2 KB)

Event Timeline