diff --git a/web/account/log-in-form.css b/web/account/log-in-form.css index 9aa1dbe83..ade93a03f 100644 --- a/web/account/log-in-form.css +++ b/web/account/log-in-form.css @@ -1,42 +1,45 @@ div.modal_body { display: flex; flex-direction: column; + justify-content: center; + min-height: 324px; + min-width: 320px; padding: 20px 40px; border-radius: 16px; background-color: var(--modal-bg); box-shadow: 0 0 40px rgba(126, 87, 194, 0.5); } div.form_title { padding: 6px 6px 0 0; font-size: var(--s-font-14); font-weight: var(--bold); color: var(--fg); } div.form_content { margin-top: 4px; margin-bottom: 8px; font-family: var(--font-stack); color: var(--fg); } div.form_footer { display: flex; flex-direction: column; margin-top: 16px; } div.form_footer > button:disabled { min-height: 48px; opacity: 0.5; } div.modal_form_error { margin-top: 16px; font-size: 14px; color: var(--error); font-style: italic; padding-left: 6px; align-self: center; } diff --git a/web/account/log-in-form.react.js b/web/account/log-in-form.react.js index c922b730a..4f2d37f0c 100644 --- a/web/account/log-in-form.react.js +++ b/web/account/log-in-form.react.js @@ -1,48 +1,60 @@ // @flow import { useConnectModal } from '@rainbow-me/rainbowkit'; import * as React from 'react'; import { useSigner } from 'wagmi'; import { isDev } from 'lib/utils/dev-utils'; import css from './log-in-form.css'; import SIWEButton from './siwe-button.react.js'; import SIWELoginForm from './siwe-login-form.react.js'; import TraditionalLoginForm from './traditional-login-form.react.js'; function LoginForm(): React.Node { const { openConnectModal } = useConnectModal(); const { data: signer } = useSigner(); const [ siweAuthFlowSelected, setSIWEAuthFlowSelected, ] = React.useState(false); const onSIWEButtonClick = React.useCallback(() => { setSIWEAuthFlowSelected(true); openConnectModal && openConnectModal(); }, [openConnectModal]); const cancelSIWEAuthFlow = React.useCallback(() => { setSIWEAuthFlowSelected(false); }, []); - let siweSection; + let siweLoginForm, siweButton; if (isDev && siweAuthFlowSelected && signer) { - siweSection = ; + siweLoginForm = ; } else if (isDev) { - siweSection = ; + siweButton = ; + } + + if (siweLoginForm) { + return
{siweLoginForm}
; + } + + if (siweButton) { + return ( +
+ +
+ {siweButton} +
+ ); } return (
- {siweSection ?
: null} - {siweSection}
); } export default LoginForm; diff --git a/web/account/siwe-login-form.react.js b/web/account/siwe-login-form.react.js index f8c24a6ae..7f146a0dd 100644 --- a/web/account/siwe-login-form.react.js +++ b/web/account/siwe-login-form.react.js @@ -1,159 +1,159 @@ // @flow import '@rainbow-me/rainbowkit/dist/index.css'; import olm from '@matrix-org/olm'; import { ConnectButton } from '@rainbow-me/rainbowkit'; import invariant from 'invariant'; import * as React from 'react'; import { useDispatch } from 'react-redux'; import { useAccount, useSigner } from 'wagmi'; import { getSIWENonce, getSIWENonceActionTypes, siweAuth, siweAuthActionTypes, } from 'lib/actions/siwe-actions'; import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors'; import type { LogInStartingPayload } from 'lib/types/account-types.js'; import { useDispatchActionPromise, useServerCall, } from 'lib/utils/action-utils'; import { createSIWEMessage, getSIWEStatementForPublicKey, siweMessageSigningExplanationStatements, } from 'lib/utils/siwe-utils.js'; import Button from '../components/button.react'; import LoadingIndicator from '../loading-indicator.react'; import { setPrimaryIdentityPublicKey } from '../redux/primary-identity-public-key-reducer'; import { useSelector } from '../redux/redux-utils'; import { webLogInExtraInfoSelector } from '../selectors/account-selectors.js'; import css from './siwe.css'; type SIWELoginFormProps = { +cancelSIWEAuthFlow: () => void, }; const getSIWENonceLoadingStatusSelector = createLoadingStatusSelector( getSIWENonceActionTypes, ); function SIWELoginForm(props: SIWELoginFormProps): React.Node { const { address } = useAccount(); const { data: signer } = useSigner(); const dispatch = useDispatch(); const dispatchActionPromise = useDispatchActionPromise(); const getSIWENonceCall = useServerCall(getSIWENonce); const getSIWENonceCallLoadingStatus = useSelector( getSIWENonceLoadingStatusSelector, ); const siweAuthCall = useServerCall(siweAuth); const logInExtraInfo = useSelector(webLogInExtraInfoSelector); const [siweNonce, setSIWENonce] = React.useState(null); const siweNonceShouldBeFetched = !siweNonce && getSIWENonceCallLoadingStatus !== 'loading'; React.useEffect(() => { if (!siweNonceShouldBeFetched) { return; } dispatchActionPromise( getSIWENonceActionTypes, (async () => { const response = await getSIWENonceCall(); setSIWENonce(response); })(), ); }, [dispatchActionPromise, getSIWENonceCall, siweNonceShouldBeFetched]); const primaryIdentityPublicKey = useSelector( state => state.primaryIdentityPublicKey, ); React.useEffect(() => { (async () => { await olm.init(); const account = new olm.Account(); account.create(); const { ed25519 } = JSON.parse(account.identity_keys()); dispatch({ type: setPrimaryIdentityPublicKey, payload: ed25519, }); })(); }, [dispatch]); const callSIWEAuthEndpoint = React.useCallback( (message: string, signature: string, extraInfo) => siweAuthCall({ message, signature, ...extraInfo, }), [siweAuthCall], ); const attemptSIWEAuth = React.useCallback( (message: string, signature: string) => { const extraInfo = logInExtraInfo(); dispatchActionPromise( siweAuthActionTypes, callSIWEAuthEndpoint(message, signature, extraInfo), undefined, ({ calendarQuery: extraInfo.calendarQuery }: LogInStartingPayload), ); }, [callSIWEAuthEndpoint, dispatchActionPromise, logInExtraInfo], ); const onSignInButtonClick = React.useCallback(async () => { invariant(signer, 'signer must be present during SIWE attempt'); invariant(siweNonce, 'nonce must be present during SIWE attempt'); invariant( primaryIdentityPublicKey, 'primaryIdentityPublicKey must be present during SIWE attempt', ); const statement = getSIWEStatementForPublicKey(primaryIdentityPublicKey); const message = createSIWEMessage(address, statement, siweNonce); const signature = await signer.signMessage(message); attemptSIWEAuth(message, signature); }, [address, attemptSIWEAuth, primaryIdentityPublicKey, signer, siweNonce]); const { cancelSIWEAuthFlow } = props; if (!siweNonce || !primaryIdentityPublicKey) { return ( -
- +
+
); } return (

{siweMessageSigningExplanationStatements[0]}

{siweMessageSigningExplanationStatements[1]}

By signing up, you agree to our{' '} Terms of Use &{' '} Privacy Policy.


); } export default SIWELoginForm; diff --git a/web/account/siwe.css b/web/account/siwe.css index e1def9f9a..afe2ca247 100644 --- a/web/account/siwe.css +++ b/web/account/siwe.css @@ -1,50 +1,55 @@ div.ethereumLogoContainer { display: flex; justify-content: center; align-content: center; margin: 0 4px; } hr { margin: 20px 0; height: 0; overflow: visible; text-align: center; border: none; border-top: #ffffff33 solid 1px; } hr:after { position: relative; top: -12px; padding: 0 8px; color: white; content: 'or'; background-color: #1f1f1fff; } div.siweLoginFormContainer p { color: white; font-family: sans-serif; text-align: center; padding-bottom: 20px; font-size: 14px; } div.siweLoginFormContainer { display: flex; flex-direction: column; } div.connectButtonContainer { width: 100%; display: flex; justify-content: center; align-content: center; padding-bottom: 20px; } +div.loadingIndicator { + display: flex; + justify-content: center; +} + div.siweContainer { display: flex; flex-direction: column; }