Remove client-side isLoggedIn value
[ProtonMail-WebClient.git] / packages / drive-store / components / SignatureAlert.tsx
blobdc3f359429d08095b01161ae33d72846878d9a7a
1 import { c } from 'ttag';
3 import { Alert, TextLoader } from '@proton/components';
4 import { VERIFICATION_STATUS } from '@proton/crypto';
5 import { getKnowledgeBaseUrl } from '@proton/shared/lib/helpers/url';
7 import type { SignatureIssueLocation, SignatureIssues } from '../store';
9 type Props = {
10     loading: boolean;
11     signatureIssues: SignatureIssues | undefined;
12     signatureNetworkError?: boolean;
13     signatureAddress: string | undefined;
14     isFile: boolean;
15     name: string;
16     corruptedLink?: boolean;
17     className?: string;
20 export default function SignatureAlert({
21     loading,
22     signatureIssues,
23     signatureNetworkError,
24     corruptedLink,
25     className,
26     ...props
27 }: Props) {
28     if (loading) {
29         return (
30             <Alert type="info" className={className}>
31                 <TextLoader className="m-0">{c('Info').t`Checking signatures`}</TextLoader>
32             </Alert>
33         );
34     }
36     if (corruptedLink) {
37         return (
38             <Alert type="warning" className={className}>
39                 <span>{c('Info')
40                     .t`Unfortunately, it appears that the file or some of its data cannot be decrypted.`}</span>
41             </Alert>
42         );
43     }
45     if (signatureNetworkError) {
46         return (
47             <Alert type="warning" className={className}>
48                 <span>{c('Info').t`Signature cannot be validated due to network error, please try again later.`}</span>
49             </Alert>
50         );
51     }
53     return (
54         <Alert type={signatureIssues ? 'error' : 'success'} className={className}>
55             <SignatureAlertBody signatureIssues={signatureIssues} {...props} />
56         </Alert>
57     );
60 type PropsBody = {
61     signatureIssues: SignatureIssues | undefined;
62     signatureAddress: string | undefined;
63     isFile: boolean;
64     name: string;
67 export function SignatureAlertBody({ signatureIssues, signatureAddress, isFile, name }: PropsBody) {
68     const fileName = (
69         <strong className="text-break" key="fileName">
70             {name}
71         </strong>
72     );
74     const emailAddress = (
75         <strong className="text-break" key="signatureAddress" data-testid="signature-address">
76             {signatureAddress}
77         </strong>
78     );
80     if (!signatureIssues) {
81         return (
82             <>
83                 {isFile
84                     ? c('Info').jt`Digital signature verified. This file was securely uploaded by ${emailAddress}.`
85                     : c('Info').jt`Digital signature verified. This folder was securely uploaded by ${emailAddress}.`}
86             </>
87         );
88     }
90     const locationTranslations: { [key in SignatureIssueLocation]: string } = {
91         passphrase: c('Item').t`keys`,
92         hash: c('Item').t`hash key`,
93         name: c('Item').t`name`,
94         xattrs: c('Item').t`file attributes`,
95         contentKeyPacket: c('Item').t`file data key`,
96         blocks: c('Item').t`file data`,
97         thumbnail: c('Item').t`thumbnail`,
98         manifest: c('Item').t`file data order`,
99     };
100     const items = Object.keys(signatureIssues)
101         .map((location) => locationTranslations[location as SignatureIssueLocation])
102         .join(', ');
104     const statuses = Object.values(signatureIssues);
105     const hasNoSignatureIssue = statuses.some((status) => status === VERIFICATION_STATUS.NOT_SIGNED);
106     const hasBadSignatureIssue = statuses.some((status) => status === VERIFICATION_STATUS.SIGNED_AND_INVALID);
108     let textReason;
109     let textWarning;
110     if (hasNoSignatureIssue && !hasBadSignatureIssue) {
111         if (signatureAddress) {
112             textReason = isFile
113                 ? c('Info').jt`File is missing signature. We couldn’t verify that ${emailAddress} uploaded ${fileName}.`
114                 : c('Info')
115                       .jt`Folder is missing signature. We couldn’t verify that ${emailAddress} uploaded ${fileName}.`;
116         } else {
117             textReason = isFile
118                 ? c('Info').jt`File is missing signature. We couldn’t verify who uploaded ${fileName}.`
119                 : c('Info').jt`Folder is missing signature. We couldn’t verify who uploaded ${fileName}.`;
120         }
121         textWarning = c('Info').jt`The following may have been tampered with: ${items}. Only open if you trust it.`;
122     } else {
123         if (signatureAddress) {
124             textReason = c('Info').jt`We couldn’t verify that ${emailAddress} uploaded ${fileName}.`;
125             textWarning = c('Info')
126                 .jt`The account may have a new key, or the following may have been tampered with: ${items}. Only open if you trust it.`;
127         } else {
128             textReason = c('Info').jt`We couldn’t verify who uploaded ${fileName}.`;
129             textWarning = c('Info').jt`The following may have been tampered with: ${items}. Only open if you trust it.`;
130         }
131     }
133     return (
134         <>
135             {textReason}
136             &nbsp;
137             {textWarning}
138             &nbsp;
139             <a href={getKnowledgeBaseUrl('/drive-signature-management')} target="_blank">
140                 {c('Action').t`Learn more`}
141             </a>
142         </>
143     );