-
Notifications
You must be signed in to change notification settings - Fork 96
/
embedded-verification-2.patch
129 lines (127 loc) · 4.25 KB
/
embedded-verification-2.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
diff --git a/packages/components/containers/index.ts b/packages/components/containers/index.ts
index 9bfef3d1f..546b273c8 100644
--- a/packages/components/containers/index.ts
+++ b/packages/components/containers/index.ts
@@ -58,6 +58,5 @@ export * from './sessions';
export * from './support';
export * from './themes';
export * from './topBanners';
-export * from './verification';
export * from './v5WelcomeModal';
export * from './vpn';
diff --git a/packages/components/containers/verification/EmbeddedVerification.tsx b/packages/components/containers/verification/EmbeddedVerification.tsx
deleted file mode 100644
index 6425df9ec..000000000
--- a/packages/components/containers/verification/EmbeddedVerification.tsx
+++ /dev/null
@@ -1,103 +0,0 @@
-import { useEffect, useMemo, useRef, useState } from 'react';
-
-import { APPS } from '@proton/shared/lib/constants';
-import { getAppUrlFromApiUrl, getAppUrlRelativeToOrigin, stringifySearchParams } from '@proton/shared/lib/helpers/url';
-import { localeCode } from '@proton/shared/lib/i18n';
-import { HumanVerificationMethodType } from '@proton/shared/lib/interfaces';
-
-import { useConfig, useNotifications } from '../../hooks';
-
-interface EmbeddedVerificationProps {
- token: string;
- methods: HumanVerificationMethodType[];
- defaultCountry?: string;
- defaultEmail?: string;
- defaultPhone?: string;
- onSuccess: (token: string, tokenType: HumanVerificationMethodType) => void;
-}
-
-const EmbeddedVerification = ({
- token,
- methods,
- onSuccess,
- defaultCountry,
- defaultEmail,
- defaultPhone,
-}: EmbeddedVerificationProps) => {
- const iframeRef = useRef<HTMLIFrameElement>(null);
- const [iframeHeight, setIframeHeight] = useState<number | undefined>();
- const { API_URL } = useConfig();
- const { createNotification } = useNotifications();
-
- const embedUrl = useMemo(() => {
- if (window.location.origin.includes('localhost')) {
- return getAppUrlFromApiUrl(API_URL, APPS.PROTONVERIFICATION);
- }
-
- return getAppUrlRelativeToOrigin(window.location.origin, APPS.PROTONVERIFICATION);
- }, []);
-
- useEffect(() => {
- const handleMessage = (e: MessageEvent) => {
- const { origin, data, source } = e;
-
- const contentWindow = iframeRef.current?.contentWindow;
-
- if (!contentWindow || origin !== embedUrl.origin || !data || source !== contentWindow) {
- return;
- }
-
- const { type, payload } = JSON.parse(e.data);
-
- switch (type) {
- case 'RESIZE': {
- const { height } = payload;
- setIframeHeight(height);
- break;
- }
-
- case 'NOTIFICATION': {
- createNotification(payload);
- break;
- }
-
- case 'HUMAN_VERIFICATION_SUCCESS': {
- const { token, type } = payload;
- onSuccess(token, type);
- break;
- }
-
- default:
- }
- };
-
- window.addEventListener('message', handleMessage);
-
- return () => {
- window.removeEventListener('message', handleMessage);
- };
- }, [onSuccess]);
-
- const params = {
- methods,
- token,
- defaultCountry: defaultCountry || undefined,
- defaultEmail: defaultEmail || undefined,
- defaultPhone: defaultPhone || undefined,
- locale: localeCode,
- };
-
- const src = `${embedUrl.toString()}?${stringifySearchParams(params)}`;
-
- return (
- <iframe
- style={{ height: `${iframeHeight}px`, width: '100%' }}
- src={src}
- ref={iframeRef}
- title="verification-iframe"
- sandbox="allow-scripts allow-same-origin allow-popups"
- />
- );
-};
-
-export default EmbeddedVerification;
diff --git a/packages/components/containers/verification/index.ts b/packages/components/containers/verification/index.ts
deleted file mode 100644
index 16a977e60..000000000
--- a/packages/components/containers/verification/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default as EmbeddedVerification } from './EmbeddedVerification';