import { useIsMobileWidth } from "@/base/hooks"; import { ensure } from "@/utils/ensure"; import CodeBlock from "@ente/shared/components/CodeBlock"; import DialogTitleWithCloseButton from "@ente/shared/components/DialogBox/TitleWithCloseButton"; import { getRecoveryKey } from "@ente/shared/crypto/helpers"; import { downloadAsFile } from "@ente/shared/utils"; import { Box, Button, Dialog, DialogActions, DialogContent, Typography, styled, } from "@mui/material"; import * as bip39 from "bip39"; import { t } from "i18next"; import { useEffect, useState } from "react"; // mobile client library only supports english. bip39.setDefaultWordlist("english"); const RECOVERY_KEY_FILE_NAME = "ente-recovery-key.txt"; interface Props { show: boolean; onHide: () => void; somethingWentWrong: any; } function RecoveryKey({ somethingWentWrong, ...props }: Props) { const [recoveryKey, setRecoveryKey] = useState(null); const fullScreen = useIsMobileWidth(); useEffect(() => { if (!props.show) { return; } const main = async () => { try { const recoveryKey = await getRecoveryKey(); setRecoveryKey(bip39.entropyToMnemonic(recoveryKey)); } catch (e) { somethingWentWrong(); props.onHide(); } }; main(); }, [props.show]); function onSaveClick() { downloadAsFile(RECOVERY_KEY_FILE_NAME, ensure(recoveryKey)); props.onHide(); } return ( {t("RECOVERY_KEY")} {t("RECOVERY_KEY_DESCRIPTION")} {t("KEY_NOT_STORED_DISCLAIMER")} ); } export default RecoveryKey; const DashedBorderWrapper = styled(Box)(({ theme }) => ({ border: `1px dashed ${theme.palette.grey.A400}`, borderRadius: theme.spacing(1), }));