import React, { useState } from 'react'; import { send } from 'loot-core/src/platform/client/fetch'; import { getTestKeyError } from 'loot-core/src/shared/errors'; import { View, Text, Modal, Button, ButtonWithLoading, P, ModalButtons, Input, InitialFocus, ExternalLink } from 'loot-design/src/components/common'; import { colors } from 'loot-design/src/style'; export default function FixEncryptionKey({ modalProps, actions, options = {} }) { let { hasExistingKey, cloudFileId, onSuccess } = options; let [password, setPassword] = useState(''); let [error, setError] = useState(''); let [loading, setLoading] = useState(false); let [showPassword, setShowPassword] = useState(false); async function onUpdateKey() { if (password !== '' && !loading) { setLoading(true); setError(null); let { error } = await send('key-test', { password, fileId: cloudFileId }); if (error) { setError(getTestKeyError(error)); setLoading(false); return; } actions.popModal(); onSuccess && onSuccess(); } } return ( {() => ( {hasExistingKey ? 'Unable to decrypt file' : 'This file is encrypted'} {hasExistingKey ? (

This file was encrypted with a different key than you are currently using. This probably means you changed your password. Enter your current password to update your key.{' '} Learn more

) : (

We don{"'"}t have a key that encrypts or decrypts this file. Enter the password for this file to create the key for encryption.{' '} Learn more

)}
{ e.preventDefault(); onUpdateKey(); }} > Password{' '} {error && ( {error} )} setPassword(e.target.value)} /> {hasExistingKey ? 'Update key' : 'Create key'}
)}
); }