diff --git a/web/account/log-in-form.react.js b/web/account/log-in-form.react.js --- a/web/account/log-in-form.react.js +++ b/web/account/log-in-form.react.js @@ -23,6 +23,10 @@ import { alchemyProvider } from 'wagmi/providers/alchemy'; import { publicProvider } from 'wagmi/providers/public'; +import { + getSIWENonce, + getSIWENonceActionTypes, +} from 'lib/actions/siwe-actions.js'; import { logInActionTypes, logIn } from 'lib/actions/user-actions'; import { useModalContext } from 'lib/components/modal-provider.react'; import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors'; @@ -69,6 +73,9 @@ provider, }); +const getSIWENonceLoadingStatusSelector = createLoadingStatusSelector( + getSIWENonceActionTypes, +); const loadingStatusSelector = createLoadingStatusSelector(logInActionTypes); function LoginForm(): React.Node { const { openConnectModal } = useConnectModal(); @@ -76,12 +83,19 @@ const inputDisabled = useSelector(loadingStatusSelector) === 'loading'; const loginExtraInfo = useSelector(webLogInExtraInfoSelector); const callLogIn = useServerCall(logIn); + + const getSIWENonceCall = useServerCall(getSIWENonce); + const getSIWENonceCallLoadingStatus = useSelector( + getSIWENonceLoadingStatusSelector, + ); + const dispatchActionPromise = useDispatchActionPromise(); const modalContext = useModalContext(); const [username, setUsername] = React.useState(''); const [password, setPassword] = React.useState(''); const [errorMessage, setErrorMessage] = React.useState(''); + const [siweNonce, setSIWENonce] = React.useState(null); const usernameInputRef = React.useRef(); @@ -89,6 +103,20 @@ usernameInputRef.current?.focus(); }, []); + React.useEffect(() => { + if (!signer || !isDev) { + setSIWENonce(null); + return; + } + dispatchActionPromise( + getSIWENonceActionTypes, + (async () => { + const response = await getSIWENonceCall(); + setSIWENonce(response); + })(), + ); + }, [dispatchActionPromise, getSIWENonceCall, signer]); + const onUsernameChange = React.useCallback(e => { invariant(e.target instanceof HTMLInputElement, 'target not input'); setUsername(e.target.value); @@ -174,7 +202,16 @@ } let siweConnectButton; - if (isDev && signer) { + if (isDev && signer && !siweNonce) { + siweConnectButton = ( +
+ +
+ ); + } else if (isDev && signer) { siweConnectButton = (