Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / components / hooks / useRecoveryStatus.ts
blobbd5a2300ee57e315b7b2649e2aeff0160dce141d
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';
23     return [
24         {
25             accountRecoveryStatus,
26             dataRecoveryStatus,
27             mnemonicIsSet,
28         },
29         loadingUserSettings || !userSettings,
30     ] as const;
33 export default useRecoveryStatus;