1 import { c } from 'ttag';
3 import { useAddresses } from '@proton/account/addresses/hooks';
4 import { useUser } from '@proton/account/user/hooks';
5 import { ThemeColor } from '@proton/colors';
6 import useIsRecoveryFileAvailable from '@proton/components/hooks/recoveryFile/useIsRecoveryFileAvailable';
7 import useHasOutdatedRecoveryFile from '@proton/components/hooks/useHasOutdatedRecoveryFile';
8 import { FeatureCode, useFeature } from '@proton/features';
9 import { MNEMONIC_STATUS } from '@proton/shared/lib/interfaces';
10 import { getLikelyHasKeysToReactivate } from '@proton/shared/lib/keys/getInactiveKeys';
12 import useSecurityCenter from '../components/drawer/views/SecurityCenter/useSecurityCenter';
13 import { getOverallStatus } from '../containers/recovery/getOverallStatus';
14 import useIsDataRecoveryAvailable from './useIsDataRecoveryAvailable';
15 import useIsMnemonicAvailable from './useIsMnemonicAvailable';
16 import useIsSentinelUser from './useIsSentinelUser';
17 import useRecoveryStatus from './useRecoveryStatus';
19 const useRecoveryNotification = (
20 isLessInvasive: boolean,
21 isQuickSettings?: boolean,
22 canDisplayNewSentinelSettings?: boolean
23 ): { path: string; text: string; color: ThemeColor } | undefined => {
24 const [user] = useUser();
25 const [addresses, loadingAddresses] = useAddresses();
26 const isSecurityCenterEnabled = useSecurityCenter();
27 const alreadyDisplayedInSecurityCenter = isSecurityCenterEnabled && isQuickSettings;
29 const [{ accountRecoveryStatus, dataRecoveryStatus, mnemonicIsSet }, loadingRecoveryStatus] = useRecoveryStatus();
31 const [isRecoveryFileAvailable, loadingIsRecoveryFileAvailable] = useIsRecoveryFileAvailable();
32 const [isMnemonicAvailable, loadingIsMnemonicAvailable] = useIsMnemonicAvailable();
33 const [isDataRecoveryAvailable, loadingIsDataRecoveryAvailable] = useIsDataRecoveryAvailable();
34 const hasOutdatedRecoveryFile = useHasOutdatedRecoveryFile();
35 const [{ isSentinelUser, hasMnemonic }, loadingIsSentinelUser] = useIsSentinelUser();
37 const { feature: hasDismissedRecoverDataCard } = useFeature(FeatureCode.DismissedRecoverDataCard);
38 const hasKeysToReactivate = getLikelyHasKeysToReactivate(user, addresses);
40 const overallStatus = getOverallStatus({ accountRecoveryStatus, dataRecoveryStatus, isDataRecoveryAvailable });
43 loadingRecoveryStatus ||
44 loadingIsRecoveryFileAvailable ||
45 loadingIsMnemonicAvailable ||
46 loadingIsDataRecoveryAvailable ||
47 loadingIsSentinelUser ||
53 if (!isDataRecoveryAvailable) {
57 const hasOutdatedMnemonic = user.MnemonicStatus === MNEMONIC_STATUS.OUTDATED;
58 if (isMnemonicAvailable && hasOutdatedMnemonic) {
60 path: '/recovery#data',
61 text: c('Action').t`Update recovery phrase`,
62 color: ThemeColor.Danger,
66 if (isRecoveryFileAvailable && hasOutdatedRecoveryFile && !alreadyDisplayedInSecurityCenter) {
68 path: '/recovery#data',
69 text: c('Action').t`Update recovery file`,
70 color: ThemeColor.Danger,
78 if (hasKeysToReactivate && hasDismissedRecoverDataCard?.Value === false) {
80 path: '/recovery?action=recover-data',
81 text: c('Action').t`Unlock data`,
82 color: ThemeColor.Danger,
85 // keeps account recovery notification dot consistent with mail security center for new recovery settings for sentinel users
86 if (isSentinelUser && canDisplayNewSentinelSettings && !alreadyDisplayedInSecurityCenter) {
89 path: '/recovery#data',
90 text: c('Action').t`Update recovery phrase`,
91 color: ThemeColor.Danger,
97 if (mnemonicIsSet || overallStatus === 'complete') {
101 const mnemonicCanBeSet =
102 user.MnemonicStatus === MNEMONIC_STATUS.ENABLED || user.MnemonicStatus === MNEMONIC_STATUS.PROMPT;
103 if (isMnemonicAvailable && mnemonicCanBeSet && !alreadyDisplayedInSecurityCenter) {
105 path: '/recovery?action=generate-recovery-phrase',
106 text: c('Action').t`Set recovery phrase`,
107 color: ThemeColor.Warning,
111 if (!alreadyDisplayedInSecurityCenter) {
114 text: c('Action').t`Activate recovery`,
115 color: ThemeColor.Warning,
120 export default useRecoveryNotification;