diff --git a/nym-wallet/src/context/main.tsx b/nym-wallet/src/context/main.tsx index da14162777..a2d1e18645 100644 --- a/nym-wallet/src/context/main.tsx +++ b/nym-wallet/src/context/main.tsx @@ -9,6 +9,7 @@ type TClientContext = { clientDetails?: TClientDetails getBalance: TUseGetBalance showAdmin: boolean + mode: 'light' | 'dark' handleShowAdmin: () => void logIn: (clientDetails: TSignInWithMnemonic) => void logOut: () => void @@ -23,6 +24,7 @@ export const ClientContextProvider = ({ }) => { const [clientDetails, setClientDetails] = useState() const [showAdmin, setShowAdmin] = useState(false) + const [mode, setMode] = useState<'light' | 'dark'>('dark') const history = useHistory() const getBalance = useGetBalance() @@ -44,6 +46,7 @@ export const ClientContextProvider = ({ clientDetails, getBalance, showAdmin, + mode, handleShowAdmin, logIn, logOut, diff --git a/nym-wallet/src/index.tsx b/nym-wallet/src/index.tsx index be1f847ed5..5cffe82ac1 100644 --- a/nym-wallet/src/index.tsx +++ b/nym-wallet/src/index.tsx @@ -5,7 +5,7 @@ import { BrowserRouter as Router } from 'react-router-dom' import { Routes } from './routes' import { ClientContext, ClientContextProvider } from './context/main' import { ApplicationLayout } from './layouts' -import { SignIn } from './routes/sign-in' +import { SignIn } from './routes/sign-in/' import { Admin, ErrorFallback } from './components' import { NymWalletTheme } from './theme' diff --git a/nym-wallet/src/routes/index.tsx b/nym-wallet/src/routes/index.tsx index 6450688f0b..c4730f00fa 100644 --- a/nym-wallet/src/routes/index.tsx +++ b/nym-wallet/src/routes/index.tsx @@ -6,16 +6,12 @@ import { Bond } from './bond' import { Delegate } from './delegate' import { Receive } from './receive' import { Send } from './send' -import { SignIn } from './sign-in' import { Unbond } from './unbond' import { Undelegate } from './undelegate' import { InternalDocs } from './internal-docs' export const Routes = () => ( - - - diff --git a/nym-wallet/src/routes/sign-in.tsx b/nym-wallet/src/routes/sign-in.tsx index 3a8afe2881..7e3b2b2b46 100644 --- a/nym-wallet/src/routes/sign-in.tsx +++ b/nym-wallet/src/routes/sign-in.tsx @@ -199,6 +199,7 @@ const CreateAccountContent = ({ showSignIn }: { showSignIn: () => void }) => { setError(e) } } + return ( Create wallet diff --git a/nym-wallet/src/routes/sign-in/create-account.tsx b/nym-wallet/src/routes/sign-in/create-account.tsx new file mode 100644 index 0000000000..0be09db914 --- /dev/null +++ b/nym-wallet/src/routes/sign-in/create-account.tsx @@ -0,0 +1,86 @@ +import React, { useEffect, useState } from 'react' +import { + Alert, + Button, + Card, + CardActions, + CardContent, + CardHeader, + CircularProgress, + Stack, + Typography, +} from '@mui/material' +import { Box } from '@mui/system' +import { createAccount } from '../../requests' +import { TCreateAccount } from '../../types' +import logo from '../../images/logo-background.svg' +import { CopyToClipboard } from '../../components' + +export const CreateAccountContent: React.FC<{ showSignIn: () => void }> = ({ + showSignIn, +}) => { + 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) { + setError(e) + } + } + + useEffect(() => { + handleCreateAccount() + }, []) + + if (isLoading) return + + return ( + + + Congratulations + Account setup complete! + + + Please store your mnemonic in a safe place. You'll need it to access + your account! + + + + + + {accountDetails?.mnemonic} + + + + + + + Account address: + + {accountDetails?.client_address} + + + {error && ( + + {error} + + )} + + + ) +} diff --git a/nym-wallet/src/routes/sign-in/index.tsx b/nym-wallet/src/routes/sign-in/index.tsx new file mode 100644 index 0000000000..b9b19b25cd --- /dev/null +++ b/nym-wallet/src/routes/sign-in/index.tsx @@ -0,0 +1,35 @@ +import React, { useContext, useState } from 'react' +import { Box } from '@mui/system' +import { SignInContent } from './sign-in' +import { CreateAccountContent } from './create-account' + +export const SignIn = () => { + const [showCreateAccount, setShowCreateAccount] = useState(false) + return ( + + + {showCreateAccount ? ( + setShowCreateAccount(false)} + /> + ) : ( + setShowCreateAccount(true)} /> + )} + + + ) +} diff --git a/nym-wallet/src/routes/sign-in/sign-in.tsx b/nym-wallet/src/routes/sign-in/sign-in.tsx new file mode 100644 index 0000000000..f5e96e1651 --- /dev/null +++ b/nym-wallet/src/routes/sign-in/sign-in.tsx @@ -0,0 +1,96 @@ +import React, { useContext, useState } from 'react' +import { + Button, + CircularProgress, + Grid, + Stack, + Link, + TextField, + Typography, + Alert, +} from '@mui/material' +import logo from '../../images/logo-background.svg' +import { signInWithMnemonic } from '../../requests' +import { ClientContext } from '../../context/main' + +export const SignInContent: React.FC<{ showCreateAccount: () => void }> = ({ + showCreateAccount, +}) => { + const [mnemonic, setMnemonic] = useState('') + const [inputError, setInputError] = useState() + const [isLoading, setIsLoading] = useState(false) + + const { logIn } = useContext(ClientContext) + + const handleSignIn = async (e: React.MouseEvent) => { + e.preventDefault() + + setIsLoading(true) + setInputError(undefined) + + try { + const res = await signInWithMnemonic(mnemonic || '') + setIsLoading(false) + logIn(res) + } catch (e: any) { + setIsLoading(false) + setInputError(e) + } + } + + return ( + + + Enter Mnemonic and 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} + sx={{ color: 'red' }} + /> + + + + + {inputError && ( + + + {inputError} + + + )} + +
+ Don't have an account?{' '} + + Create one now + +
+
+ ) +} diff --git a/nym-wallet/src/theme/index.tsx b/nym-wallet/src/theme/index.tsx index 3bd65a852c..497cfd97d9 100644 --- a/nym-wallet/src/theme/index.tsx +++ b/nym-wallet/src/theme/index.tsx @@ -1,16 +1,15 @@ -import * as React from 'react' +import React, { useContext } from 'react' import { createTheme, ThemeProvider } from '@mui/material/styles' import { CssBaseline } from '@mui/material' import { getDesignTokens } from './theme' +import { ClientContext } from '../context/main' /** * Provides the theme for the Network Explorer by reacting to the light/dark mode choice stored in the app context. */ export const NymWalletTheme: React.FC = ({ children }) => { - const theme = React.useMemo( - () => createTheme(getDesignTokens('light')), - ['light'], - ) + const { mode } = useContext(ClientContext) + const theme = React.useMemo(() => createTheme(getDesignTokens(mode)), [mode]) return ( diff --git a/nym-wallet/src/theme/theme.tsx b/nym-wallet/src/theme/theme.tsx index f80d39e544..c0a4ae2284 100644 --- a/nym-wallet/src/theme/theme.tsx +++ b/nym-wallet/src/theme/theme.tsx @@ -31,7 +31,7 @@ const nymPalette: NymPalette = { const darkMode: NymPaletteVariant = { mode: 'dark', background: { - main: '#111826', + main: '#121726', paper: '#242C3D', }, text: { @@ -192,7 +192,6 @@ export const getDesignTokens = (mode: PaletteMode): ThemeOptions => { easeIn: 'cubic-bezier(0.4, 0, 1, 1)', }, }, - palette, } }