From 7658eec9b95ad0fbc055b2391021784c471e06b6 Mon Sep 17 00:00:00 2001 From: fmtabbara Date: Thu, 9 Sep 2021 09:16:38 +0100 Subject: [PATCH] create account page --- tauri-wallet/src/context/main.tsx | 6 +- tauri-wallet/src/routes/create-account.tsx | 0 tauri-wallet/src/routes/index.tsx | 2 +- tauri-wallet/src/routes/sign-in.tsx | 232 +++++++++++++-------- 4 files changed, 154 insertions(+), 86 deletions(-) delete mode 100644 tauri-wallet/src/routes/create-account.tsx diff --git a/tauri-wallet/src/context/main.tsx b/tauri-wallet/src/context/main.tsx index d5ed5001dc..48bee15883 100644 --- a/tauri-wallet/src/context/main.tsx +++ b/tauri-wallet/src/context/main.tsx @@ -1,6 +1,6 @@ -import { invoke } from '@tauri-apps/api' -import React, { createContext, useCallback, useEffect, useState } from 'react' +import React, { createContext, useEffect, useState } from 'react' import { useHistory } from 'react-router-dom' +import { invoke } from '@tauri-apps/api' import { Coin, TClientDetails } from '../types' type TClientContext = { @@ -23,7 +23,7 @@ export const ClientContextProvider = ({ const history = useHistory() useEffect(() => { - !clientDetails ? history.push('/signin') : history.push('/bond') + !clientDetails ? history.push('/signin') : history.push('/balance') }, [clientDetails]) const logIn = async (clientDetails: TClientDetails) => { diff --git a/tauri-wallet/src/routes/create-account.tsx b/tauri-wallet/src/routes/create-account.tsx deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tauri-wallet/src/routes/index.tsx b/tauri-wallet/src/routes/index.tsx index a90d313d39..6450688f0b 100644 --- a/tauri-wallet/src/routes/index.tsx +++ b/tauri-wallet/src/routes/index.tsx @@ -13,7 +13,7 @@ import { InternalDocs } from './internal-docs' export const Routes = () => ( - + diff --git a/tauri-wallet/src/routes/sign-in.tsx b/tauri-wallet/src/routes/sign-in.tsx index ce21aeeab3..2c11b1300d 100644 --- a/tauri-wallet/src/routes/sign-in.tsx +++ b/tauri-wallet/src/routes/sign-in.tsx @@ -1,4 +1,5 @@ import React, { useContext, useState } from 'react' +import { useHistory } from 'react-router-dom' import { TextField, CircularProgress, @@ -11,39 +12,15 @@ import { } from '@material-ui/core' import { Alert } from '@material-ui/lab' import { useTheme } from '@material-ui/styles' +import { ArrowBack } from '@material-ui/icons' import { invoke } from '@tauri-apps/api' import logo from '../images/logo-background.svg' import { ClientContext } from '../context/main' import { TClientDetails } from '../types/global' export const SignIn = () => { - const [mnemonic, setMnemonic] = useState( - 'alley mutual arrange escape army vacuum cherry ozone frame steel current smile dad subject primary foster lazy want perfect fury general eye cannon motor' - ) - const [inputError, setInputError] = useState() - const [isLoading, setIsLoading] = useState(false) - - const { logIn } = useContext(ClientContext) - const theme: Theme = useTheme() - - const handleSignIn = async (e: React.FormEvent) => { - e.preventDefault() - - setIsLoading(true) - setInputError(undefined) - - invoke('connect_with_mnemonic', { mnemonic }) - .then((res) => { - setIsLoading(false) - logIn(res as TClientDetails) - }) - .catch((e) => { - setIsLoading(false) - setInputError(e) - }) - } - + const [showCreateAccount, setShowCreateAccount] = useState(false) return (
{ background: theme.palette.grey[100], }} > - - Sign in -
- - - ) => - setMnemonic(e.target.value) - } - size="medium" - variant="outlined" - margin="normal" - required - fullWidth - id="mnemonic" - label="BIP-39 Mnemonic" - name="mnemonic" - autoComplete="mnemonic" - autoFocus - disabled={isLoading} - /> - - - - - {inputError && ( - - {inputError} - - )} - - - Don't have an account? - {' '} - Create one - - -
-
+ {showCreateAccount ? ( + setShowCreateAccount(false)} + /> + ) : ( + setShowCreateAccount(true)} /> + )}
) } + +const SignInContent = ({ + showCreateAccount, +}: { + showCreateAccount: () => void +}) => { + const [mnemonic, setMnemonic] = useState( + 'alley mutual arrange escape army vacuum cherry ozone frame steel current smile dad subject primary foster lazy want perfect fury general eye cannon motor' + ) + const [inputError, setInputError] = useState() + const [isLoading, setIsLoading] = useState(false) + + const { logIn } = useContext(ClientContext) + + const theme: Theme = useTheme() + + const handleSignIn = async (e: React.FormEvent) => { + e.preventDefault() + + setIsLoading(true) + setInputError(undefined) + + invoke('connect_with_mnemonic', { mnemonic }) + .then((res) => { + setIsLoading(false) + logIn(res as TClientDetails) + }) + .catch((e) => { + setIsLoading(false) + setInputError(e) + }) + } + + return ( + + Sign in +
+ + + ) => + setMnemonic(e.target.value) + } + size="medium" + variant="outlined" + margin="normal" + required + fullWidth + id="mnemonic" + label="BIP-39 Mnemonic" + name="mnemonic" + autoComplete="mnemonic" + autoFocus + disabled={isLoading} + /> + + + + + {inputError && ( + + {inputError} + + )} + + + Don't have an account? + {' '} + + Create one + + + +
+
+ ) +} + +const CreateAccountContent = ({ showSignIn }: { showSignIn: () => void }) => { + const theme: Theme = useTheme() + return ( + <> + + + Create wallet + + + + Create an new wallet to start using the Nym network + + + + + + + + + + + + ) +}