diff --git a/nym-wallet/src/components/Accounts/AccountItem.tsx b/nym-wallet/src/components/Accounts/AccountItem.tsx
index a1fdb2f1cd..940da46285 100644
--- a/nym-wallet/src/components/Accounts/AccountItem.tsx
+++ b/nym-wallet/src/components/Accounts/AccountItem.tsx
@@ -1,4 +1,4 @@
-import React from 'react';
+import React, { useContext } from 'react';
import {
Box,
IconButton,
@@ -10,48 +10,44 @@ import {
Typography,
} from '@mui/material';
import { Edit } from '@mui/icons-material';
+import { AccountsContext } from 'src/context';
import { AccountAvatar } from './AccountAvatar';
import { ShowMnemonic } from './ShowMnemonic';
-export const AccountItem = ({
- name,
- address,
- isSelected,
- onSelect,
- onEdit,
-}: {
- name: string;
- address: string;
- isSelected: boolean;
- onSelect: () => void;
- onEdit: () => void;
-}) => (
-
-
-
-
-
-
- {address}
-
-
+export const AccountItem = ({ name, address }: { name: string; address: string }) => {
+ const { selectedAccount, handleSelectAccount, handleAccountToEdit } = useContext(AccountsContext);
+ return (
+
+ handleSelectAccount(name)}>
+
+
+
+
+ {address}
+
+
+
-
- }
- />
-
- {
- e.stopPropagation();
- onEdit();
- }}
- >
-
-
-
-
-
-);
+ }
+ />
+
+ {
+ e.stopPropagation();
+ handleAccountToEdit(name);
+ }}
+ >
+
+
+
+
+
+ );
+};
diff --git a/nym-wallet/src/components/Accounts/Accounts.tsx b/nym-wallet/src/components/Accounts/Accounts.tsx
index 04d27f0dfb..2dd50102d4 100644
--- a/nym-wallet/src/components/Accounts/Accounts.tsx
+++ b/nym-wallet/src/components/Accounts/Accounts.tsx
@@ -1,90 +1,29 @@
-import React from 'react';
+import React, { useContext } from 'react';
import { Button } from '@mui/material';
-import { v4 as uuidv4 } from 'uuid';
-import { AccountEntry } from 'src/types';
+import { AccountsContext } from 'src/context';
import { EditAccountModal } from './EditAccountModal';
import { AddAccountModal } from './AddAccountModal';
import { AccountsModal } from './AccountsModal';
import { ImportAccountModal } from './ImportAccountModal';
import { AccountAvatar } from './AccountAvatar';
-import { TDialog } from './types';
-export const Accounts = ({
- accounts,
- selectedAccount,
- accountToEdit,
- dialogToDisplay,
- addAccount,
- editAccount,
- setAccountToEdit,
- importAccount,
- setSelectedAccount,
- setDialogToDisplay,
-}: {
- accounts?: AccountEntry[];
- selectedAccount?: AccountEntry;
- accountToEdit?: AccountEntry;
- dialogToDisplay?: TDialog;
- addAccount: (acc: { accountName: string; mnemonic: string; password: string }) => Promise;
- editAccount: (acc: AccountEntry) => void;
- importAccount: (acc: AccountEntry & { mnemonic: string }) => void;
- setAccountToEdit: (accountName: string) => void;
- setSelectedAccount: (accountName: string) => void;
- setDialogToDisplay: (dialog: TDialog | undefined) => void;
-}) =>
- accounts && selectedAccount ? (
+export const Accounts = () => {
+ const { accounts, selectedAccount, setDialogToDisplay } = useContext(AccountsContext);
+
+ return accounts && selectedAccount ? (
<>
}
+ startIcon={}
sx={{ color: 'nym.text.dark' }}
onClick={() => setDialogToDisplay('Accounts')}
disableRipple
>
{selectedAccount.id}
- setDialogToDisplay(undefined)}
- accounts={accounts}
- onAccountSelect={(accountName) => setSelectedAccount(accountName)}
- selectedAccount={selectedAccount.id}
- onAdd={() => {
- setDialogToDisplay('Add');
- }}
- onEdit={(accountName) => {
- setAccountToEdit(accountName);
- setDialogToDisplay('Edit');
- }}
- onImport={() => setDialogToDisplay('Import')}
- />
- {
- setDialogToDisplay('Accounts');
- }}
- onAdd={async (data) => {
- addAccount(data);
- setDialogToDisplay('Accounts');
- }}
- />
- {
- setDialogToDisplay('Accounts');
- }}
- onEdit={(account) => {
- editAccount(account);
- setDialogToDisplay('Accounts');
- }}
- />
- setDialogToDisplay('Accounts')}
- onImport={(mnemonic) => {
- importAccount({ id: 'New Account', address: uuidv4(), mnemonic });
- setDialogToDisplay('Accounts');
- }}
- />
+
+
+
+
>
) : null;
+};
diff --git a/nym-wallet/src/components/Accounts/AccountsModal.tsx b/nym-wallet/src/components/Accounts/AccountsModal.tsx
index bc2de38243..8210b3c562 100644
--- a/nym-wallet/src/components/Accounts/AccountsModal.tsx
+++ b/nym-wallet/src/components/Accounts/AccountsModal.tsx
@@ -1,62 +1,48 @@
-import React from 'react';
+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 { AccountEntry } from 'src/types';
+import { AccountsContext } from 'src/context';
import { AccountItem } from './AccountItem';
-export const AccountsModal = ({
- show,
- accounts,
- selectedAccount,
- onClose,
- onAccountSelect,
- onAdd,
- onEdit,
- onImport,
-}: {
- show: boolean;
- accounts: AccountEntry[];
- selectedAccount: AccountEntry['id'];
- onClose: () => void;
- onAccountSelect: (accountName: string) => void;
- onAdd: () => void;
- onEdit: (accoutnName: string) => void;
- onImport: () => void;
-}) => (
-
-);
+export const AccountsModal = ({ onClose }: { onClose?: () => void }) => {
+ const { accounts, dialogToDisplay, setDialogToDisplay } = useContext(AccountsContext);
+
+ const handleClose = () => {
+ setDialogToDisplay(undefined);
+ onClose?.();
+ };
+
+ return (
+
+ );
+};
diff --git a/nym-wallet/src/components/Accounts/AddAccountModal.tsx b/nym-wallet/src/components/Accounts/AddAccountModal.tsx
index 6a45c6213f..4745dd4590 100644
--- a/nym-wallet/src/components/Accounts/AddAccountModal.tsx
+++ b/nym-wallet/src/components/Accounts/AddAccountModal.tsx
@@ -1,4 +1,4 @@
-import React, { useEffect, useState } from 'react';
+import React, { useContext, useEffect, useState } from 'react';
import {
Alert,
Box,
@@ -15,6 +15,7 @@ import {
import { Check, Close, ContentCopySharp } from '@mui/icons-material';
import { useClipboard } from 'use-clipboard-copy';
import { createMnemonic } from 'src/requests';
+import { AccountsContext } from 'src/context';
const createAccountSteps = ['Save and copy mnemonic for your new account', 'Name your new account', 'Confirm password'];
@@ -135,42 +136,36 @@ const ConfirmPassword = ({ onConfirm }: { onConfirm: (password: string) => void
);
};
-export const AddAccountModal = ({
- show,
- withoutPassword,
- onClose,
- onAdd,
-}: {
- show: boolean;
- withoutPassword?: boolean;
- onClose: () => void;
- onAdd: (data: { accountName: string; mnemonic: string; password: string }) => void;
-}) => {
+export const AddAccountModal = ({ withoutPassword }: { withoutPassword?: boolean }) => {
const [step, setStep] = useState(0);
const [data, setData] = useState<{ mnemonic?: string; accountName?: string }>({
mnemonic: undefined,
accountName: undefined,
});
+ const { dialogToDisplay, setDialogToDisplay, handleAddAccount } = useContext(AccountsContext);
+
const generateMnemonic = async () => {
const mnemon = await createMnemonic();
setData((d) => ({ ...d, mnemonic: mnemon }));
};
+ const handleClose = () => {
+ setDialogToDisplay('Accounts');
+ setData({ mnemonic: undefined, accountName: undefined });
+ setStep(0);
+ };
+
useEffect(() => {
- if (show) generateMnemonic();
- else {
- setData({ mnemonic: undefined, accountName: undefined });
- setStep(0);
- }
- }, [show]);
+ if (dialogToDisplay === 'Accounts') generateMnemonic();
+ }, [dialogToDisplay]);
return (
-