@sanctum-key/react-native-sdk 1.0.18 → 1.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/build/package.json +3 -2
- package/build/src/components/EnhancedCameraView.d.ts.map +1 -1
- package/build/src/components/EnhancedCameraView.js +19 -182
- package/build/src/components/EnhancedCameraView.js.map +1 -1
- package/build/src/components/KYCElements/CountrySelectionTemplate.d.ts.map +1 -1
- package/build/src/components/KYCElements/CountrySelectionTemplate.js +40 -128
- package/build/src/components/KYCElements/CountrySelectionTemplate.js.map +1 -1
- package/build/src/components/KYCElements/IDCardCapture.d.ts.map +1 -1
- package/build/src/components/KYCElements/IDCardCapture.js +224 -189
- package/build/src/components/KYCElements/IDCardCapture.js.map +1 -1
- package/build/src/components/KYCElements/PhoneVerificationTemplate.d.ts.map +1 -1
- package/build/src/components/KYCElements/PhoneVerificationTemplate.js +0 -2
- package/build/src/components/KYCElements/PhoneVerificationTemplate.js.map +1 -1
- package/build/src/components/KYCElements/VerificationProgressTemplate.d.ts.map +1 -1
- package/build/src/components/KYCElements/VerificationProgressTemplate.js +38 -33
- package/build/src/components/KYCElements/VerificationProgressTemplate.js.map +1 -1
- package/build/src/components/OverLay/IdCard.d.ts +6 -1
- package/build/src/components/OverLay/IdCard.d.ts.map +1 -1
- package/build/src/components/OverLay/IdCard.js +36 -34
- package/build/src/components/OverLay/IdCard.js.map +1 -1
- package/build/src/config/countriesData.d.ts.map +1 -1
- package/build/src/config/countriesData.js.map +1 -1
- package/build/src/hooks/useTemplateKYCFlow.js +1 -1
- package/build/src/hooks/useTemplateKYCFlow.js.map +1 -1
- package/build/src/modules/api/CardAuthentification.d.ts +5 -0
- package/build/src/modules/api/CardAuthentification.d.ts.map +1 -1
- package/build/src/modules/api/CardAuthentification.js +67 -14
- package/build/src/modules/api/CardAuthentification.js.map +1 -1
- package/build/src/modules/api/KYCService.d.ts +10 -0
- package/build/src/modules/api/KYCService.d.ts.map +1 -1
- package/build/src/modules/api/KYCService.js +135 -49
- package/build/src/modules/api/KYCService.js.map +1 -1
- package/build/src/web/WebKYCEntry.d.ts.map +1 -1
- package/build/src/web/WebKYCEntry.js +34 -6
- package/build/src/web/WebKYCEntry.js.map +1 -1
- package/package.json +3 -2
- package/src/components/EnhancedCameraView.tsx +28 -219
- package/src/components/KYCElements/CountrySelectionTemplate.tsx +53 -133
- package/src/components/KYCElements/IDCardCapture.tsx +606 -570
- package/src/components/KYCElements/PhoneVerificationTemplate.tsx +0 -2
- package/src/components/KYCElements/VerificationProgressTemplate.tsx +54 -66
- package/src/components/OverLay/IdCard.tsx +48 -36
- package/src/config/countriesData.ts +0 -4
- package/src/hooks/useTemplateKYCFlow.tsx +14 -14
- package/src/modules/api/CardAuthentification.ts +133 -67
- package/src/modules/api/KYCService.ts +189 -66
- package/src/web/WebKYCEntry.tsx +42 -7
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useEffect, useMemo, useState } from 'react';
|
|
2
|
-
import { View, Text, StyleSheet, Image, ScrollView, Platform, ActivityIndicator, TouchableOpacity } from 'react-native';
|
|
2
|
+
import { View, Text, StyleSheet, Image, ScrollView, Platform, ActivityIndicator, TouchableOpacity, useWindowDimensions } from 'react-native';
|
|
3
3
|
import { showAlert } from '../../utils/platformAlert';
|
|
4
4
|
import { EnhancedCameraView } from '../EnhancedCameraView';
|
|
5
5
|
import { TemplateComponent, LocalizedText, GovernmentDocumentType, ISilentCaptureResult, IBbox, GovernmentDocumentTypeShorted, GovernmentDocumentTypeBackend } from '../../types/KYC.types';
|
|
@@ -13,586 +13,622 @@ import { getDocumentTypeInfo } from '../../utils/get-document-type-info';
|
|
|
13
13
|
import pathToBase64 from '../../utils/pathToBase64';
|
|
14
14
|
import { cropByObb, cropImageWithBBoxWithTolerance, getObbConfidence, OBB_CONFIDENCE_THRESHOLD } from '../../utils/cropByObb';
|
|
15
15
|
import REGION_MAPPING from '../../config/region_mapping.json';
|
|
16
|
+
import QRCode from 'react-native-qrcode-svg';
|
|
16
17
|
|
|
17
18
|
const ISO_TO_COUNTRY_NAME: Record<string, string> = { 'KE': 'Kenya', 'CM': 'Cameroon', 'NG': 'Nigeria', 'CA': 'Canada', 'FR': 'France', 'GH': 'Ghana', 'ZA': 'South Africa', 'GB': 'Britain', 'CI': 'Ivory Coast', 'SN': 'Senegal', 'TG': 'Togo', 'ML': 'Mali' };
|
|
18
19
|
|
|
19
20
|
interface IIDCardPayload { dir: string; file: string; mrz: string; templatePath?: string; }
|
|
20
|
-
interface IDCardCaptureProps {
|
|
21
|
+
interface IDCardCaptureProps {
|
|
22
|
+
component: TemplateComponent;
|
|
23
|
+
value?: Record<string, IIDCardPayload>;
|
|
24
|
+
onValueChange: (value: Record<string, IIDCardPayload | string>) => void;
|
|
25
|
+
error?: string;
|
|
26
|
+
language?: string;
|
|
27
|
+
currentSide?: string;
|
|
28
|
+
}
|
|
21
29
|
|
|
22
30
|
export const IDCardCapture: React.FC<IDCardCaptureProps> = ({ component, value = {}, onValueChange, error, language = 'en' }) => {
|
|
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
|
-
return {
|
|
90
|
-
cameraType: Platform.OS === 'web' ? cameraType : 'back',
|
|
91
|
-
flashMode: 'auto' as const,
|
|
92
|
-
overlay: {
|
|
93
|
-
guideText: instructions,
|
|
94
|
-
bbox: { xMin: 5, yMin: 15, xMax: 95, yMax: 85, borderColor: '#2DBD60', borderWidth: 3, cornerRadius: 8 }
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
}, [selectedDocumentType, locale, component.instructions, cameraType]);
|
|
98
|
-
|
|
99
|
-
const retakePicture = (sideToRetake: 'front' | 'back') => {
|
|
100
|
-
setIsProcessingCapture(false);
|
|
101
|
-
setProcessingImagePath(null);
|
|
102
|
-
setSilentCaptureResult({ path: '', success: false, isAnalyzing: false, error: '', templatePath: '', mrz: '', bbox: undefined });
|
|
103
|
-
setShowCamera(true);
|
|
104
|
-
refreshCamera();
|
|
105
|
-
actions.showCustomStepper(false);
|
|
106
|
-
setCapturedImages((prev) => { const newState = { ...prev }; delete newState[sideToRetake]; return newState; });
|
|
107
|
-
if (value) { const newValue = { ...value }; delete newValue[sideToRetake]; onValueChange(newValue); }
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const getCurrentSideVerification = (currentSide: string, countryKey: string) => {
|
|
111
|
-
const rawDocType = countrySelectionData?.documentType;
|
|
112
|
-
if (!rawDocType || !countryKey) { return { authMethod: [], mrzTypes: [], regionMapping: null, key: 'root' }; }
|
|
113
|
-
const rawCountryName = ISO_TO_COUNTRY_NAME[countryData?.code || ''] || countryData?.code || countryKey;
|
|
114
|
-
const baseMapping = (REGION_MAPPING as any).regionMapping || REGION_MAPPING;
|
|
115
|
-
let countryMapping = baseMapping[rawCountryName];
|
|
116
|
-
if (!countryMapping) {
|
|
117
|
-
const foundKey = Object.keys(baseMapping).find(k => k.toLowerCase() === rawCountryName.toLowerCase() || k.toLowerCase() === countryKey.toLowerCase());
|
|
118
|
-
if (foundKey) countryMapping = baseMapping[foundKey];
|
|
119
|
-
}
|
|
120
|
-
if (!countryMapping) { return { authMethod: [], mrzTypes: [], regionMapping: null, key: 'root' }; }
|
|
121
|
-
const regionMapping = countryMapping[rawDocType];
|
|
122
|
-
if (!regionMapping) { return { authMethod: [], mrzTypes: [], regionMapping: null, key: 'root' }; }
|
|
123
|
-
const authMethod: string[] = [];
|
|
124
|
-
const mrzTypes: string[] = [];
|
|
125
|
-
const key = countrySelectionData.region?.trim()?.length > 0 ? countrySelectionData.region.trim() : 'root';
|
|
126
|
-
if (regionMapping?.[key] && Array.isArray(regionMapping[key])) {
|
|
127
|
-
regionMapping[key].forEach((item: any) => {
|
|
128
|
-
if (item[currentSide]) {
|
|
129
|
-
authMethod.push(item[currentSide]);
|
|
130
|
-
if (item?.mrz_type) mrzTypes.push(item?.mrz_type);
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
return { authMethod: removeDuplicates(authMethod), mrzTypes: removeDuplicates(mrzTypes), regionMapping, key };
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const getCorrespondingMrzType = (templatePath: string, mapping: any, selectedDocumentType: string = "root") => {
|
|
138
|
-
if (!mapping || !mapping[selectedDocumentType]) return null;
|
|
139
|
-
const fileName = templatePath.split("/").pop()?.replace(".jpg", "").replace(".png", "");
|
|
140
|
-
if (!fileName) return null;
|
|
141
|
-
const pyName = `${fileName}.py`;
|
|
142
|
-
const found = mapping[selectedDocumentType].find((item: any) => item.py_file === pyName);
|
|
143
|
-
return found?.mrz_type || null;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const getCorrespondingAuthMethod = (templatePath: string, mapping: any, selectedDocumentType: string = "root", side: 'front' | 'back') => {
|
|
147
|
-
if (!mapping || !mapping[selectedDocumentType]) return null;
|
|
148
|
-
const fileName = templatePath.split("/").pop()?.replace(".jpg", "").replace(".png", "");
|
|
149
|
-
if (!fileName) return null;
|
|
150
|
-
const pyName = `${fileName}.py`;
|
|
151
|
-
const found = mapping[selectedDocumentType].find((item: any) => item.py_file === pyName);
|
|
152
|
-
return found?.[side] || null;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const autoCapture = async (capturePath: string, verified: ISilentCaptureResult) => {
|
|
156
|
-
if (isProcessingCapture) return;
|
|
157
|
-
setIsProcessingCapture(true);
|
|
158
|
-
setProcessingImagePath(capturePath);
|
|
159
|
-
|
|
160
|
-
try {
|
|
161
|
-
let imagePathForUpload = capturePath;
|
|
162
|
-
|
|
163
|
-
const overlayBbox = cameraConfig.overlay.bbox;
|
|
164
|
-
const uiCropBbox = {
|
|
165
|
-
minX: overlayBbox.xMin / 100,
|
|
166
|
-
minY: overlayBbox.yMin / 100,
|
|
167
|
-
width: (overlayBbox.xMax - overlayBbox.xMin) / 100,
|
|
168
|
-
height: (overlayBbox.yMax - overlayBbox.yMin) / 100,
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
try {
|
|
172
|
-
// Apply the crop using the UI percentages and a tight 2% tolerance
|
|
173
|
-
// NOTE: If you integrated the Kotlin centered crop function earlier, replace this with cropToCenterScanArea
|
|
174
|
-
imagePathForUpload = await cropImageWithBBoxWithTolerance(capturePath, uiCropBbox, 0.02);
|
|
175
|
-
} catch (e) {
|
|
176
|
-
console.warn("Crop failed, falling back to original image", e);
|
|
177
|
-
imagePathForUpload = capturePath;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const base64 = await pathToBase64(imagePathForUpload);
|
|
181
|
-
const newImages = {
|
|
182
|
-
...capturedImages,
|
|
183
|
-
[currentSide]: { dir: imagePathForUpload, file: base64, mrz: verified.mrz || "", templatePath: verified.templatePath },
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
setCapturedImages(newImages);
|
|
187
|
-
|
|
188
|
-
if (verified.country && verified.documentType) {
|
|
189
|
-
onValueChange({
|
|
190
|
-
...newImages,
|
|
191
|
-
country: verified.country,
|
|
192
|
-
documentType: GovernmentDocumentTypeBackend[verified.documentType as keyof typeof GovernmentDocumentTypeBackend] || '',
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
setTimeout(() => {
|
|
197
|
-
setShowCamera(false);
|
|
198
|
-
actions.showCustomStepper(true);
|
|
199
|
-
setSilentCaptureResult(prev => ({ ...prev, isAnalyzing: false }));
|
|
200
|
-
setIsProcessingCapture(false);
|
|
201
|
-
setProcessingImagePath(null);
|
|
202
|
-
}, 600);
|
|
203
|
-
|
|
204
|
-
} catch (e: any) {
|
|
205
|
-
console.error("Backend Error:", e);
|
|
206
|
-
const friendlyError = state.currentLanguage === 'en' ? 'Unable to process document. Please try again.' : 'Impossible de traiter le document. Veuillez réessayer.';
|
|
207
|
-
showAlert('Error', friendlyError);
|
|
208
|
-
setSilentCaptureResult(prev => ({ ...prev, isAnalyzing: false, success: false }));
|
|
209
|
-
setIsProcessingCapture(false);
|
|
210
|
-
setProcessingImagePath(null);
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
const handleSilentCapture = async (result: { success: boolean; path?: string; error?: string }) => {
|
|
215
|
-
if (silentCaptureResult.isAnalyzing || isProcessingCapture) return;
|
|
216
|
-
if (result.success && result.path) {
|
|
217
|
-
setSilentCaptureResult((prev) => ({ ...prev, isAnalyzing: true, success: false, error: '' }));
|
|
218
|
-
let templatePath = capturedImages[currentSide]?.templatePath || '';
|
|
219
|
-
let templateBbox: IBbox | undefined;
|
|
220
|
-
let templateResponse: any;
|
|
221
|
-
if (!selectedDocumentType) {
|
|
222
|
-
setSilentCaptureResult((prev) => ({ ...prev, isAnalyzing: false, success: false, error: 'Document type not selected' }));
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
try {
|
|
226
|
-
if (!templatePath) {
|
|
227
|
-
const templateType = await checkTemplateType({ path: result.path || '', docType: selectedDocumentType?.type as GovernmentDocumentType, docRegion: countryData?.code || "", postfix: currentSide }, env);
|
|
228
|
-
templateResponse = templateType;
|
|
229
|
-
if (templateType.template_path) templatePath = templateType.template_path;
|
|
230
|
-
if (templateType.card_obb) {
|
|
231
|
-
const obbConfidence = getObbConfidence((templateType as any).card_obb);
|
|
232
|
-
if (obbConfidence !== null && obbConfidence < OBB_CONFIDENCE_THRESHOLD) {
|
|
233
|
-
setSilentCaptureResult((prev) => ({ ...prev, isAnalyzing: false, success: false, error: t('kyc.idCardCapture.cardNotFullyInFrame') }));
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
try {
|
|
237
|
-
const crop = await cropByObb(result.path, (templateType as any).card_obb);
|
|
238
|
-
templateBbox = crop.bbox;
|
|
239
|
-
} catch { }
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
const extractedCountryKey = templatePath ? templatePath.split('/')[0] : (ISO_TO_COUNTRY_NAME[countryData?.code || ''] || 'root');
|
|
243
|
-
const regionMappings = getCurrentSideVerification(currentSide, extractedCountryKey);
|
|
244
|
-
let verificationRes: any;
|
|
245
|
-
if (currentSide === 'front') {
|
|
246
|
-
const matchedAuthMethod = getCorrespondingAuthMethod(templatePath, regionMappings.regionMapping, regionMappings.key || '', 'front');
|
|
247
|
-
const mrzType = getCorrespondingMrzType(templatePath, regionMappings.regionMapping, regionMappings.key || '') || 'TD1';
|
|
248
|
-
verificationRes = await frontVerification({ path: result.path, regionMapping: { authMethod: matchedAuthMethod ? [matchedAuthMethod] : regionMappings.authMethod, mrzTypes: regionMappings.mrzTypes }, selectedDocumentType: GovernmentDocumentTypeShorted[selectedDocumentType?.type as keyof typeof GovernmentDocumentTypeShorted] || '', code: countryData?.code || '', currentSide, templatePath, mrzType }, env);
|
|
249
|
-
} else {
|
|
250
|
-
let matchedBackAuthMethod = getCorrespondingAuthMethod(templatePath, regionMappings.regionMapping, regionMappings.key || '', 'back');
|
|
251
|
-
if (!matchedBackAuthMethod && currentSide === 'back') {
|
|
252
|
-
matchedBackAuthMethod = 'MRZ';
|
|
253
|
-
}
|
|
254
|
-
const backMrzType = getCorrespondingMrzType(templatePath, regionMappings.regionMapping, regionMappings.key || '') || 'TD1';
|
|
255
|
-
verificationRes = await backVerification({ path: result.path, regionMapping: { authMethod: matchedBackAuthMethod ? [matchedBackAuthMethod] : regionMappings.authMethod, mrzTypes: regionMappings.mrzTypes }, selectedDocumentType: GovernmentDocumentTypeShorted[selectedDocumentType.type as keyof typeof GovernmentDocumentTypeShorted] || '', code: countryData?.code || '', currentSide, templatePath, mrzType: backMrzType, templateResponse }, env);
|
|
256
|
-
}
|
|
257
|
-
const bbox = verificationRes?.bbox || templateBbox;
|
|
258
|
-
const mrz = verificationRes?.mrz ? JSON.stringify(verificationRes.mrz) : "";
|
|
259
|
-
const verifiedResult: ISilentCaptureResult = { path: result.path, templatePath, bbox, success: true, mrz, isAnalyzing: false, country: countryData?.code, documentType: selectedDocumentType.type };
|
|
260
|
-
setSilentCaptureResult(verifiedResult);
|
|
261
|
-
if (bbox) setBboxBySide(prev => ({ ...prev, [currentSide]: bbox }));
|
|
262
|
-
await autoCapture(result.path, verifiedResult);
|
|
263
|
-
} catch (error: any) {
|
|
264
|
-
console.log("Backend Verification Error:", error);
|
|
265
|
-
|
|
266
|
-
// 2. Define a map of technical keywords to user-friendly messages
|
|
267
|
-
const rawMessage = (error?.message || '').toLowerCase();
|
|
268
|
-
|
|
269
|
-
let userFriendlyMessage ='Verification failed. Please try again.';
|
|
270
|
-
|
|
271
|
-
if (rawMessage.includes('impossible') || rawMessage.includes('unreadable')) {
|
|
272
|
-
userFriendlyMessage = 'Document unreadable. Please hold the camera steady in good light.';
|
|
273
|
-
} else if (rawMessage.includes('country mismatch') || rawMessage.includes('pays sélectionné')) {
|
|
274
|
-
userFriendlyMessage = 'The document does not match your selected country.';
|
|
275
|
-
} else if (rawMessage.includes('card_not_fully_in_frame')) {
|
|
276
|
-
// 🚨 REMOVED 'too far' CHECK FROM HERE
|
|
277
|
-
userFriendlyMessage = 'Move closer to the document and ensure all corners are visible.';
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// 3. Set ONLY the friendly message to the UI state
|
|
281
|
-
setSilentCaptureResult(prev => ({
|
|
282
|
-
...prev,
|
|
283
|
-
isAnalyzing: false,
|
|
284
|
-
success: false,
|
|
285
|
-
error: userFriendlyMessage
|
|
31
|
+
const { t, locale } = useI18n();
|
|
32
|
+
const [showCamera, setShowCamera] = useState(false);
|
|
33
|
+
const [capturedImages, setCapturedImages] = useState<Record<string, IIDCardPayload>>(value || {});
|
|
34
|
+
const [currentSide, setCurrentSide] = useState<'front' | 'back'>('front');
|
|
35
|
+
const [bboxBySide, setBboxBySide] = useState<Record<string, IBbox>>({});
|
|
36
|
+
const [silentCaptureResult, setSilentCaptureResult] = useState<ISilentCaptureResult>({ success: false, isAnalyzing: false });
|
|
37
|
+
const [isProcessingCapture, setIsProcessingCapture] = useState(false);
|
|
38
|
+
const [processingImagePath, setProcessingImagePath] = useState<string | null>(null);
|
|
39
|
+
const [cameraKey, setCameraKey] = useState(0);
|
|
40
|
+
const [isRebootingCamera, setIsRebootingCamera] = useState(false);
|
|
41
|
+
const [cameraType, setCameraType] = useState<'back' | 'front'>('back');
|
|
42
|
+
const [showQRModal, setShowQRModal] = useState(false);
|
|
43
|
+
const [currentUrl, setCurrentUrl] = useState('');
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (typeof window !== 'undefined' && window.location) {
|
|
47
|
+
setCurrentUrl(window.location.href);
|
|
48
|
+
}
|
|
49
|
+
}, []);
|
|
50
|
+
|
|
51
|
+
const documentTypeMapping: Record<string, GovernmentDocumentType> = { 'nationalId': 'national_id', 'passport': 'passport', 'driversLicense': 'drivers_licence', 'residencePermit': 'permanent_residence', 'healthInsuranceCard': 'health_insurance_card', };
|
|
52
|
+
|
|
53
|
+
const { actions, state, env } = useTemplateKYCFlowContext();
|
|
54
|
+
const { width: screenWidth, height: screenHeight } = useWindowDimensions();
|
|
55
|
+
|
|
56
|
+
const getLocalizedText = (text: LocalizedText | Record<string, LocalizedText>): string => {
|
|
57
|
+
if (text && typeof text[currentSide] === 'object' && text[currentSide][locale]) return text[currentSide][locale] || '';
|
|
58
|
+
return "";
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const countrySelectionData = useMemo(() => {
|
|
62
|
+
const countrySelectionComponent = state.template.components.find(c => c.type === 'country_selection');
|
|
63
|
+
return countrySelectionComponent ? state.componentData[countrySelectionComponent.id] : null;
|
|
64
|
+
}, [state.template.components, state.componentData]);
|
|
65
|
+
|
|
66
|
+
const selectedDocumentType = useMemo<{ type: GovernmentDocumentType; region: string } | null>(() => {
|
|
67
|
+
if (!countrySelectionData?.documentType) return null;
|
|
68
|
+
const backendDocType = countrySelectionData.documentType;
|
|
69
|
+
const mappedType = documentTypeMapping[backendDocType] || backendDocType as GovernmentDocumentType;
|
|
70
|
+
return { type: mappedType, region: countrySelectionData.region || 'root' };
|
|
71
|
+
}, [countrySelectionData, documentTypeMapping]);
|
|
72
|
+
|
|
73
|
+
const countryData = useMemo(() => countrySelectionData, [countrySelectionData]);
|
|
74
|
+
|
|
75
|
+
const refreshCamera = () => {
|
|
76
|
+
setIsRebootingCamera(true);
|
|
77
|
+
setTimeout(() => {
|
|
78
|
+
setCameraKey(prev => prev + 1);
|
|
79
|
+
setIsRebootingCamera(false);
|
|
80
|
+
}, 500);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const toggleCameraLens = () => {
|
|
84
|
+
setCameraType(prev => prev === 'back' ? 'front' : 'back');
|
|
85
|
+
refreshCamera();
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
if (value && Object.keys(value).length > 0) {
|
|
90
|
+
if (JSON.stringify(value) !== JSON.stringify(capturedImages)) {
|
|
91
|
+
const updatedImages = value as Record<string, IIDCardPayload>;
|
|
92
|
+
setCapturedImages(updatedImages);
|
|
93
|
+
const currentImageData = updatedImages[currentSide];
|
|
94
|
+
if (currentImageData?.dir) {
|
|
95
|
+
setSilentCaptureResult(prev => ({
|
|
96
|
+
...prev, path: currentImageData.dir, success: true, isAnalyzing: false, mrz: currentImageData.mrz || '', templatePath: currentImageData.templatePath || '',
|
|
286
97
|
}));
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}, [value, currentSide]);
|
|
102
|
+
|
|
103
|
+
const cameraConfig = useMemo(() => {
|
|
104
|
+
const instructions = selectedDocumentType ? (locale === 'en' ? getDocumentTypeInfo(selectedDocumentType.type).instructions.en : getDocumentTypeInfo(selectedDocumentType.type).instructions.fr) : getLocalizedText(component.instructions as Record<string, LocalizedText>);
|
|
105
|
+
const isLandscape = screenWidth > screenHeight;
|
|
106
|
+
let xMin, xMax, yMin, yMax;
|
|
107
|
+
|
|
108
|
+
if (Platform.OS === 'web') {
|
|
109
|
+
const boxWidthPercent = isLandscape ? 0.40 : 0.85;
|
|
110
|
+
xMin = isLandscape ? 30 : 7.5;
|
|
111
|
+
xMax = xMin + (boxWidthPercent * 100);
|
|
112
|
+
const containerWidth = Math.min(screenWidth * 0.95, 1000);
|
|
113
|
+
const containerHeight = isLandscape ? screenHeight * 0.80 : screenHeight * 0.90;
|
|
114
|
+
const boxPixelWidth = containerWidth * boxWidthPercent;
|
|
115
|
+
const boxPixelHeight = boxPixelWidth / 1.59;
|
|
116
|
+
const heightPercent = (boxPixelHeight / containerHeight) * 100;
|
|
117
|
+
yMin = (100 - heightPercent) / 2.5;
|
|
118
|
+
yMax = yMin + heightPercent;
|
|
119
|
+
} else {
|
|
120
|
+
xMin = 5; xMax = 95; yMin = 34; yMax = 66;
|
|
121
|
+
}
|
|
122
|
+
const platformBbox = { xMin, yMin, xMax, yMax, borderColor: '#2DBD60', borderWidth: Platform.OS === 'web' ? 2 : 3, cornerRadius: 8 };
|
|
123
|
+
return {
|
|
124
|
+
cameraType: Platform.OS === 'web' ? cameraType : 'back',
|
|
125
|
+
flashMode: 'auto' as const,
|
|
126
|
+
overlay: { guideText: instructions, bbox: platformBbox }
|
|
127
|
+
};
|
|
128
|
+
}, [selectedDocumentType, locale, component.instructions, cameraType, screenWidth, screenHeight]);
|
|
129
|
+
|
|
130
|
+
const retakePicture = (sideToRetake: 'front' | 'back') => {
|
|
131
|
+
setIsProcessingCapture(false);
|
|
132
|
+
setProcessingImagePath(null);
|
|
133
|
+
setSilentCaptureResult({ path: '', success: false, isAnalyzing: false, error: '', templatePath: '', mrz: '', bbox: undefined });
|
|
134
|
+
setShowCamera(true);
|
|
135
|
+
refreshCamera();
|
|
136
|
+
actions.showCustomStepper(false);
|
|
137
|
+
setCapturedImages((prev) => { const newState = { ...prev }; delete newState[sideToRetake]; return newState; });
|
|
138
|
+
if (value) { const newValue = { ...value }; delete newValue[sideToRetake]; onValueChange(newValue); }
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const getCurrentSideVerification = (currentSide: string, countryKey: string) => {
|
|
142
|
+
const rawDocType = countrySelectionData?.documentType;
|
|
143
|
+
if (!rawDocType || !countryKey) { return { authMethod: [], mrzTypes: [], regionMapping: null, key: 'root' }; }
|
|
144
|
+
const rawCountryName = ISO_TO_COUNTRY_NAME[countryData?.code || ''] || countryData?.code || countryKey;
|
|
145
|
+
const baseMapping = (REGION_MAPPING as any).regionMapping || REGION_MAPPING;
|
|
146
|
+
let countryMapping = baseMapping[rawCountryName];
|
|
147
|
+
if (!countryMapping) {
|
|
148
|
+
const foundKey = Object.keys(baseMapping).find(k => k.toLowerCase() === rawCountryName.toLowerCase() || k.toLowerCase() === countryKey.toLowerCase());
|
|
149
|
+
if (foundKey) countryMapping = baseMapping[foundKey];
|
|
150
|
+
}
|
|
151
|
+
if (!countryMapping) { return { authMethod: [], mrzTypes: [], regionMapping: null, key: 'root' }; }
|
|
152
|
+
const regionMapping = countryMapping[rawDocType];
|
|
153
|
+
if (!regionMapping) { return { authMethod: [], mrzTypes: [], regionMapping: null, key: 'root' }; }
|
|
154
|
+
const authMethod: string[] = [];
|
|
155
|
+
const mrzTypes: string[] = [];
|
|
156
|
+
const key = countrySelectionData.region?.trim()?.length > 0 ? countrySelectionData.region.trim() : 'root';
|
|
157
|
+
if (regionMapping?.[key] && Array.isArray(regionMapping[key])) {
|
|
158
|
+
regionMapping[key].forEach((item: any) => {
|
|
159
|
+
if (item[currentSide]) {
|
|
160
|
+
authMethod.push(item[currentSide]);
|
|
161
|
+
if (item?.mrz_type) mrzTypes.push(item?.mrz_type);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
return { authMethod: removeDuplicates(authMethod), mrzTypes: removeDuplicates(mrzTypes), regionMapping, key };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const getCorrespondingMrzType = (templatePath: string, mapping: any, selectedDocumentType: string = "root") => {
|
|
169
|
+
if (!mapping || !mapping[selectedDocumentType]) return null;
|
|
170
|
+
const fileName = templatePath.split("/").pop()?.replace(".jpg", "").replace(".png", "");
|
|
171
|
+
if (!fileName) return null;
|
|
172
|
+
const pyName = `${fileName}.py`;
|
|
173
|
+
const found = mapping[selectedDocumentType].find((item: any) => item.py_file === pyName);
|
|
174
|
+
return found?.mrz_type || null;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const getCorrespondingAuthMethod = (templatePath: string, mapping: any, selectedDocumentType: string = "root", side: 'front' | 'back') => {
|
|
178
|
+
if (!mapping || !mapping[selectedDocumentType]) return null;
|
|
179
|
+
const fileName = templatePath.split("/").pop()?.replace(".jpg", "").replace(".png", "");
|
|
180
|
+
if (!fileName) return null;
|
|
181
|
+
const pyName = `${fileName}.py`;
|
|
182
|
+
const found = mapping[selectedDocumentType].find((item: any) => item.py_file === pyName);
|
|
183
|
+
return found?.[side] || null;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const autoCapture = async (capturePath: string, verified: ISilentCaptureResult & { region?: string }) => {
|
|
187
|
+
if (isProcessingCapture) return;
|
|
188
|
+
setIsProcessingCapture(true);
|
|
189
|
+
setProcessingImagePath(capturePath);
|
|
190
|
+
try {
|
|
191
|
+
let imagePathForUpload = capturePath;
|
|
192
|
+
const overlayBbox = cameraConfig.overlay.bbox;
|
|
193
|
+
const uiCropBbox = {
|
|
194
|
+
minX: overlayBbox.xMin / 100,
|
|
195
|
+
minY: overlayBbox.yMin / 100,
|
|
196
|
+
width: (overlayBbox.xMax - overlayBbox.xMin) / 100,
|
|
197
|
+
height: (overlayBbox.yMax - overlayBbox.yMin) / 100,
|
|
198
|
+
};
|
|
199
|
+
try {
|
|
200
|
+
imagePathForUpload = await cropImageWithBBoxWithTolerance(capturePath, uiCropBbox, 0.06);
|
|
201
|
+
} catch (e) {
|
|
202
|
+
console.warn("Crop failed, falling back to original image", e);
|
|
203
|
+
imagePathForUpload = capturePath;
|
|
204
|
+
}
|
|
205
|
+
const base64 = await pathToBase64(imagePathForUpload);
|
|
206
|
+
const newImages = {
|
|
207
|
+
...capturedImages,
|
|
208
|
+
[currentSide]: { dir: imagePathForUpload, file: base64, mrz: verified.mrz || "", templatePath: verified.templatePath },
|
|
209
|
+
};
|
|
210
|
+
setCapturedImages(newImages);
|
|
211
|
+
|
|
212
|
+
if (verified.country && verified.documentType) {
|
|
213
|
+
onValueChange({
|
|
214
|
+
...newImages,
|
|
215
|
+
country: verified.country,
|
|
216
|
+
documentType: GovernmentDocumentTypeBackend[verified.documentType as keyof typeof GovernmentDocumentTypeBackend] || '',
|
|
217
|
+
...(verified.region ? { region: verified.region } : {})
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
setTimeout(() => {
|
|
222
|
+
setShowCamera(false);
|
|
223
|
+
actions.showCustomStepper(true);
|
|
224
|
+
setSilentCaptureResult(prev => ({ ...prev, isAnalyzing: false }));
|
|
225
|
+
setIsProcessingCapture(false);
|
|
226
|
+
setProcessingImagePath(null);
|
|
227
|
+
}, 600);
|
|
228
|
+
} catch (e: any) {
|
|
229
|
+
console.error("Backend Error:", e);
|
|
230
|
+
const friendlyError = state.currentLanguage === 'en' ? 'Unable to process document. Please try again.' : 'Impossible de traiter le document. Veuillez réessayer.';
|
|
231
|
+
showAlert('Error', friendlyError);
|
|
232
|
+
setSilentCaptureResult(prev => ({ ...prev, isAnalyzing: false, success: false }));
|
|
233
|
+
setIsProcessingCapture(false);
|
|
234
|
+
setProcessingImagePath(null);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const handleSilentCapture = async (result: { success: boolean; path?: string; error?: string }) => {
|
|
239
|
+
if (silentCaptureResult.isAnalyzing || isProcessingCapture) return;
|
|
240
|
+
|
|
241
|
+
if (result.success && result.path) {
|
|
242
|
+
setSilentCaptureResult((prev) => ({ ...prev, isAnalyzing: true, success: false, error: '' }));
|
|
243
|
+
let templatePath = capturedImages[currentSide]?.templatePath || '';
|
|
244
|
+
let templateBbox: IBbox | undefined;
|
|
245
|
+
let templateResponse: any;
|
|
246
|
+
|
|
247
|
+
if (!selectedDocumentType) {
|
|
248
|
+
setSilentCaptureResult((prev) => ({ ...prev, isAnalyzing: false, success: false, error: 'Document type not selected' }));
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const issuingSubdivision = selectedDocumentType.region !== 'root' ? selectedDocumentType.region : undefined;
|
|
253
|
+
|
|
254
|
+
try {
|
|
255
|
+
if (!templatePath) {
|
|
256
|
+
const templateType = await checkTemplateType({
|
|
257
|
+
path: result.path || '',
|
|
258
|
+
docType: selectedDocumentType?.type as GovernmentDocumentType,
|
|
259
|
+
docRegion: countryData?.code || "",
|
|
260
|
+
postfix: currentSide,
|
|
261
|
+
issuingSubdivision: issuingSubdivision
|
|
262
|
+
}, env);
|
|
263
|
+
|
|
264
|
+
templateResponse = templateType;
|
|
265
|
+
if (templateType.template_path) templatePath = templateType.template_path;
|
|
266
|
+
|
|
267
|
+
if (templateType.card_obb) {
|
|
268
|
+
const obbConfidence = getObbConfidence((templateType as any).card_obb);
|
|
269
|
+
if (obbConfidence !== null && obbConfidence < OBB_CONFIDENCE_THRESHOLD) {
|
|
270
|
+
setSilentCaptureResult((prev) => ({ ...prev, isAnalyzing: false, success: false, error: t('kyc.idCardCapture.cardNotFullyInFrame') }));
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
try {
|
|
274
|
+
const crop = await cropByObb(result.path, (templateType as any).card_obb);
|
|
275
|
+
templateBbox = crop.bbox;
|
|
276
|
+
} catch { }
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const extractedCountryKey = templatePath ? templatePath.split('/')[0] : (ISO_TO_COUNTRY_NAME[countryData?.code || ''] || 'root');
|
|
281
|
+
const regionMappings = getCurrentSideVerification(currentSide, extractedCountryKey);
|
|
282
|
+
let verificationRes: any;
|
|
283
|
+
|
|
284
|
+
if (currentSide === 'front') {
|
|
285
|
+
const matchedAuthMethod = getCorrespondingAuthMethod(templatePath, regionMappings.regionMapping, regionMappings.key || '', 'front');
|
|
286
|
+
const mrzType = getCorrespondingMrzType(templatePath, regionMappings.regionMapping, regionMappings.key || '') || 'TD1';
|
|
287
|
+
|
|
288
|
+
verificationRes = await frontVerification({
|
|
289
|
+
path: result.path,
|
|
290
|
+
regionMapping: { authMethod: matchedAuthMethod ? [matchedAuthMethod] : regionMappings.authMethod, mrzTypes: regionMappings.mrzTypes },
|
|
291
|
+
selectedDocumentType: GovernmentDocumentTypeShorted[selectedDocumentType?.type as keyof typeof GovernmentDocumentTypeShorted] || '',
|
|
292
|
+
code: countryData?.code || '',
|
|
293
|
+
currentSide,
|
|
294
|
+
templatePath,
|
|
295
|
+
mrzType,
|
|
296
|
+
issuingSubdivision: issuingSubdivision
|
|
297
|
+
}, env);
|
|
298
|
+
} else {
|
|
299
|
+
let matchedBackAuthMethod = getCorrespondingAuthMethod(templatePath, regionMappings.regionMapping, regionMappings.key || '', 'back');
|
|
300
|
+
if (!matchedBackAuthMethod && currentSide === 'back') { matchedBackAuthMethod = 'MRZ'; }
|
|
301
|
+
const backMrzType = getCorrespondingMrzType(templatePath, regionMappings.regionMapping, regionMappings.key || '') || '';
|
|
302
|
+
|
|
303
|
+
// 🚨 EXTRACT FRONT TEMPLATE TO VALIDATE AGAINST BACK TEMPLATE
|
|
304
|
+
const frontTemplatePath = capturedImages['front']?.templatePath || '';
|
|
305
|
+
|
|
306
|
+
verificationRes = await backVerification({
|
|
307
|
+
path: result.path,
|
|
308
|
+
regionMapping: { authMethod: matchedBackAuthMethod ? [matchedBackAuthMethod] : regionMappings.authMethod, mrzTypes: regionMappings.mrzTypes },
|
|
309
|
+
selectedDocumentType: GovernmentDocumentTypeShorted[selectedDocumentType.type as keyof typeof GovernmentDocumentTypeShorted] || '',
|
|
310
|
+
code: countryData?.code || '',
|
|
311
|
+
currentSide,
|
|
312
|
+
templatePath,
|
|
313
|
+
mrzType: backMrzType,
|
|
314
|
+
templateResponse,
|
|
315
|
+
issuingSubdivision: issuingSubdivision,
|
|
316
|
+
frontTemplatePath: frontTemplatePath // 🚨 PASSED DOWN TO TRIGGER VALIDATION
|
|
317
|
+
}, env);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const bbox = verificationRes?.bbox || templateBbox;
|
|
321
|
+
const mrz = verificationRes?.mrz ? JSON.stringify(verificationRes.mrz) : "";
|
|
322
|
+
|
|
323
|
+
const verifiedResult: ISilentCaptureResult & { region?: string } = {
|
|
324
|
+
path: result.path,
|
|
325
|
+
templatePath,
|
|
326
|
+
bbox,
|
|
327
|
+
success: true,
|
|
328
|
+
mrz,
|
|
329
|
+
isAnalyzing: false,
|
|
330
|
+
country: countryData?.code,
|
|
331
|
+
documentType: selectedDocumentType.type,
|
|
332
|
+
region: issuingSubdivision
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
setSilentCaptureResult(verifiedResult);
|
|
336
|
+
if (bbox) setBboxBySide(prev => ({ ...prev, [currentSide]: bbox }));
|
|
337
|
+
|
|
338
|
+
await autoCapture(result.path, verifiedResult);
|
|
339
|
+
|
|
340
|
+
} catch (error: any) {
|
|
341
|
+
console.log("Backend Verification Error:", error);
|
|
342
|
+
const rawMessage = (error?.message || '').toLowerCase();
|
|
343
|
+
let userFriendlyMessage ='Verification failed. Please try again.';
|
|
344
|
+
|
|
345
|
+
if (rawMessage.includes('impossible') || rawMessage.includes('unreadable')) {
|
|
346
|
+
userFriendlyMessage = 'Document unreadable. Please hold the camera steady in good light.';
|
|
347
|
+
} else if (rawMessage.includes('country mismatch') || rawMessage.includes('pays sélectionné')) {
|
|
348
|
+
userFriendlyMessage = 'The document does not match your selected country.';
|
|
349
|
+
} else if (rawMessage.includes('card_not_fully_in_frame')) {
|
|
350
|
+
userFriendlyMessage = 'Move closer to the document and ensure all corners are visible.';
|
|
351
|
+
} else if (rawMessage.includes('ne correspond pas au recto')) { // 🚨 New Security Error Handler
|
|
352
|
+
userFriendlyMessage = 'The back of the document does not match the front. You must scan the same ID.';
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
setSilentCaptureResult(prev => ({ ...prev, isAnalyzing: false, success: false, error: userFriendlyMessage }));
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
const handleError = (event: { message: string }) => {
|
|
361
|
+
showAlert('Erreur', event.message);
|
|
362
|
+
setShowCamera(false);
|
|
363
|
+
setIsProcessingCapture(false);
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
useEffect(() => {
|
|
367
|
+
actions.showCustomStepper(!showCamera);
|
|
368
|
+
}, [showCamera]);
|
|
369
|
+
|
|
370
|
+
if (!countrySelectionData || !selectedDocumentType) {
|
|
371
|
+
return (
|
|
372
|
+
<View style={styles.root}>
|
|
373
|
+
<View style={styles.previewContainer}>
|
|
374
|
+
<Text style={styles.title}>{getLocalizedText(component.labels)}</Text>
|
|
375
|
+
<Text style={styles.description}>
|
|
376
|
+
{state.currentLanguage === "en" ? "Please complete the country and document selection first." : "Veuillez d'abord compléter la sélection du pays et du document."}
|
|
377
|
+
</Text>
|
|
378
|
+
</View>
|
|
379
|
+
</View>
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
if (showCamera) {
|
|
384
|
+
const isBusy = isProcessingCapture;
|
|
385
|
+
if (isRebootingCamera) {
|
|
386
|
+
return (
|
|
387
|
+
<View style={[styles.root, { justifyContent: 'center', alignItems: 'center', backgroundColor: '#000' }]}>
|
|
388
|
+
<ActivityIndicator size="large" color="#2DBD60" />
|
|
389
|
+
<Text style={{ color: 'white', marginTop: 20, fontSize: 16 }}>Initializing Camera...</Text>
|
|
390
|
+
</View>
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
return (
|
|
394
|
+
<View style={styles.root}>
|
|
395
|
+
<View style={[styles.cameraWrapper, { flex: 1 }]}>
|
|
396
|
+
<View style={styles.headerContainer}>
|
|
397
|
+
<Text style={styles.headerTitle}>
|
|
398
|
+
{selectedDocumentType ? (locale === 'en' ? getDocumentTypeInfo(selectedDocumentType.type).name.en : getDocumentTypeInfo(selectedDocumentType.type).name.fr) : ''}
|
|
399
|
+
</Text>
|
|
400
|
+
<View style={styles.stepBadge}>
|
|
401
|
+
<Text style={styles.stepText}>
|
|
402
|
+
{t('kyc.idCardCapture.captureTitle', { side: currentSide === 'front' ? locale === 'en' ? 'Front' : 'Recto' : locale === 'en' ? 'Back' : 'Verso' })}
|
|
403
|
+
</Text>
|
|
404
|
+
</View>
|
|
405
|
+
</View>
|
|
406
|
+
|
|
407
|
+
<View style={[styles.cameraFeedContainer, { flex: 1, backgroundColor: '#000' }]}>
|
|
408
|
+
{Platform.OS === 'web' && (
|
|
409
|
+
<View style={styles.webTopControls}>
|
|
410
|
+
<TouchableOpacity style={styles.webFlipButton} onPress={toggleCameraLens}>
|
|
411
|
+
<Text style={styles.webFlipText}>🔄 Flip Lens</Text>
|
|
412
|
+
</TouchableOpacity>
|
|
413
|
+
</View>
|
|
414
|
+
)}
|
|
415
|
+
|
|
416
|
+
<EnhancedCameraView
|
|
417
|
+
key={`${currentSide}-${cameraKey}`}
|
|
418
|
+
showCamera={true}
|
|
419
|
+
isProcessing={isBusy}
|
|
420
|
+
cameraType={cameraConfig.cameraType}
|
|
421
|
+
style={{ ...StyleSheet.absoluteFillObject, ...(Platform.OS === 'web' ? { width: '100%', height: '100%', left: 0, top: 0 } as any : {}) }}
|
|
422
|
+
onError={handleError}
|
|
423
|
+
onSilentCapture={handleSilentCapture}
|
|
424
|
+
silentCaptureResult={silentCaptureResult}
|
|
425
|
+
overlayComponent={
|
|
426
|
+
<>
|
|
427
|
+
<IdCardOverlay
|
|
428
|
+
xMin={cameraConfig.overlay.bbox.xMin} yMin={cameraConfig.overlay.bbox.yMin} xMax={cameraConfig.overlay.bbox.xMax} yMax={cameraConfig.overlay.bbox.yMax}
|
|
429
|
+
instructions={cameraConfig.overlay.guideText}
|
|
430
|
+
cornerOpacity={cameraConfig.overlay.bbox.cornerRadius || 0 as number}
|
|
431
|
+
isSuccess={silentCaptureResult.success}
|
|
432
|
+
language={state.currentLanguage}
|
|
433
|
+
stepperProps={{
|
|
434
|
+
back: () => {
|
|
435
|
+
if (currentSide === 'back') {
|
|
436
|
+
setCurrentSide('front'); setShowCamera(false); setIsProcessingCapture(false); setProcessingImagePath(null);
|
|
437
|
+
if (capturedImages['front']?.dir) {
|
|
438
|
+
const frontImage = capturedImages['front'];
|
|
439
|
+
setSilentCaptureResult((prev) => ({ ...prev, path: frontImage.dir, success: true, isAnalyzing: false, error: '', mrz: frontImage.mrz || '', templatePath: frontImage.templatePath || '', bbox: bboxBySide['front'] }));
|
|
440
|
+
} else { setSilentCaptureResult((prev) => ({ ...prev, path: '', success: false, isAnalyzing: false, error: '', templatePath: '' })); }
|
|
441
|
+
} else { actions.previousComponent(); }
|
|
442
|
+
},
|
|
443
|
+
selectedDocumentType: selectedDocumentType ? (locale === 'en' ? getDocumentTypeInfo(selectedDocumentType.type).name.en : getDocumentTypeInfo(selectedDocumentType.type).name.fr) : '',
|
|
444
|
+
step: state.currentComponentIndex + 1, totalSteps: state.template.components.length, side: currentSide,
|
|
445
|
+
}}
|
|
446
|
+
/>
|
|
447
|
+
</>
|
|
448
|
+
}
|
|
449
|
+
/>
|
|
450
|
+
|
|
451
|
+
{!isBusy && silentCaptureResult.isAnalyzing && (
|
|
452
|
+
<View style={styles.topAnalyzingPillContainer}>
|
|
453
|
+
<View style={styles.topAnalyzingPill}>
|
|
454
|
+
<ActivityIndicator size="small" color="white" />
|
|
455
|
+
<Text style={styles.analyzingPillText}>
|
|
456
|
+
{state.currentLanguage === 'en' ? 'Scanning...' : 'Analyse...'}
|
|
457
|
+
</Text>
|
|
458
|
+
</View>
|
|
459
|
+
</View>
|
|
460
|
+
)}
|
|
461
|
+
|
|
462
|
+
{isBusy && (
|
|
463
|
+
<View style={[StyleSheet.absoluteFillObject, { zIndex: 9999 }]}>
|
|
464
|
+
{processingImagePath && (
|
|
465
|
+
<Image
|
|
466
|
+
source={{ uri: processingImagePath.startsWith('file://') ? processingImagePath : `file://${processingImagePath}` }}
|
|
467
|
+
style={StyleSheet.absoluteFillObject}
|
|
468
|
+
resizeMode="cover"
|
|
469
|
+
/>
|
|
470
|
+
)}
|
|
471
|
+
<View style={styles.processingOverlay}>
|
|
472
|
+
<ActivityIndicator size="large" color="#2DBD60" />
|
|
473
|
+
<Text style={styles.processingText}>
|
|
474
|
+
{state.currentLanguage === 'en' ? 'Perfect!\nProcessing Document...' : 'Parfait!\nTraitement du document...'}
|
|
475
|
+
</Text>
|
|
476
|
+
</View>
|
|
477
|
+
</View>
|
|
478
|
+
)}
|
|
479
|
+
|
|
480
|
+
{!isBusy && Platform.OS === 'web' ? (
|
|
481
|
+
<View style={styles.webBottomControlBar}>
|
|
482
|
+
{silentCaptureResult.error && (
|
|
483
|
+
<View style={styles.floatingErrorBanner}>
|
|
484
|
+
<Text style={styles.floatingErrorText}>⚠️ {silentCaptureResult.error}</Text>
|
|
485
|
+
</View>
|
|
486
|
+
)}
|
|
487
|
+
<View style={styles.webActionButtonsRow}>
|
|
488
|
+
<TouchableOpacity style={styles.webSecondaryButton} onPress={() => setShowCamera(false)}>
|
|
489
|
+
<Text style={styles.webSecondaryButtonText}>Cancel</Text>
|
|
490
|
+
</TouchableOpacity>
|
|
491
|
+
<TouchableOpacity style={styles.webPrimaryButton} onPress={refreshCamera}>
|
|
492
|
+
<Text style={styles.webPrimaryButtonText}>↻ Refresh Camera</Text>
|
|
349
493
|
</TouchableOpacity>
|
|
350
|
-
</View>
|
|
351
|
-
)}
|
|
352
|
-
|
|
353
|
-
<EnhancedCameraView
|
|
354
|
-
key={`${currentSide}-${cameraKey}`}
|
|
355
|
-
showCamera={true}
|
|
356
|
-
isProcessing={isBusy}
|
|
357
|
-
cameraType={cameraConfig.cameraType}
|
|
358
|
-
style={StyleSheet.absoluteFillObject}
|
|
359
|
-
onError={handleError}
|
|
360
|
-
onSilentCapture={handleSilentCapture}
|
|
361
|
-
silentCaptureResult={silentCaptureResult}
|
|
362
|
-
overlayComponent={
|
|
363
|
-
<>
|
|
364
|
-
<IdCardOverlay
|
|
365
|
-
xMin={cameraConfig.overlay.bbox.xMin} yMin={cameraConfig.overlay.bbox.yMin} xMax={cameraConfig.overlay.bbox.xMax} yMax={cameraConfig.overlay.bbox.yMax}
|
|
366
|
-
instructions={cameraConfig.overlay.guideText}
|
|
367
|
-
cornerOpacity={cameraConfig.overlay.bbox.cornerRadius || 0 as number}
|
|
368
|
-
isSuccess={silentCaptureResult.success}
|
|
369
|
-
language={state.currentLanguage}
|
|
370
|
-
stepperProps={{
|
|
371
|
-
back: () => {
|
|
372
|
-
if (currentSide === 'back') {
|
|
373
|
-
setCurrentSide('front');
|
|
374
|
-
setShowCamera(false);
|
|
375
|
-
setIsProcessingCapture(false);
|
|
376
|
-
setProcessingImagePath(null);
|
|
377
|
-
if (capturedImages['front']?.dir) {
|
|
378
|
-
const frontImage = capturedImages['front'];
|
|
379
|
-
setSilentCaptureResult((prev) => ({ ...prev, path: frontImage.dir, success: true, isAnalyzing: false, error: '', mrz: frontImage.mrz || '', templatePath: frontImage.templatePath || '', bbox: bboxBySide['front'] }));
|
|
380
|
-
} else { setSilentCaptureResult((prev) => ({ ...prev, path: '', success: false, isAnalyzing: false, error: '', templatePath: '' })); }
|
|
381
|
-
} else { actions.previousComponent(); }
|
|
382
|
-
},
|
|
383
|
-
selectedDocumentType: selectedDocumentType ? (locale === 'en' ? getDocumentTypeInfo(selectedDocumentType.type).name.en : getDocumentTypeInfo(selectedDocumentType.type).name.fr) : '',
|
|
384
|
-
step: state.currentComponentIndex + 1, totalSteps: state.template.components.length, side: currentSide,
|
|
385
|
-
}}
|
|
386
|
-
/>
|
|
387
|
-
</>
|
|
388
|
-
}
|
|
389
|
-
/>
|
|
390
|
-
|
|
391
|
-
{!isBusy && silentCaptureResult.isAnalyzing && (
|
|
392
|
-
<View style={styles.topAnalyzingPillContainer}>
|
|
393
|
-
<View style={styles.topAnalyzingPill}>
|
|
394
|
-
<ActivityIndicator size="small" color="white" />
|
|
395
|
-
<Text style={styles.analyzingPillText}>
|
|
396
|
-
{state.currentLanguage === 'en' ? 'Scanning...' : 'Analyse...'}
|
|
397
|
-
</Text>
|
|
398
|
-
</View>
|
|
399
|
-
</View>
|
|
400
|
-
)}
|
|
401
|
-
|
|
402
|
-
{isBusy && (
|
|
403
|
-
<View style={[StyleSheet.absoluteFillObject, { zIndex: 9999 }]}>
|
|
404
|
-
{processingImagePath && (
|
|
405
|
-
<Image
|
|
406
|
-
source={{ uri: processingImagePath.startsWith('file://') ? processingImagePath : `file://${processingImagePath}` }}
|
|
407
|
-
style={StyleSheet.absoluteFillObject}
|
|
408
|
-
resizeMode="cover"
|
|
409
|
-
/>
|
|
410
|
-
)}
|
|
411
|
-
<View style={styles.processingOverlay}>
|
|
412
|
-
<ActivityIndicator size="large" color="#2DBD60" />
|
|
413
|
-
<Text style={styles.processingText}>
|
|
414
|
-
{state.currentLanguage === 'en' ? 'Perfect!\nProcessing Document...' : 'Parfait!\nTraitement du document...'}
|
|
415
|
-
</Text>
|
|
416
|
-
</View>
|
|
417
|
-
</View>
|
|
418
|
-
)}
|
|
419
|
-
|
|
420
|
-
{/* 🚨 THE ESCAPE HATCH: Branching UI for Web vs Mobile */}
|
|
421
|
-
{!isBusy && Platform.OS === 'web' ? (
|
|
422
|
-
<View style={styles.webBottomControlBar}>
|
|
423
|
-
{silentCaptureResult.error ? (
|
|
424
|
-
<View style={styles.floatingErrorBanner}>
|
|
425
|
-
<Text style={styles.floatingErrorText}>⚠️ {silentCaptureResult.error}</Text>
|
|
426
|
-
</View>
|
|
427
|
-
) : <View style={{ height: 10 }} />}
|
|
428
|
-
|
|
429
|
-
<View style={styles.webActionButtonsRow}>
|
|
430
|
-
<TouchableOpacity style={styles.webSecondaryButton} onPress={() => setShowCamera(false)}>
|
|
431
|
-
<Text style={styles.webSecondaryButtonText}>Cancel</Text>
|
|
432
|
-
</TouchableOpacity>
|
|
433
|
-
<TouchableOpacity style={styles.webPrimaryButton} onPress={refreshCamera}>
|
|
434
|
-
<Text style={styles.webPrimaryButtonText}>↻ Refresh Camera</Text>
|
|
435
|
-
</TouchableOpacity>
|
|
436
|
-
</View>
|
|
437
494
|
</View>
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
495
|
+
</View>
|
|
496
|
+
) : !isBusy ? (
|
|
497
|
+
<View style={styles.escapeHatchContainer}>
|
|
498
|
+
<TouchableOpacity style={styles.fallbackRefreshButton} onPress={refreshCamera}>
|
|
499
|
+
<Text style={styles.fallbackRefreshText}>↻ Refresh Camera</Text>
|
|
500
|
+
</TouchableOpacity>
|
|
501
|
+
<TouchableOpacity
|
|
502
|
+
style={[styles.fallbackRefreshButton, { marginTop: 15, backgroundColor: 'rgba(220, 38, 38, 0.8)', borderColor: '#DC2626' }]}
|
|
503
|
+
onPress={() => setShowCamera(false)}
|
|
504
|
+
>
|
|
505
|
+
<Text style={styles.fallbackRefreshText}>Cancel / Go Back</Text>
|
|
506
|
+
</TouchableOpacity>
|
|
507
|
+
</View>
|
|
508
|
+
) : null}
|
|
509
|
+
|
|
510
|
+
{silentCaptureResult.error && !isBusy && Platform.OS !== 'web' ? (
|
|
511
|
+
<View style={[styles.floatingErrorBanner, { zIndex: 10000 }]}>
|
|
512
|
+
<Text style={styles.floatingErrorText}>⚠️ {silentCaptureResult.error}</Text>
|
|
513
|
+
</View>
|
|
514
|
+
) : null}
|
|
515
|
+
</View>
|
|
516
|
+
</View>
|
|
517
|
+
</View>
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
return (
|
|
522
|
+
<View style={styles.root}>
|
|
523
|
+
<View style={styles.previewContainer}>
|
|
524
|
+
<ScrollView style={styles.previewItemContainer} showsVerticalScrollIndicator={false}>
|
|
525
|
+
<View key={currentSide} style={styles.sideContainer}>
|
|
526
|
+
<Text style={styles.sideTitle}>
|
|
527
|
+
{t('kyc.idCardCapture.captureTitle', { side: currentSide === 'front' ? locale === 'en' ? 'Front' : 'Recto' : locale === 'en' ? 'Back' : 'Verso' })}
|
|
528
|
+
</Text>
|
|
529
|
+
<Text style={{ fontSize: 14, color: '#666', textAlign: 'center', marginBottom: 16, lineHeight: 22 }}>
|
|
530
|
+
{getLocalizedText(component.instructions)}
|
|
531
|
+
</Text>
|
|
532
|
+
<View style={{ alignItems: 'center', justifyContent: 'center', flexDirection: "column", gap: 16 }}>
|
|
533
|
+
<View style={styles.imagePreviewWrapper}>
|
|
534
|
+
{capturedImages[currentSide]?.dir ? (
|
|
535
|
+
<Image source={{ uri: capturedImages[currentSide].dir }} style={styles.previewImage} />
|
|
536
|
+
) : silentCaptureResult.path ? (
|
|
537
|
+
<Image source={{ uri: silentCaptureResult.path }} style={styles.previewImage} />
|
|
538
|
+
) : null}
|
|
539
|
+
</View>
|
|
540
|
+
{!capturedImages[currentSide]?.dir && (
|
|
541
|
+
<View style={{ width: '100%', gap: 12 }}>
|
|
542
|
+
<Button
|
|
543
|
+
title={state.currentLanguage === "en" ? "Start Scanning" : "Commencer la numérisation"}
|
|
544
|
+
onPress={() => { setShowCamera(true); refreshCamera(); actions.showCustomStepper(false); }}
|
|
545
|
+
variant="primary" size="large" fullWidth
|
|
546
|
+
/>
|
|
547
|
+
{Platform.OS === 'web' && (
|
|
548
|
+
<Button
|
|
549
|
+
title={state.currentLanguage === "en" ? "Continue on Phone" : "Continuer sur le téléphone"}
|
|
550
|
+
onPress={() => setShowQRModal(true)}
|
|
551
|
+
variant="outline" size="large" fullWidth
|
|
552
|
+
/>
|
|
553
|
+
)}
|
|
449
554
|
</View>
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
<Image source={{ uri: silentCaptureResult.path }} style={styles.previewImage} />
|
|
487
|
-
) : null}
|
|
488
|
-
</View>
|
|
489
|
-
|
|
490
|
-
{!capturedImages[currentSide]?.dir && (
|
|
491
|
-
<Button
|
|
492
|
-
title={state.currentLanguage === "en" ? "Start Scanning" : "Commencer la numérisation"}
|
|
493
|
-
onPress={() => { setShowCamera(true); refreshCamera(); actions.showCustomStepper(false); }}
|
|
494
|
-
variant="primary" size="large" fullWidth
|
|
495
|
-
/>
|
|
496
|
-
)}
|
|
497
|
-
{capturedImages[currentSide]?.dir && (
|
|
498
|
-
<>
|
|
499
|
-
<Button title={t('kyc.idCardCapture.retakeButton')} onPress={() => retakePicture(currentSide)} variant="outline" size="medium" fullWidth />
|
|
500
|
-
<Button title={t('common.next')} onPress={() => {
|
|
501
|
-
if (!selectedDocumentType) { showAlert('Error', 'Document type not selected'); return; }
|
|
502
|
-
if (currentSide === 'back' || selectedDocumentType.type === 'passport') {
|
|
503
|
-
actions.nextComponent();
|
|
504
|
-
} else {
|
|
505
|
-
setShowCamera(true);
|
|
506
|
-
refreshCamera();
|
|
507
|
-
setCurrentSide('back');
|
|
508
|
-
setSilentCaptureResult({ success: false, isAnalyzing: false, path: '', error: '', templatePath: undefined });
|
|
509
|
-
setIsProcessingCapture(false);
|
|
510
|
-
setProcessingImagePath(null);
|
|
511
|
-
}
|
|
512
|
-
}} variant="primary" size="large" fullWidth />
|
|
513
|
-
</>
|
|
514
|
-
)}
|
|
515
|
-
</View>
|
|
516
|
-
</View>
|
|
517
|
-
</ScrollView>
|
|
518
|
-
</View>
|
|
519
|
-
</View>
|
|
520
|
-
);
|
|
555
|
+
)}
|
|
556
|
+
{capturedImages[currentSide]?.dir && (
|
|
557
|
+
<>
|
|
558
|
+
<Button title={t('kyc.idCardCapture.retakeButton')} onPress={() => retakePicture(currentSide)} variant="outline" size="medium" fullWidth />
|
|
559
|
+
<Button title={t('common.next')} onPress={() => {
|
|
560
|
+
if (!selectedDocumentType) { showAlert('Error', 'Document type not selected'); return; }
|
|
561
|
+
if (currentSide === 'back' || selectedDocumentType.type === 'passport') {
|
|
562
|
+
actions.nextComponent();
|
|
563
|
+
} else {
|
|
564
|
+
setShowCamera(true); refreshCamera(); setCurrentSide('back'); setSilentCaptureResult({ success: false, isAnalyzing: false, path: '', error: '', templatePath: undefined }); setIsProcessingCapture(false); setProcessingImagePath(null);
|
|
565
|
+
}
|
|
566
|
+
}} variant="primary" size="large" fullWidth />
|
|
567
|
+
</>
|
|
568
|
+
)}
|
|
569
|
+
</View>
|
|
570
|
+
</View>
|
|
571
|
+
</ScrollView>
|
|
572
|
+
</View>
|
|
573
|
+
{showQRModal && Platform.OS === 'web' && (
|
|
574
|
+
<View style={styles.qrModalOverlay}>
|
|
575
|
+
<View style={styles.qrModalContainer}>
|
|
576
|
+
<Text style={styles.qrModalTitle}>
|
|
577
|
+
{state.currentLanguage === 'en' ? 'Scan to continue' : 'Scannez pour continuer'}
|
|
578
|
+
</Text>
|
|
579
|
+
<Text style={styles.qrModalText}>
|
|
580
|
+
{state.currentLanguage === 'en' ? "Point your phone's camera at this QR code to seamlessly continue the process on your mobile device." : "Pointez l'appareil photo de votre téléphone vers ce code QR pour continuer le processus en toute fluidité sur votre appareil mobile."}
|
|
581
|
+
</Text>
|
|
582
|
+
<View style={styles.qrCodeWrapper}>
|
|
583
|
+
<QRCode value={currentUrl} size={220} backgroundColor="transparent" />
|
|
584
|
+
</View>
|
|
585
|
+
<Button title={state.currentLanguage === 'en' ? "Close" : "Fermer"} onPress={() => setShowQRModal(false)} variant="outline" fullWidth />
|
|
586
|
+
</View>
|
|
587
|
+
</View>
|
|
588
|
+
)}
|
|
589
|
+
</View>
|
|
590
|
+
);
|
|
521
591
|
};
|
|
522
592
|
|
|
523
593
|
const styles = StyleSheet.create({
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
previewContainer: {
|
|
566
|
-
width: '100%', backgroundColor: 'white', borderRadius: 12, paddingVertical: 24, paddingHorizontal: 20, shadowColor: '#000', shadowOffset: { width: 0, height: 4 }, shadowOpacity: 0.1, shadowRadius: 12, elevation: 8,
|
|
567
|
-
...Platform.select({ web: { alignSelf: 'center', maxWidth: 600 }, default: { margin: 10, width: '95%' }})
|
|
568
|
-
},
|
|
569
|
-
previewItemContainer: { flexGrow: 1, },
|
|
570
|
-
title: { fontSize: 24, fontWeight: 'bold', color: '#333', marginBottom: 8, textAlign: 'center' },
|
|
571
|
-
description: { fontSize: 16, color: '#666', textAlign: 'center', marginBottom: 24, lineHeight: 22 },
|
|
572
|
-
sideContainer: { marginBottom: 24 },
|
|
573
|
-
sideTitle: { fontSize: 25, fontWeight: 'bold', color: '#000', marginBottom: 12, textAlign: 'center' },
|
|
574
|
-
|
|
575
|
-
imagePreviewWrapper: {
|
|
576
|
-
width: '100%', borderRadius: 12, padding: 1, overflow: 'hidden', shadowColor: '#000', shadowOffset: { width: 0, height: 4 }, shadowOpacity: 0.18, shadowRadius: 8, elevation: 8, backgroundColor: '#f0f0f0',
|
|
577
|
-
...Platform.select({
|
|
578
|
-
web: { aspectRatio: 1.59, height: 'auto' } as any,
|
|
579
|
-
default: { height: 220 }
|
|
580
|
-
})
|
|
581
|
-
},
|
|
582
|
-
previewImage: { width: '100%', height: '100%', borderRadius: 12, resizeMode: 'cover' },
|
|
583
|
-
|
|
584
|
-
floatingErrorBanner: {
|
|
585
|
-
backgroundColor: '#FEF2F2', borderWidth: 1, borderColor: '#FCA5A5', paddingVertical: 12, paddingHorizontal: 16, borderRadius: 12, alignItems: 'center', justifyContent: 'center', width: '100%',
|
|
586
|
-
...Platform.select({
|
|
587
|
-
default: { position: 'absolute', top: Platform.OS === 'ios' ? 90 : 70, left: 24, right: 24, zIndex: 10000 }
|
|
588
|
-
})
|
|
589
|
-
},
|
|
590
|
-
floatingErrorText: { color: '#991B1B', fontSize: 14, fontWeight: '700', textAlign: 'center' },
|
|
591
|
-
processingOverlay: { flex: 1, backgroundColor: 'rgba(0, 0, 0, 0.6)', justifyContent: 'center', alignItems: 'center', zIndex: 9999 },
|
|
592
|
-
processingText: { color: '#FFF', fontSize: 18, fontWeight: 'bold', marginTop: 16, textAlign: 'center' },
|
|
593
|
-
|
|
594
|
-
errorText: { color: '#dc2626', fontSize: 14, marginTop: 8, textAlign: 'center' },
|
|
595
|
-
topAnalyzingPillContainer: { position: 'absolute', top: Platform.OS === 'android' ? 60 : 50, left: 0, right: 0, alignItems: 'center', zIndex: 100 },
|
|
596
|
-
topAnalyzingPill: { flexDirection: 'row', alignItems: 'center', backgroundColor: 'rgba(0,0,0,0.6)', paddingVertical: 8, paddingHorizontal: 16, borderRadius: 20, gap: 8 },
|
|
597
|
-
analyzingPillText: { color: 'white', fontSize: 14, fontWeight: 'bold' }
|
|
594
|
+
root: { flex: 1, width: '100%', backgroundColor: 'transparent', alignSelf: 'center', ...Platform.select({ web: { minHeight: '85vh', justifyContent: 'center', alignItems: 'center' } as any, }) },
|
|
595
|
+
cameraWrapper: { width: '100%', backgroundColor: '#000000', overflow: 'hidden', ...Platform.select({ web: { maxWidth: 1000, width: '95%', height: '80vh', minHeight: 600, borderRadius: 24, shadowColor: '#000', shadowOffset: { width: 0, height: 10 }, shadowOpacity: 0.15, shadowRadius: 30, elevation: 24 } as any, default: { flex: 1 } }) },
|
|
596
|
+
headerContainer: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', flexWrap: 'wrap', gap: 10, paddingHorizontal: 20, paddingVertical: 18, backgroundColor: '#FFFFFF', borderBottomWidth: 1, borderBottomColor: '#F1F5F9', zIndex: 10, ...Platform.select({ web: { display: 'flex' }, default: { display: 'none' } }) },
|
|
597
|
+
headerTitle: { fontSize: 18, fontWeight: '700', color: '#0F172A', flexShrink: 1 },
|
|
598
|
+
stepBadge: { backgroundColor: '#F1F5F9', paddingHorizontal: 12, paddingVertical: 6, borderRadius: 20, },
|
|
599
|
+
stepText: { fontSize: 13, fontWeight: '600', color: '#64748B', },
|
|
600
|
+
cameraFeedContainer: { flex: 1, position: 'relative', backgroundColor: '#000', },
|
|
601
|
+
escapeHatchContainer: { position: 'absolute', bottom: 40, left: 0, right: 0, alignItems: 'center', justifyContent: 'center', zIndex: 99999 },
|
|
602
|
+
fallbackRefreshButton: { backgroundColor: 'rgba(0, 0, 0, 0.8)', borderWidth: 1, borderColor: 'rgba(255, 255, 255, 0.5)', paddingVertical: 12, paddingHorizontal: 24, borderRadius: 24, shadowColor: '#000', shadowOffset: { width: 0, height: 4 }, shadowOpacity: 0.3, shadowRadius: 5, elevation: 8 },
|
|
603
|
+
fallbackRefreshText: { color: '#FFFFFF', fontWeight: 'bold', fontSize: 16 },
|
|
604
|
+
webBottomControlBar: { position: 'absolute', bottom: 0, left: 0, right: 0, paddingHorizontal: 24, paddingBottom: 24, paddingTop: 30, backgroundColor: 'rgba(0,0,0,0.6)', zIndex: 99999 },
|
|
605
|
+
webActionButtonsRow: { flexDirection: 'row', justifyContent: 'center', gap: 16, marginTop: 12, maxWidth: 500, alignSelf: 'center', width: '100%' },
|
|
606
|
+
webPrimaryButton: { flex: 1, backgroundColor: '#2DBD60', paddingVertical: 14, borderRadius: 12, alignItems: 'center' },
|
|
607
|
+
webPrimaryButtonText: { color: 'white', fontWeight: 'bold', fontSize: 16 },
|
|
608
|
+
webSecondaryButton: { flex: 1, backgroundColor: 'rgba(255,255,255,0.15)', borderWidth: 1, borderColor: 'rgba(255,255,255,0.3)', paddingVertical: 14, borderRadius: 12, alignItems: 'center' },
|
|
609
|
+
webSecondaryButtonText: { color: 'white', fontWeight: 'bold', fontSize: 16 },
|
|
610
|
+
webTopControls: { position: 'absolute', top: Platform.OS === 'ios' ? 70 : 20, right: 20, zIndex: 9999 },
|
|
611
|
+
webFlipButton: { backgroundColor: 'rgba(0,0,0,0.6)', paddingHorizontal: 16, paddingVertical: 10, borderRadius: 20, borderWidth: 1, borderColor: 'rgba(255,255,255,0.4)', ...Platform.select({ web: { backdropFilter: 'blur(4px)' } as any }) },
|
|
612
|
+
webFlipText: { color: 'white', fontWeight: 'bold', fontSize: 14 },
|
|
613
|
+
previewContainer: { width: '100%', backgroundColor: 'white', borderRadius: 12, paddingVertical: 30, paddingHorizontal: 24, shadowColor: '#000', shadowOffset: { width: 0, height: 4 }, shadowOpacity: 0.08, shadowRadius: 16, elevation: 8, ...Platform.select({ web: { alignSelf: 'center', maxWidth: 650 }, default: { margin: 10, width: '95%' }}) },
|
|
614
|
+
previewItemContainer: { flexGrow: 1, },
|
|
615
|
+
title: { fontSize: 24, fontWeight: 'bold', color: '#333', marginBottom: 8, textAlign: 'center' },
|
|
616
|
+
description: { fontSize: 16, color: '#666', textAlign: 'center', marginBottom: 24, lineHeight: 22 },
|
|
617
|
+
sideContainer: { marginBottom: 24 },
|
|
618
|
+
sideTitle: { fontSize: 22, fontWeight: 'bold', color: '#000', marginBottom: 12, textAlign: 'center' },
|
|
619
|
+
imagePreviewWrapper: { width: '100%', borderRadius: 12, padding: 1, overflow: 'hidden', shadowColor: '#000', shadowOffset: { width: 0, height: 4 }, shadowOpacity: 0.12, shadowRadius: 8, elevation: 8, backgroundColor: '#f0f0f0', ...Platform.select({ web: { aspectRatio: 1.59, height: 'auto', maxWidth: 450, alignSelf: 'center' } as any, default: { height: 220 } }) },
|
|
620
|
+
previewImage: { width: '100%', height: '100%', borderRadius: 12, resizeMode: 'cover' },
|
|
621
|
+
floatingErrorBanner: { backgroundColor: '#FEF2F2', borderWidth: 1, borderColor: '#FCA5A5', paddingVertical: 12, paddingHorizontal: 16, borderRadius: 12, alignItems: 'center', justifyContent: 'center', width: '100%', ...Platform.select({ web: { position: 'absolute', bottom: '100%', marginBottom: 16, maxWidth: 500, alignSelf: 'center', zIndex: 100000, boxShadow: '0 4px 12px rgba(0,0,0,0.15)' } as any, default: { position: 'absolute', top: Platform.OS === 'ios' ? 90 : 70, left: 24, right: 24, zIndex: 10000 } }) },
|
|
622
|
+
floatingErrorText: { color: '#991B1B', fontSize: 14, fontWeight: '700', textAlign: 'center' },
|
|
623
|
+
processingOverlay: { flex: 1, backgroundColor: 'rgba(0, 0, 0, 0.7)', justifyContent: 'center', alignItems: 'center', zIndex: 9999, ...Platform.select({ web: { backdropFilter: 'blur(4px)' } as any }) },
|
|
624
|
+
processingText: { color: '#FFF', fontSize: 18, fontWeight: 'bold', marginTop: 16, textAlign: 'center' },
|
|
625
|
+
errorText: { color: '#dc2626', fontSize: 14, marginTop: 8, textAlign: 'center' },
|
|
626
|
+
topAnalyzingPillContainer: { position: 'absolute', top: Platform.OS === 'android' ? 60 : 75, left: 0, right: 0, alignItems: 'center', zIndex: 100 },
|
|
627
|
+
topAnalyzingPill: { flexDirection: 'row', alignItems: 'center', backgroundColor: 'rgba(0,0,0,0.7)', paddingVertical: 10, paddingHorizontal: 20, borderRadius: 30, gap: 10, shadowColor: '#000', shadowOffset: {width: 0, height: 4}, shadowOpacity: 0.3, shadowRadius: 8 },
|
|
628
|
+
analyzingPillText: { color: 'white', fontSize: 14, fontWeight: 'bold' },
|
|
629
|
+
qrModalOverlay: { ...StyleSheet.absoluteFillObject, backgroundColor: 'rgba(0,0,0,0.6)', justifyContent: 'center', alignItems: 'center', zIndex: 999999, ...Platform.select({ web: { backdropFilter: 'blur(5px)' } as any }) },
|
|
630
|
+
qrModalContainer: { backgroundColor: '#FFFFFF', borderRadius: 24, padding: 32, width: '90%', maxWidth: 400, alignItems: 'center', shadowColor: '#000', shadowOffset: { width: 0, height: 10 }, shadowOpacity: 0.15, shadowRadius: 30, elevation: 24, },
|
|
631
|
+
qrModalTitle: { fontSize: 22, fontWeight: 'bold', color: '#0F172A', marginBottom: 12, textAlign: 'center' },
|
|
632
|
+
qrModalText: { fontSize: 15, color: '#64748B', textAlign: 'center', marginBottom: 24, lineHeight: 22, },
|
|
633
|
+
qrCodeWrapper: { padding: 16, backgroundColor: '#FFFFFF', borderRadius: 16, borderWidth: 1, borderColor: '#E2E8F0', marginBottom: 24, }
|
|
598
634
|
});
|