diff --git a/nym-wallet/src/pages/welcome/components/index.ts b/nym-wallet/src/pages/welcome/components/index.ts index adb07f38a9..137fbe9fbb 100644 --- a/nym-wallet/src/pages/welcome/components/index.ts +++ b/nym-wallet/src/pages/welcome/components/index.ts @@ -2,3 +2,5 @@ export * from './heading'; export * from './word-tiles'; export * from './render-page'; export * from './password-strength'; +export * from './error'; +export * from './textfields'; diff --git a/nym-wallet/src/pages/welcome/components/password-strength.tsx b/nym-wallet/src/pages/welcome/components/password-strength.tsx index a2813b869f..32c128cbac 100644 --- a/nym-wallet/src/pages/welcome/components/password-strength.tsx +++ b/nym-wallet/src/pages/welcome/components/password-strength.tsx @@ -51,7 +51,13 @@ const getPasswordStrength = (strength: TStrength) => { } }; -export const PasswordStrength = ({ password }: { password: string }) => { +export const PasswordStrength = ({ + password, + onChange, +}: { + password: string; + onChange: (isStrong: boolean) => void; +}) => { const [strength, setStrength] = useState('init'); useEffect(() => { @@ -72,6 +78,14 @@ export const PasswordStrength = ({ password }: { password: string }) => { setStrength('weak'); }, [password]); + useEffect(() => { + if (strength === 'strong') { + onChange(true); + } else { + onChange(false); + } + }, [strength]); + return ( diff --git a/nym-wallet/src/pages/welcome/components/textfields.tsx b/nym-wallet/src/pages/welcome/components/textfields.tsx index 889b3a9f1d..bcfa640a3a 100644 --- a/nym-wallet/src/pages/welcome/components/textfields.tsx +++ b/nym-wallet/src/pages/welcome/components/textfields.tsx @@ -1,43 +1,38 @@ -import React, { useContext, useState } from 'react'; -import { Alert, Button, IconButton, Stack, TextField } from '@mui/material'; +import React, { useState } from 'react'; +import { IconButton, Stack, TextField } from '@mui/material'; import { Visibility, VisibilityOff } from '@mui/icons-material'; -import { ClientContext } from '../../../context/main'; +import { Error } from './error'; -export const MnemonicInput: React.FC<{ mnemonic: string; onUpdateMnemonic: (mnemonic: string) => void }> = ({ - mnemonic, - onUpdateMnemonic, -}) => { - const { error } = useContext(ClientContext); - return ( - - onUpdateMnemonic(e.target.value)} - multiline - rows={5} - fullWidth - /> - {error && ( - - {error} - - )} - - ); -}; +export const MnemonicInput: React.FC<{ + mnemonic: string; + error?: string; + onUpdateMnemonic: (mnemonic: string) => void; +}> = ({ mnemonic, error, onUpdateMnemonic }) => ( + + onUpdateMnemonic(e.target.value)} + multiline + rows={5} + fullWidth + /> + {error && } + +); -export const PasswordInput: React.FC<{ password: string; onUpdatePassword: (password: string) => void }> = ({ - password, - onUpdatePassword, -}) => { +export const PasswordInput: React.FC<{ + password: string; + error?: string; + label: string; + onUpdatePassword: (password: string) => void; +}> = ({ password, label, error, onUpdatePassword }) => { const [showPassword, setShowPassword] = useState(false); - const { error } = useContext(ClientContext); return ( onUpdatePassword(e.target.value)} @@ -50,11 +45,7 @@ export const PasswordInput: React.FC<{ password: string; onUpdatePassword: (pass ), }} /> - {error && ( - - {error} - - )} + {error && } ); }; diff --git a/nym-wallet/src/pages/welcome/pages/create-account.tsx b/nym-wallet/src/pages/welcome/pages/create-account.tsx deleted file mode 100644 index 8cda73b794..0000000000 --- a/nym-wallet/src/pages/welcome/pages/create-account.tsx +++ /dev/null @@ -1,118 +0,0 @@ -import React, { useContext, useEffect, useState } from 'react'; -import { Alert, Button, Grid, ToggleButton, ToggleButtonGroup, Typography } from '@mui/material'; -import { CopyToClipboard } from '@nymproject/react'; -import { WordTiles } from '../components'; -import { TMnemonicWords, TPages } from '../types'; -import { MnemonicInput } from '../components/textfields'; -import { signInWithMnemonic } from 'src/requests'; -import { ClientContext } from 'src/context/main'; - -export const CreateAccount = ({ - mnemonicWords, - mnemonic, - page, - onUseNew, - onNext, - onPrev, -}: { - mnemonicWords?: TMnemonicWords; - mnemonic: string; - onUseNew: () => void; - onNext: () => void; - onPrev: () => void; - page: TPages; -}) => { - const [toggle, setToggle] = useState('new'); - const [existingMnemonic, setExistingMnemonic] = useState(''); - - const { setError } = useContext(ClientContext); - const validateMnemonic = async () => { - try { - await signInWithMnemonic(existingMnemonic); - } catch (e) { - setError(e as string); - } - }; - - useEffect(() => { - if (toggle === 'new') { - onUseNew(); - } else { - setExistingMnemonic(''); - } - }, [toggle]); - - return ( - - - - Write down your mnemonic - - - {toggle === 'new' && ( - - } - > - Please store your mnemonic in a safe place - - This is the only way to access your wallet! - - - - )} - - , value: string) => { - setToggle(value); - }} - > - Create new mnemonic - Use existing mnemonic - - - - {toggle === 'new' && } - {toggle === 'existing' && ( - setExistingMnemonic(mnc)} /> - )} - - - - - - - - - - - - ); -};