From 774f2aa7eb9f05722c0dffbff559798004d15fbc Mon Sep 17 00:00:00 2001 From: Leo Unoki Date: Mon, 31 Jul 2023 13:23:26 +0100 Subject: [PATCH] Add offboarding modal --- src/assets/icons/Warning.tsx | 24 +++++ .../Offboarding/OffboardingForm.tsx | 100 ++++++++++++++++++ .../Offboarding/useOffboardingModal.tsx | 21 ++++ src/views/settings/SettingsView.tsx | 7 +- 4 files changed, 149 insertions(+), 3 deletions(-) create mode 100644 src/assets/icons/Warning.tsx create mode 100644 src/components/Offboarding/OffboardingForm.tsx create mode 100644 src/components/Offboarding/useOffboardingModal.tsx diff --git a/src/assets/icons/Warning.tsx b/src/assets/icons/Warning.tsx new file mode 100644 index 000000000..f81e3df2b --- /dev/null +++ b/src/assets/icons/Warning.tsx @@ -0,0 +1,24 @@ +import { Icon, IconProps } from "@chakra-ui/react"; + +const WarningIcon: React.FC = props => { + return ( + + + + ); +}; + +export default WarningIcon; diff --git a/src/components/Offboarding/OffboardingForm.tsx b/src/components/Offboarding/OffboardingForm.tsx new file mode 100644 index 000000000..c4725992c --- /dev/null +++ b/src/components/Offboarding/OffboardingForm.tsx @@ -0,0 +1,100 @@ +import { + FormControl, + ModalBody, + ModalCloseButton, + ModalHeader, + Text, + ModalFooter, + Box, + Button, + FormErrorMessage, + Input, + Checkbox, + Divider, +} from "@chakra-ui/react"; +import { FormProvider, useForm } from "react-hook-form"; +import WarningIcon from "../../assets/icons/Warning"; +import colors from "../../style/colors"; +import { useReset } from "../../utils/hooks/accountHooks"; + +const CONFIRMATION_CODE = "wasabi"; + +const OffboardingForm = () => { + const reset = useReset(); + + const onSubmit = () => { + if (!getValues("check") || getValues("confirmationCode") !== CONFIRMATION_CODE) { + return; + } + reset(); + }; + + const form = useForm<{ check: boolean; confirmationCode: string }>({ + mode: "onBlur", + }); + const { + register, + handleSubmit, + formState: { isValid, errors }, + getValues, + } = form; + + return ( + +
+ + + + + + Off-board Wallet + + + + + This will permanently delete any data from this computer. + + + Please enter « {CONFIRMATION_CODE} » to confirm. The accounts are still available to be + imported in the future; in order to regain access to your accounts, please make sure + that you keep the recovery phrase. + + + + + + + I have read the warning and I am certain I want to delete my private keys locally. + I also made sure to keep my recovery phrase. + + + + + + + confirmationCode === CONFIRMATION_CODE || "Confirmation code does not match", + })} + placeholder="Enter code word to confirm" + /> + {errors.confirmationCode && ( + {errors.confirmationCode.message} + )} + + + + + + + + +
+ ); +}; + +export default OffboardingForm; diff --git a/src/components/Offboarding/useOffboardingModal.tsx b/src/components/Offboarding/useOffboardingModal.tsx new file mode 100644 index 000000000..9895b2613 --- /dev/null +++ b/src/components/Offboarding/useOffboardingModal.tsx @@ -0,0 +1,21 @@ +import { Modal, ModalContent, ModalOverlay, useDisclosure } from "@chakra-ui/react"; +import colors from "../../style/colors"; +import OffboardingForm from "./OffboardingForm"; + +const useOffboardingModal = () => { + const { isOpen, onOpen, onClose } = useDisclosure(); + + return { + modalElement: ( + + + + + + + ), + onOpen, + }; +}; + +export default useOffboardingModal; diff --git a/src/views/settings/SettingsView.tsx b/src/views/settings/SettingsView.tsx index 87ae72561..1eed8da18 100644 --- a/src/views/settings/SettingsView.tsx +++ b/src/views/settings/SettingsView.tsx @@ -8,8 +8,8 @@ import ClickableCard, { } from "../../components/ClickableCard"; import { IconAndTextBtn } from "../../components/IconAndTextBtn"; import NetworkSelector from "../../components/NetworkSelector"; +import useOffboarsingModal from "../../components/Offboarding/useOffboardingModal"; import { TopBar } from "../../components/TopBar"; -import { useReset } from "../../utils/hooks/accountHooks"; import { BeaconDrawerCard } from "./BeaconDrawerCard"; import ErrorLogsDrawerCard from "./ErrorLogsDrawerCard"; @@ -128,7 +128,7 @@ const BackupSection = () => { }; const AdvancedSection = () => { - const reset = useReset(); + const { modalElement, onOpen } = useOffboarsingModal(); return ( @@ -145,8 +145,9 @@ const AdvancedSection = () => { {}} /> - + {}} /> + {modalElement} ); };