Skip to content

Commit

Permalink
Remove useDeriveAccountModal
Browse files Browse the repository at this point in the history
  • Loading branch information
ryutamago committed Sep 29, 2023
1 parent 35b1c88 commit cdec1d2
Showing 1 changed file with 6 additions and 38 deletions.
44 changes: 6 additions & 38 deletions src/views/home/AccountsList.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
import {
Box,
Button,
Flex,
Heading,
Modal,
ModalContent,
Text,
useDisclosure,
useToast,
} from "@chakra-ui/react";
import { Box, Button, Flex, Heading, Text, useToast } from "@chakra-ui/react";
import { compact, groupBy } from "lodash";
import { useContext, useRef } from "react";
import { useContext } from "react";
import { BsWindowPlus } from "react-icons/bs";
import KeyIcon from "../../assets/icons/Key";
import { DynamicModalContext } from "../../components/DynamicModal";
Expand Down Expand Up @@ -54,7 +44,6 @@ const AccountGroup: React.FC<{
const first = accounts[0];
const isMultisig = first.type === AccountType.MULTISIG;
const isMnemonic = first.type === AccountType.MNEMONIC;
const { element: deriveAccountModal, onOpen: openDeriveAccountModal } = useDeriveAccountModal();
const { openWith, onClose } = useContext(DynamicModalContext);
const removeMnemonic = useRemoveMnemonic();
const removeNonMnemonic = useRemoveNonMnemonic();
Expand All @@ -79,20 +68,22 @@ const AccountGroup: React.FC<{
/>
);
};

const onDerive = () => {
if (!isMnemonic) {
throw new Error(`Can't derive a non mnemonic account!`);
}
openDeriveAccountModal({ fingerprint: first.seedFingerPrint });
openWith(<DeriveAccount onDone={onClose} fingerprint={first.seedFingerPrint} />);
};

return (
<Box data-testid={`account-group-${groupLabel}`}>
<Flex justifyContent="space-between">
<Heading size="md" mb={4}>
{groupLabel}
</Heading>

{isMultisig ? null : (
{!isMultisig && (
<AccountPopover onCreate={isMnemonic ? onDerive : undefined} onDelete={onDelete} />
)}
</Flex>
Expand All @@ -108,7 +99,6 @@ const AccountGroup: React.FC<{
/>
);
})}
{deriveAccountModal}
</Box>
);
};
Expand Down Expand Up @@ -212,25 +202,3 @@ const DeriveAccount = (props: { onDone: () => void; fingerprint: string }) => {
/>
);
};

export const useDeriveAccountModal = () => {
const { isOpen, onOpen, onClose } = useDisclosure();

const paramsRef = useRef<{ fingerprint: string }>();

return {
element: (
<Modal isOpen={isOpen} onClose={onClose}>
<ModalContent bg={colors.gray[900]}>
{paramsRef.current?.fingerprint && (
<DeriveAccount onDone={onClose} fingerprint={paramsRef.current.fingerprint} />
)}
</ModalContent>
</Modal>
),
onOpen: (params: { fingerprint: string }) => {
paramsRef.current = params;
onOpen();
},
};
};

0 comments on commit cdec1d2

Please sign in to comment.