ente/src/components/RecoveryKeyModal.tsx

90 lines
2.7 KiB
TypeScript
Raw Normal View History

2021-04-05 07:41:31 +00:00
import React, { useEffect, useState } from 'react';
2021-04-11 06:43:47 +00:00
import { downloadAsFile } from 'utils/file';
2021-04-05 07:41:31 +00:00
import { getRecoveryKey } from 'utils/crypto';
import { setJustSignedUp } from 'utils/storage';
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
interface Props {
2021-04-05 07:41:31 +00:00
show: boolean;
onHide: () => void;
somethingWentWrong: any;
2021-04-05 07:41:31 +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();
if (!recoveryKey) {
somethingWentWrong();
props.onHide();
}
2021-04-05 07:41:31 +00:00
setRecoveryKey(recoveryKey);
};
main();
}, [props.show]);
function onSaveClick() {
downloadAsFile(constants.RECOVERY_KEY_FILENAME, recoveryKey);
onClose();
}
function onClose() {
props.onHide();
}
2021-04-05 07:41:31 +00:00
return (
<MessageDialog
show={props.show}
onHide={onClose}
2021-05-09 06:53:56 +00:00
size="lg"
attributes={{
title: constants.DOWNLOAD_RECOVERY_KEY,
close: {
text: constants.SAVE_LATER,
variant: 'danger',
},
staticBackdrop: true,
proceed: {
text: constants.SAVE,
action: onSaveClick,
disabled: !recoveryKey,
variant: 'success',
},
}}
>
<p>{constants.RECOVERY_KEY_DESCRIPTION}</p>
<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%',
}}
>
{recoveryKey}
</div>
) : (
2021-04-18 13:01:40 +00:00
<EnteSpinner />
)}
</div>
<p>{constants.KEY_NOT_STORED_DISCLAIMER}</p>
</MessageDialog>
2021-04-05 07:41:31 +00:00
);
}
export default RecoveryKeyModal;