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-04-05 07:41:31 +00:00
|
|
|
|
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-04-05 15:37:56 +00:00
|
|
|
<p>{constants.RECOVERY_KEY_DESCRIPTION}</p>
|
2021-04-05 12:00:17 +00:00
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
background: '#1a1919',
|
|
|
|
height: '150px',
|
|
|
|
padding: '40px',
|
|
|
|
color: 'white',
|
|
|
|
margin: '20px 0',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{recoveryKey ? (
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
wordWrap: 'break-word',
|
|
|
|
overflowWrap: 'break-word',
|
2021-04-05 13:48:47 +00:00
|
|
|
minWidth: '30%',
|
2021-04-05 12:00:17 +00:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
{recoveryKey}
|
|
|
|
</div>
|
|
|
|
) : (
|
2021-04-18 13:01:40 +00:00
|
|
|
<EnteSpinner />
|
2021-04-05 12:00:17 +00:00
|
|
|
)}
|
|
|
|
</div>
|
2021-04-05 15:37:56 +00:00
|
|
|
<p>{constants.KEY_NOT_STORED_DISCLAIMER}</p>
|
2021-04-05 12:00:17 +00:00
|
|
|
</MessageDialog>
|
2021-04-05 07:41:31 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
export default RecoveryKeyModal;
|