1 import { useUser } from '@proton/account/user/hooks';
2 import { useUserSettings } from '@proton/account/userSettings/hooks';
3 import { MNEMONIC_STATUS } from '@proton/shared/lib/interfaces';
5 import type RecoveryStatus from '../containers/recovery/RecoveryStatus';
6 import usePrimaryRecoverySecret from './usePrimaryRecoverySecret';
8 const useRecoveryStatus = () => {
9 const [user] = useUser();
10 const [userSettings, loadingUserSettings] = useUserSettings();
11 const hasVerifiedRecoveryEmailAddress = !!userSettings?.Email?.Reset && !!userSettings?.Email?.Value;
12 const hasRecoveryPhoneNumber = !!userSettings?.Phone?.Reset && !!userSettings?.Phone?.Value;
14 const primaryRecoverySecret = usePrimaryRecoverySecret();
15 const hasCurrentRecoveryFile = primaryRecoverySecret !== undefined;
17 const accountRecoveryStatus: RecoveryStatus =
18 hasVerifiedRecoveryEmailAddress || hasRecoveryPhoneNumber ? 'complete' : 'incomplete';
20 const mnemonicIsSet = user.MnemonicStatus === MNEMONIC_STATUS.SET;
21 const dataRecoveryStatus: RecoveryStatus = mnemonicIsSet || hasCurrentRecoveryFile ? 'complete' : 'incomplete';
25 accountRecoveryStatus,
29 loadingUserSettings || !userSettings,
33 export default useRecoveryStatus;