1 import { useUser } from '@proton/account/user/hooks';
2 import { useUserSettings } from '@proton/account/userSettings/hooks';
3 import { MNEMONIC_STATUS, SETTINGS_PROTON_SENTINEL_STATE } from '@proton/shared/lib/interfaces';
5 import useIsMnemonicAvailable from './useIsMnemonicAvailable';
7 const useIsSentinelUser = () => {
8 const [userSettings, loadingUserSettings] = useUserSettings();
9 const [isMnemonicAvailable, loadingIsMnemonicAvailable] = useIsMnemonicAvailable();
10 const [user] = useUser();
12 const isSentinelUser = userSettings?.HighSecurity?.Value === SETTINGS_PROTON_SENTINEL_STATE.ENABLED;
14 const hasEmail = !!userSettings?.Email?.Value;
15 const hasEmailVerified = !!userSettings?.Email?.Status;
16 const hasEmailEnabled = !!userSettings?.Email?.Reset;
17 const hasPhone = !!userSettings?.Phone?.Value;
18 const hasPhoneVerified = !!userSettings?.Phone?.Status;
19 const hasPhoneEnabled = !!userSettings?.Phone?.Reset;
21 const hasVerifiedandDisabledEmail = hasEmail && hasEmailVerified && !hasEmailEnabled;
22 const hasVerifiedandDisabledPhone = hasPhone && hasPhoneVerified && !hasPhoneEnabled;
23 const hasRecoveryMethod = hasVerifiedandDisabledEmail || hasVerifiedandDisabledPhone;
24 const hasMnemonic = isMnemonicAvailable && user.MnemonicStatus === MNEMONIC_STATUS.SET;
26 const getSentinelRecoveryStatus = () => {
27 if (isSentinelUser && hasMnemonic && hasRecoveryMethod) {
30 if (isSentinelUser && hasMnemonic) {
31 return 'intermediate';
33 if (isSentinelUser && !hasMnemonic && ((hasEmail && hasEmailEnabled) || (hasPhone && hasPhoneEnabled))) {
40 const sentinelRecoveryStatus = getSentinelRecoveryStatus();
44 sentinelRecoveryStatus,
47 loadingUserSettings || !userSettings || loadingIsMnemonicAvailable,
51 export default useIsSentinelUser;