diff --git a/tauri-wallet/src/context/main.tsx b/tauri-wallet/src/context/main.tsx index 4ce551617a..962c721dee 100644 --- a/tauri-wallet/src/context/main.tsx +++ b/tauri-wallet/src/context/main.tsx @@ -1,14 +1,13 @@ import React, { createContext, useEffect, useState } from 'react' import { useHistory } from 'react-router-dom' -import { invoke } from '@tauri-apps/api' -import { Coin, TClientDetails } from '../types' +import { Coin, TClientDetails, TSignInWithMnemonic } from '../types' import { TUseGetBalance, useGetBalance } from '../hooks/useGetBalance' type TClientContext = { clientDetails?: TClientDetails gasPrice?: Coin getBalance: TUseGetBalance - logIn: (clientDetails: TClientDetails) => void + logIn: (clientDetails: TSignInWithMnemonic) => void logOut: () => void } @@ -30,12 +29,8 @@ export const ClientContextProvider = ({ !clientDetails ? history.push('/signin') : history.push('/balance') }, [clientDetails]) - const logIn = async (clientDetails: TClientDetails) => { - await invoke('get_gas_price') - .then((res) => setGasPrice(res as Coin)) - .catch((e) => console.log(e)) + const logIn = async (clientDetails: TSignInWithMnemonic) => setClientDetails(clientDetails) - } const logOut = () => setClientDetails(undefined) diff --git a/tauri-wallet/src/requests/index.ts b/tauri-wallet/src/requests/index.ts new file mode 100644 index 0000000000..7aa82a891f --- /dev/null +++ b/tauri-wallet/src/requests/index.ts @@ -0,0 +1,10 @@ +import { invoke } from '@tauri-apps/api' +import { TCreateAccount, TSignInWithMnemonic } from '../types' + +export const createAccount = async (): Promise => + await invoke('create_new_account') + +export const signInWithMnemonic = async ( + mnemonic: string +): Promise => + await invoke('connect_with_mnemonic', { mnemonic }) diff --git a/tauri-wallet/src/routes/sign-in.tsx b/tauri-wallet/src/routes/sign-in.tsx index 96e931c8f1..8f866c10ab 100644 --- a/tauri-wallet/src/routes/sign-in.tsx +++ b/tauri-wallet/src/routes/sign-in.tsx @@ -8,16 +8,19 @@ import { Link, Theme, Card, + Divider, } from '@material-ui/core' import { Alert } from '@material-ui/lab' import { useTheme } from '@material-ui/styles' -import { ArrowBack } from '@material-ui/icons' +import { ArrowBack, CheckCircleOutline } from '@material-ui/icons' import { invoke } from '@tauri-apps/api' import logo from '../images/logo-background.svg' import logo_alt from '../images/logo.png' import { ClientContext } from '../context/main' -import { TClientDetails } from '../types/global' import { theme } from '../theme' +import { createAccount, signInWithMnemonic } from '../requests' +import { TCreateAccount } from '../types' +import { CopyToClipboard } from '../components' export const SignIn = () => { const theme: Theme = useTheme() @@ -71,10 +74,8 @@ const SignInContent = ({ }: { 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 [mnemonic, setMnemonic] = useState() + const [inputError, setInputError] = useState() const [isLoading, setIsLoading] = useState(false) const { logIn } = useContext(ClientContext) @@ -87,15 +88,14 @@ const SignInContent = ({ setIsLoading(true) setInputError(undefined) - invoke('connect_with_mnemonic', { mnemonic }) - .then((res) => { - setIsLoading(false) - logIn(res as TClientDetails) - }) - .catch((e) => { - setIsLoading(false) - setInputError(e) - }) + try { + const res = await signInWithMnemonic(mnemonic || '') + setIsLoading(false) + logIn(res) + } catch (e: any) { + setIsLoading(false) + setInputError(e) + } } return ( @@ -157,49 +157,6 @@ const SignInContent = ({ ) } -const CreateAccountContent = ({ showSignIn }: { showSignIn: () => void }) => { - return ( - - <> - - - Create wallet - - Create an new wallet to start using the Nym network - - - - - - - - - - - ) -} - const SignInCard: React.FC = ({ children }) => { const theme: Theme = useTheme() return ( @@ -210,18 +167,19 @@ const SignInCard: React.FC = ({ children }) => { padding: theme.spacing(6, 10), borderRadius: theme.shape.borderRadius, position: 'relative', - height: 300, + minHeight: 350, }} > {children} @@ -229,3 +187,131 @@ const SignInCard: React.FC = ({ children }) => { ) } + +const CreateAccountContent = ({ showSignIn }: { showSignIn: () => void }) => { + const [accountDetails, setAccountDetails] = useState() + const [isLoading, setIsLoading] = useState(false) + const [error, setError] = useState() + + const handleCreateAccount = async () => { + setIsLoading(true) + setError(undefined) + try { + const res = await createAccount() + setTimeout(() => { + setAccountDetails(res) + setIsLoading(false) + }, 2500) + } catch (e: any) { + console.log(e) + setError(e) + } + } + return ( + + Create wallet + + Create an new wallet to start using the Nym network + + + + {isLoading && } + {!isLoading && accountDetails && ( + <> +
+ + Wallet setup complete +
+ + Please store your mnemonic in a safe place. + You'll need it to access your wallet + + + + + + Mnemonic + + + + {accountDetails.mnemonic} +
+ +
+
+ + + + + + Address + + + + {accountDetails.client_address} + +
+
+ + )} +
+ {error && ( + + {error} + + )} + + {!accountDetails && ( + + )} + + +
+
+ ) +} diff --git a/tauri-wallet/src/types/global.ts b/tauri-wallet/src/types/global.ts index 7e190ef0c7..2f5573204b 100644 --- a/tauri-wallet/src/types/global.ts +++ b/tauri-wallet/src/types/global.ts @@ -12,3 +12,11 @@ export type TClientDetails = { client_address: string contract_address: string } + +export type TSignInWithMnemonic = { + denom: string +} & TClientDetails + +export type TCreateAccount = { + mnemonic: string +} & TSignInWithMnemonic diff --git a/tauri-wallet/src/types/rust/index.ts b/tauri-wallet/src/types/rust/index.ts index 090e6b088a..074f01fc2a 100644 --- a/tauri-wallet/src/types/rust/index.ts +++ b/tauri-wallet/src/types/rust/index.ts @@ -3,3 +3,5 @@ export * from './coin' export * from './mixnode' export * from './gateway' export * from './mixnode' +export * from './tauritxresult' +export * from './transactiondetails'