Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3492431
D6225.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D6225.diff
View Options
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<string>('');
const [password, setPassword] = React.useState<string>('');
const [errorMessage, setErrorMessage] = React.useState<string>('');
+ const [siweNonce, setSIWENonce] = React.useState<?string>(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 = (
+ <div className={css.connectButtonContainer}>
+ <LoadingIndicator
+ status={getSIWENonceCallLoadingStatus}
+ size="medium"
+ />
+ </div>
+ );
+ } else if (isDev && signer) {
siweConnectButton = (
<div className={css.connectButtonContainer}>
<ConnectButton />
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 19, 11:52 PM (20 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2679219
Default Alt Text
D6225.diff (2 KB)
Attached To
Mode
D6225: [web] Conditionally display `ConnectButton` once `nonce` received from `keyserver`
Attached
Detach File
Event Timeline
Log In to Comment