2021-05-30 16:56:48 +00:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
import { downloadAsFile } from 'utils/file';
|
|
|
|
import { getRecoveryKey } from 'utils/crypto';
|
2021-04-05 07:41:31 +00:00
|
|
|
import constants from 'utils/strings/constants';
|
2021-04-07 09:22:59 +00:00
|
|
|
import MessageDialog from './MessageDialog';
|
2021-04-18 13:01:40 +00:00
|
|
|
import EnteSpinner from './EnteSpinner';
|
2021-06-17 12:43:14 +00:00
|
|
|
import styled from 'styled-components';
|
2021-04-05 07:41:31 +00:00
|
|
|
|
2021-06-17 12:43:14 +00:00
|
|
|
export const CodeBlock = styled.div<{ height: number }>`
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
background: #1a1919;
|
|
|
|
height: ${(props) => props.height}px;
|
2021-08-13 02:38:38 +00:00
|
|
|
padding-left: 30px;
|
|
|
|
padding-right: 20px;
|
2021-06-17 12:43:14 +00:00
|
|
|
color: white;
|
|
|
|
margin: 20px 0;
|
2021-08-13 02:38:38 +00:00
|
|
|
width: 100%;
|
2021-06-17 12:43:14 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
export const FreeFlowText = styled.div`
|
|
|
|
word-wrap: break-word;
|
|
|
|
overflow-wrap: break-word;
|
|
|
|
min-width: 30%;
|
|
|
|
`;
|
2021-04-05 12:00:17 +00:00
|
|
|
interface Props {
|
2021-04-05 07:41:31 +00:00
|
|
|
show: boolean;
|
|
|
|
onHide: () => void;
|
2021-04-05 13:18:41 +00:00
|
|
|
somethingWentWrong: any;
|
2021-04-05 07:41:31 +00:00
|
|
|
}
|
2021-05-30 16:56:48 +00:00
|
|
|
function RecoveryKeyModal({ somethingWentWrong, ...props }: Props) {
|
2021-04-05 07:41:31 +00:00
|
|
|
const [recoveryKey, setRecoveryKey] = useState(null);
|
|
|
|
useEffect(() => {
|
2021-04-05 09:11:06 +00:00
|
|
|
if (!props.show) {
|
|
|
|
return;
|
|
|
|
}
|
2021-04-05 07:41:31 +00:00
|
|
|
const main = async () => {
|
2021-04-05 12:18:29 +00:00
|
|
|
const recoveryKey = await getRecoveryKey();
|
2021-04-05 13:18:41 +00:00
|
|
|
if (!recoveryKey) {
|
2021-04-05 16:22:54 +00:00
|
|
|
somethingWentWrong();
|
2021-04-05 13:18:41 +00:00
|
|
|
props.onHide();
|
|
|
|
}
|
2021-04-05 07:41:31 +00:00
|
|
|
setRecoveryKey(recoveryKey);
|
|
|
|
};
|
|
|
|
main();
|
|
|
|
}, [props.show]);
|
|
|
|
|
2021-04-05 15:37:56 +00:00
|
|
|
function onSaveClick() {
|
|
|
|
downloadAsFile(constants.RECOVERY_KEY_FILENAME, recoveryKey);
|
2021-04-07 07:18:45 +00:00
|
|
|
onClose();
|
2021-04-05 15:37:56 +00:00
|
|
|
}
|
2021-04-07 07:18:45 +00:00
|
|
|
function onClose() {
|
2021-04-05 15:37:56 +00:00
|
|
|
props.onHide();
|
|
|
|
}
|
2021-04-05 07:41:31 +00:00
|
|
|
return (
|
2021-04-05 12:00:17 +00:00
|
|
|
<MessageDialog
|
2021-04-07 07:18:45 +00:00
|
|
|
show={props.show}
|
|
|
|
onHide={onClose}
|
2021-05-09 06:53:56 +00:00
|
|
|
size="lg"
|
2021-04-05 12:00:17 +00:00
|
|
|
attributes={{
|
|
|
|
title: constants.DOWNLOAD_RECOVERY_KEY,
|
2021-04-07 07:18:45 +00:00
|
|
|
close: {
|
2021-04-05 15:37:56 +00:00
|
|
|
text: constants.SAVE_LATER,
|
2021-04-07 07:18:45 +00:00
|
|
|
variant: 'danger',
|
2021-04-05 15:37:56 +00:00
|
|
|
},
|
|
|
|
staticBackdrop: true,
|
2021-04-05 12:00:17 +00:00
|
|
|
proceed: {
|
|
|
|
text: constants.SAVE,
|
2021-04-05 15:37:56 +00:00
|
|
|
action: onSaveClick,
|
2021-04-23 10:18:41 +00:00
|
|
|
disabled: !recoveryKey,
|
2021-04-25 15:40:33 +00:00
|
|
|
variant: 'success',
|
2021-04-05 12:00:17 +00:00
|
|
|
},
|
2021-08-13 02:38:38 +00:00
|
|
|
}}>
|
2021-04-05 15:37:56 +00:00
|
|
|
<p>{constants.RECOVERY_KEY_DESCRIPTION}</p>
|
2021-06-17 12:43:14 +00:00
|
|
|
<CodeBlock height={150}>
|
2021-04-05 12:00:17 +00:00
|
|
|
{recoveryKey ? (
|
2021-08-13 02:38:38 +00:00
|
|
|
<FreeFlowText>{recoveryKey}</FreeFlowText>
|
2021-04-05 12:00:17 +00:00
|
|
|
) : (
|
2021-04-18 13:01:40 +00:00
|
|
|
<EnteSpinner />
|
2021-04-05 12:00:17 +00:00
|
|
|
)}
|
2021-06-17 12:43:14 +00:00
|
|
|
</CodeBlock>
|
2021-04-05 15:37:56 +00:00
|
|
|
<p>{constants.KEY_NOT_STORED_DISCLAIMER}</p>
|
2021-08-13 02:38:38 +00:00
|
|
|
</MessageDialog>
|
2021-04-05 07:41:31 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
export default RecoveryKeyModal;
|