From f35396481fd8d515071c26e07edafeb16e2fb348 Mon Sep 17 00:00:00 2001 From: fmtabbara Date: Fri, 22 Sep 2023 12:04:07 +0100 Subject: [PATCH] take user password when editing account name --- .../Accounts/modals/EditAccountModal.tsx | 53 ++++++++++++++----- nym-wallet/src/context/accounts.tsx | 39 ++++++++++++-- nym-wallet/src/context/mocks/accounts.tsx | 11 +++- nym-wallet/src/requests/account.ts | 15 ++++++ 4 files changed, 99 insertions(+), 19 deletions(-) diff --git a/nym-wallet/src/components/Accounts/modals/EditAccountModal.tsx b/nym-wallet/src/components/Accounts/modals/EditAccountModal.tsx index a9625ee354..25b306a031 100644 --- a/nym-wallet/src/components/Accounts/modals/EditAccountModal.tsx +++ b/nym-wallet/src/components/Accounts/modals/EditAccountModal.tsx @@ -15,23 +15,58 @@ import { Close } from '@mui/icons-material'; import { useTheme } from '@mui/material/styles'; import { AccountsContext } from 'src/context'; import { StyledBackButton } from 'src/components/StyledBackButton'; +import { ConfirmPasswordModal } from './ConfirmPasswordModal'; export const EditAccountModal = () => { - const { accountToEdit, dialogToDisplay, setDialogToDisplay, handleEditAccount, handleAccountToEdit } = + const { accountToEdit, dialogToDisplay, setDialogToDisplay, handleEditAccount, handleAccountToEdit, setError } = useContext(AccountsContext); + const [accountName, setAccountName] = useState(''); + const [showConfirmPassword, setShowConfirmPassword] = useState(false); const theme = useTheme(); + useEffect(() => { if (accountToEdit) { setAccountName(accountToEdit.id); } }, [accountToEdit]); + const handleClose = () => { + handleAccountToEdit(undefined); + setDialogToDisplay('Accounts'); + }; + + const onConfirmPassword = async (password: string) => { + if (accountToEdit) { + try { + await handleEditAccount({ account: accountToEdit, newAccountName: accountName, password }); + setShowConfirmPassword(false); + } catch (e) { + setError(`Error editing account: ${e}`); + } + } + }; + + if (showConfirmPassword) { + return ( + { + setShowConfirmPassword(false); + setError(undefined); + }} + onConfirm={onConfirmPassword} + /> + ); + } + return ( setDialogToDisplay('Accounts')} + onClose={handleClose} fullWidth PaperProps={{ style: { border: `1px solid ${theme.palette.nym.nymWallet.modal.border}` }, @@ -41,7 +76,7 @@ export const EditAccountModal = () => { Rename account - setDialogToDisplay('Accounts')}> + @@ -60,22 +95,14 @@ export const EditAccountModal = () => { - { - handleAccountToEdit(undefined); - setDialogToDisplay('Accounts'); - }} - /> +