// @flow import * as React from 'react'; import Page from 'component/page'; import Card from 'component/common/card'; import Button from 'component/button'; import { Form, FormField } from 'component/common/form'; import I18nMessage from 'component/i18nMessage'; import Spinner from 'component/spinner'; import * as ICONS from 'constants/icons'; type Props = { walletEncrypted: boolean, encryptWallet: (string) => void, decryptWallet: (string) => void, registering: boolean, email: string, registerError: string, token: string, authenticating: boolean, authError: string, derivingKeys: boolean, encHmacKey: string, // ? encRootPass: string, encProviderPass: string, getSalt: (string) => void, gettingSalt: boolean, saltError: string, saltSeed: string, deriveSecrets: (string, string, string) => void, // something }; export default function NotificationSettingsPage(props: Props) { // const { } = props; const { walletEncrypted, encryptWallet, decryptWallet, registering, registeredEmail, registerError, token, authenticating, authError, authenticate, derivingKeys, encHmacKey, // ? encRootPass, encProviderPass, getSalt, generateSaltSeed, deriveSecrets, gettingSalt, saltError, saltSeed, register, } = props; const SIGN_IN_MODE = 'sign_in'; const SIGN_UP_MODE = 'sign_up'; const VERIFY_MODE = 'verify'; const MATH_MODE = 'math'; const DONE_MODE = 'done'; const [mode, setMode] = React.useState(registeredEmail ? VERIFY_MODE : SIGN_IN_MODE); const [email, setEmail] = React.useState(); const [pass, setPass] = React.useState(); const [showPass, setShowPass] = React.useState(false); const [error, setError] = React.useState(''); React.useEffect(() => { let interval; if (!token && registeredEmail) { interval = setInterval(() => { console.log('doauthint'); authenticate(); }, 5000); } return () => { clearInterval(interval); }; }, [registeredEmail, token, authenticate]); React.useEffect(() => { if (token && registeredEmail) { setMode(DONE_MODE); } }, [registeredEmail, token, setMode]); const handleSignUp = async () => { // get salt for email to make sure const saltSeedOrError = await getSalt(email); if (saltSeedOrError.seed) { setError('Email already registered'); return; } // -- if found, report email already exists - sign in? const saltSeed = await generateSaltSeed(); // saltSeed = generateSaltSeed() setMode(MATH_MODE); const secrets = await deriveSecrets(pass, email, saltSeed); setMode(VERIFY_MODE); // passwords = driveKeys(root, email, saltSeed); try { const registerSuccess = await register(email, secrets, saltSeed); } catch (e) { console.log(e); } // registerSuccess = register(email, servicePassword, saltSeed) // poll auth until success // store [token, rootPassword, providerPass, HmacKey, saltSeed, salt, registeredEmail] }; const handleSignIn = async () => { // get saltseed for email // saltSeed = getSaltSeed() // -- if error, report email not registered - sign up? // salt = generateSalt(seed) // passwords = deriveKeys(root, email, saltSeed); // token = authenticate(email, servicePassword, deviceId) // store [token, rootPassword, servicePassword, HmacKey, saltSeed, salt, registeredEmail] // kick off sync pull // -- possibly merge conflicts }; const doneCard = ( You are signed in as %email%. } actions={
Like, done and stuff...
} /> ); const verifyCard = ( Waiting for verification...} /> ); const deriveCard = ( Math...} /> ); const signInCard = (

setMode(SIGN_UP_MODE)} label={__('Sign up')} />, }} > Sign in to your sync account. Or %sign_up%.

} actions={
setEmail(e.target.value)} />

, }} > By creating an account, you agree to our %terms% and confirm you're over the age of 13.

} /> ); const signUpCard = (

setMode(SIGN_UP_MODE)} label={__('Sign in')} />, }} > Sign up for a sync account. Or %sign_in%.

} actions={
setEmail(e.target.value)} />

, }} > By creating an account, you agree to our %terms% and confirm you're over the age of 13.

} /> ); return (
{mode === DONE_MODE && <>{doneCard}} {mode === SIGN_IN_MODE && <>{signInCard}} {mode === SIGN_UP_MODE && <>{signUpCard}} {mode === MATH_MODE && <>{deriveCard}} {mode === VERIFY_MODE && <>{verifyCard}}
); }