diff --git a/nym-wallet/src/components/Accounts/AccountsModal.tsx b/nym-wallet/src/components/Accounts/AccountsModal.tsx deleted file mode 100644 index 8210b3c562..0000000000 --- a/nym-wallet/src/components/Accounts/AccountsModal.tsx +++ /dev/null @@ -1,48 +0,0 @@ -import React, { useContext } from 'react'; -import { Box, Button, Dialog, DialogActions, DialogContent, DialogTitle, IconButton, Typography } from '@mui/material'; -import { Add, ArrowDownwardSharp, Close } from '@mui/icons-material'; -import { AccountsContext } from 'src/context'; -import { AccountItem } from './AccountItem'; - -export const AccountsModal = ({ onClose }: { onClose?: () => void }) => { - const { accounts, dialogToDisplay, setDialogToDisplay } = useContext(AccountsContext); - - const handleClose = () => { - setDialogToDisplay(undefined); - onClose?.(); - }; - - return ( - - - - Accounts - - - - - - Switch between accounts - - - - {accounts?.map(({ id, address }) => ( - - ))} - - - - - - - ); -}; diff --git a/nym-wallet/src/components/Accounts/AddAccountModal.tsx b/nym-wallet/src/components/Accounts/modals/AddAccountModal.tsx similarity index 74% rename from nym-wallet/src/components/Accounts/AddAccountModal.tsx rename to nym-wallet/src/components/Accounts/modals/AddAccountModal.tsx index 3f3aec7b62..b7079d906e 100644 --- a/nym-wallet/src/components/Accounts/AddAccountModal.tsx +++ b/nym-wallet/src/components/Accounts/modals/AddAccountModal.tsx @@ -2,24 +2,21 @@ import React, { useContext, useEffect, useState } from 'react'; import { Box, Button, - CircularProgress, Dialog, DialogActions, DialogContent, DialogTitle, IconButton, - Stack, TextField, Typography, } from '@mui/material'; import { ArrowBackSharp } from '@mui/icons-material'; import { useClipboard } from 'use-clipboard-copy'; import { createMnemonic, validateMnemonic } from 'src/requests'; -import { AccountsContext } from 'src/context'; -import { PasswordInput } from 'src/components'; -import { Mnemonic } from '../Mnemonic'; import { Console } from 'src/utils/console'; -import { match } from 'assert'; +import { AccountsContext } from 'src/context'; +import { ConfirmPassword, Mnemonic } from 'src/components'; +import { MnemonicInput } from 'src/components/textfields'; const createAccountSteps = [ 'Copy and save mnemonic for your new account', @@ -66,27 +63,18 @@ const ImportMnemonic = ({ }; return ( - + <> - - {error && ( - - {error} - - )} - { - onChange(e.target.value); - setError(undefined); - }} - fullWidth - type="password" - /> - + + {error} + + { + onChange(mnemon); + setError(undefined); + }} + /> - - ); -}; - -const ConfirmPassword = ({ onConfirm }: { onConfirm: (password: string) => void }) => { - const [value, setValue] = useState(''); - const { isLoading, error } = useContext(AccountsContext); - - return ( - - - {error && ( - - {error} - - )} - setValue(pswrd)} - label="Confirm password" - autoFocus - /> - - - - - + ); }; @@ -191,24 +143,25 @@ export const AddAccountModal = () => { accountName: '', }); - const { dialogToDisplay, setDialogToDisplay, handleAddAccount, setError } = useContext(AccountsContext); + const { dialogToDisplay, setDialogToDisplay, handleAddAccount, setError, isLoading, error } = + useContext(AccountsContext); const generateMnemonic = async () => { const mnemon = await createMnemonic(); setData((d) => ({ ...d, mnemonic: mnemon })); }; - const handleClose = () => { - setDialogToDisplay('Accounts'); - resetState(); - }; - const resetState = () => { setData({ mnemonic: '', accountName: '' }); setStep(0); setError(undefined); }; + const handleClose = () => { + setDialogToDisplay('Accounts'); + resetState(); + }; + useEffect(() => { if (dialogToDisplay === 'Add') generateMnemonic(); if (dialogToDisplay === 'Accounts') resetState(); @@ -260,6 +213,7 @@ export const AddAccountModal = () => { case 2: return ( { if (data.accountName && data.mnemonic) { try { @@ -271,6 +225,8 @@ export const AddAccountModal = () => { } } }} + isLoading={isLoading} + error={error} /> ); default: diff --git a/nym-wallet/src/components/Accounts/EditAccountModal.tsx b/nym-wallet/src/components/Accounts/modals/EditAccountModal.tsx similarity index 100% rename from nym-wallet/src/components/Accounts/EditAccountModal.tsx rename to nym-wallet/src/components/Accounts/modals/EditAccountModal.tsx diff --git a/nym-wallet/src/components/Accounts/ImportAccountModal.tsx b/nym-wallet/src/components/Accounts/modals/ImportAccountModal.tsx similarity index 100% rename from nym-wallet/src/components/Accounts/ImportAccountModal.tsx rename to nym-wallet/src/components/Accounts/modals/ImportAccountModal.tsx diff --git a/nym-wallet/src/components/Accounts/MnemonicModal.tsx b/nym-wallet/src/components/Accounts/modals/MnemonicModal.tsx similarity index 92% rename from nym-wallet/src/components/Accounts/MnemonicModal.tsx rename to nym-wallet/src/components/Accounts/modals/MnemonicModal.tsx index cecc572a73..461e93b51b 100644 --- a/nym-wallet/src/components/Accounts/MnemonicModal.tsx +++ b/nym-wallet/src/components/Accounts/modals/MnemonicModal.tsx @@ -13,8 +13,7 @@ import { import { ArrowBackSharp } from '@mui/icons-material'; import { AccountsContext } from 'src/context'; import { useClipboard } from 'use-clipboard-copy'; -import { Mnemonic } from '../Mnemonic'; -import { PasswordInput } from '../textfields'; +import { PasswordInput, Mnemonic } from 'src/components'; export const MnemonicModal = () => { const [password, setPassword] = useState(''); @@ -26,7 +25,7 @@ export const MnemonicModal = () => { setDialogToDisplay, accountMnemonic, setAccountMnemonic, - handleGetAcccountMnemonic, + handleGetAccountMnemonic, error, setError, isLoading, @@ -86,7 +85,7 @@ export const MnemonicModal = () => { onClick={async () => { if (accountMnemonic?.accountName) { setError(undefined); - await handleGetAcccountMnemonic({ password, accountName: accountMnemonic?.accountName }); + await handleGetAccountMnemonic({ password, accountName: accountMnemonic?.accountName }); } }} endIcon={isLoading && }