@sanctum-key/react-native-sdk 1.0.17 → 1.0.19
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/IDCardCapture.d.ts.map +1 -1
- package/build/src/components/KYCElements/IDCardCapture.js +189 -191
- 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/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/modules/api/CardAuthentification.d.ts.map +1 -1
- package/build/src/modules/api/CardAuthentification.js +0 -1
- package/build/src/modules/api/CardAuthentification.js.map +1 -1
- package/build/src/modules/api/KYCService.d.ts.map +1 -1
- package/build/src/modules/api/KYCService.js +41 -24
- package/build/src/modules/api/KYCService.js.map +1 -1
- package/package.json +3 -2
- package/src/components/EnhancedCameraView.tsx +28 -219
- package/src/components/KYCElements/IDCardCapture.tsx +560 -581
- package/src/components/KYCElements/PhoneVerificationTemplate.tsx +0 -2
- package/src/components/OverLay/IdCard.tsx +48 -36
- package/src/config/countriesData.ts +0 -4
- package/src/modules/api/CardAuthentification.ts +0 -1
- package/src/modules/api/KYCService.ts +48 -29
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React, { useEffect, useMemo, useState } from 'react';
|
|
2
|
-
import { View, Text, StyleSheet, Image, ScrollView, Platform, ActivityIndicator, TouchableOpacity } from 'react-native';
|
|
1
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
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,565 @@ 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
|
-
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
|
+
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 { component: TemplateComponent; value?: Record<string, IIDCardPayload>; onValueChange: (value: Record<string, IIDCardPayload | string>) => void; error?: string; language?: string; currentSide?: string; }
|
|
21
|
-
|
|
22
|
-
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
|
-
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
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
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
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
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
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' }
|
|
21
|
+
interface IDCardCaptureProps { component: TemplateComponent; value?: Record<string, IIDCardPayload>; onValueChange: (value: Record<string, IIDCardPayload | string>) => void; error?: string; language?: string; currentSide?: string; }
|
|
22
|
+
|
|
23
|
+
export const IDCardCapture: React.FC<IDCardCaptureProps> = ({ component, value = {}, onValueChange, error, language = 'en' }) => {
|
|
24
|
+
const { t, locale } = useI18n();
|
|
25
|
+
const [showCamera, setShowCamera] = useState(false);
|
|
26
|
+
const [capturedImages, setCapturedImages] = useState<Record<string, IIDCardPayload>>(value || {});
|
|
27
|
+
const [currentSide, setCurrentSide] = useState<'front' | 'back'>('front');
|
|
28
|
+
const [bboxBySide, setBboxBySide] = useState<Record<string, IBbox>>({});
|
|
29
|
+
const [silentCaptureResult, setSilentCaptureResult] = useState<ISilentCaptureResult>({ success: false, isAnalyzing: false });
|
|
30
|
+
const [isProcessingCapture, setIsProcessingCapture] = useState(false);
|
|
31
|
+
const [processingImagePath, setProcessingImagePath] = useState<string | null>(null);
|
|
32
|
+
const [cameraKey, setCameraKey] = useState(0);
|
|
33
|
+
const [isRebootingCamera, setIsRebootingCamera] = useState(false);
|
|
34
|
+
const [cameraType, setCameraType] = useState<'back' | 'front'>('back');
|
|
35
|
+
const [showQRModal, setShowQRModal] = useState(false);
|
|
36
|
+
|
|
37
|
+
const [currentUrl, setCurrentUrl] = useState('');
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (typeof window !== 'undefined' && window.location) {
|
|
40
|
+
setCurrentUrl(window.location.href);
|
|
41
|
+
}
|
|
42
|
+
}, []);
|
|
43
|
+
|
|
44
|
+
const documentTypeMapping: Record<string, GovernmentDocumentType> = { 'nationalId': 'national_id', 'passport': 'passport', 'driversLicense': 'drivers_licence', 'residencePermit': 'permanent_residence', 'healthInsuranceCard': 'health_insurance_card', };
|
|
45
|
+
const { actions, state, env } = useTemplateKYCFlowContext();
|
|
46
|
+
const { width: screenWidth, height: screenHeight } = useWindowDimensions();
|
|
47
|
+
|
|
48
|
+
const getLocalizedText = (text: LocalizedText | Record<string, LocalizedText>): string => {
|
|
49
|
+
if (text && typeof text[currentSide] === 'object' && text[currentSide][locale]) return text[currentSide][locale] || '';
|
|
50
|
+
return "";
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const countrySelectionData = useMemo(() => {
|
|
54
|
+
const countrySelectionComponent = state.template.components.find(c => c.type === 'country_selection');
|
|
55
|
+
return countrySelectionComponent ? state.componentData[countrySelectionComponent.id] : null;
|
|
56
|
+
}, [state.template.components, state.componentData]);
|
|
57
|
+
|
|
58
|
+
const selectedDocumentType = useMemo<{ type: GovernmentDocumentType; region: string } | null>(() => {
|
|
59
|
+
if (!countrySelectionData?.documentType) return null;
|
|
60
|
+
const backendDocType = countrySelectionData.documentType;
|
|
61
|
+
const mappedType = documentTypeMapping[backendDocType] || backendDocType as GovernmentDocumentType;
|
|
62
|
+
return { type: mappedType, region: countrySelectionData.region || 'root' };
|
|
63
|
+
}, [countrySelectionData, documentTypeMapping]);
|
|
64
|
+
|
|
65
|
+
const countryData = useMemo(() => countrySelectionData, [countrySelectionData]);
|
|
66
|
+
|
|
67
|
+
const refreshCamera = () => {
|
|
68
|
+
setIsRebootingCamera(true);
|
|
69
|
+
setTimeout(() => {
|
|
70
|
+
setCameraKey(prev => prev + 1);
|
|
71
|
+
setIsRebootingCamera(false);
|
|
72
|
+
}, 500);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const toggleCameraLens = () => {
|
|
76
|
+
setCameraType(prev => prev === 'back' ? 'front' : 'back');
|
|
77
|
+
refreshCamera();
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (value && Object.keys(value).length > 0) {
|
|
82
|
+
if (JSON.stringify(value) !== JSON.stringify(capturedImages)) {
|
|
83
|
+
const updatedImages = value as Record<string, IIDCardPayload>;
|
|
84
|
+
setCapturedImages(updatedImages);
|
|
85
|
+
const currentImageData = updatedImages[currentSide];
|
|
86
|
+
if (currentImageData?.dir) {
|
|
87
|
+
setSilentCaptureResult(prev => ({
|
|
88
|
+
...prev, path: currentImageData.dir, success: true, isAnalyzing: false, mrz: currentImageData.mrz || '', templatePath: currentImageData.templatePath || '',
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}, [value, currentSide]);
|
|
94
|
+
|
|
95
|
+
const cameraConfig = useMemo(() => {
|
|
96
|
+
const instructions = selectedDocumentType ? (locale === 'en' ? getDocumentTypeInfo(selectedDocumentType.type).instructions.en : getDocumentTypeInfo(selectedDocumentType.type).instructions.fr) : getLocalizedText(component.instructions as Record<string, LocalizedText>);
|
|
97
|
+
|
|
98
|
+
const isLandscape = screenWidth > screenHeight;
|
|
99
|
+
let xMin, xMax, yMin, yMax;
|
|
100
|
+
|
|
101
|
+
if (Platform.OS === 'web') {
|
|
102
|
+
// 🚨 UI FIX: Differentiate Desktop Web (Landscape) vs Mobile Web (Portrait)
|
|
103
|
+
const boxWidthPercent = isLandscape ? 0.40 : 0.85;
|
|
104
|
+
|
|
105
|
+
// On wide desktop, shift slightly right. On mobile portrait, center perfectly.
|
|
106
|
+
xMin = isLandscape ? 30 : 7.5;
|
|
107
|
+
xMax = xMin + (boxWidthPercent * 100);
|
|
108
|
+
|
|
109
|
+
// Safely calculate height to guarantee a 1.59 aspect ratio
|
|
110
|
+
const containerWidth = Math.min(screenWidth * 0.95, 1000);
|
|
111
|
+
const containerHeight = isLandscape ? screenHeight * 0.80 : screenHeight * 0.90;
|
|
112
|
+
|
|
113
|
+
const boxPixelWidth = containerWidth * boxWidthPercent;
|
|
114
|
+
const boxPixelHeight = boxPixelWidth / 1.59;
|
|
115
|
+
const heightPercent = (boxPixelHeight / containerHeight) * 100;
|
|
116
|
+
|
|
117
|
+
// Center vertically
|
|
118
|
+
yMin = (100 - heightPercent) / 2.5;
|
|
119
|
+
yMax = yMin + heightPercent;
|
|
120
|
+
} else {
|
|
121
|
+
xMin = 5; xMax = 95; yMin = 34; yMax = 66;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const platformBbox = { xMin, yMin, xMax, yMax, borderColor: '#2DBD60', borderWidth: Platform.OS === 'web' ? 2 : 3, cornerRadius: 8 };
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
cameraType: Platform.OS === 'web' ? cameraType : 'back',
|
|
128
|
+
flashMode: 'auto' as const,
|
|
129
|
+
overlay: { guideText: instructions, bbox: platformBbox }
|
|
130
|
+
};
|
|
131
|
+
}, [selectedDocumentType, locale, component.instructions, cameraType, screenWidth, screenHeight]);
|
|
132
|
+
|
|
133
|
+
const retakePicture = (sideToRetake: 'front' | 'back') => {
|
|
134
|
+
setIsProcessingCapture(false);
|
|
135
|
+
setProcessingImagePath(null);
|
|
136
|
+
setSilentCaptureResult({ path: '', success: false, isAnalyzing: false, error: '', templatePath: '', mrz: '', bbox: undefined });
|
|
137
|
+
setShowCamera(true);
|
|
138
|
+
refreshCamera();
|
|
139
|
+
actions.showCustomStepper(false);
|
|
140
|
+
setCapturedImages((prev) => { const newState = { ...prev }; delete newState[sideToRetake]; return newState; });
|
|
141
|
+
if (value) { const newValue = { ...value }; delete newValue[sideToRetake]; onValueChange(newValue); }
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const getCurrentSideVerification = (currentSide: string, countryKey: string) => {
|
|
145
|
+
const rawDocType = countrySelectionData?.documentType;
|
|
146
|
+
if (!rawDocType || !countryKey) { return { authMethod: [], mrzTypes: [], regionMapping: null, key: 'root' }; }
|
|
147
|
+
const rawCountryName = ISO_TO_COUNTRY_NAME[countryData?.code || ''] || countryData?.code || countryKey;
|
|
148
|
+
const baseMapping = (REGION_MAPPING as any).regionMapping || REGION_MAPPING;
|
|
149
|
+
let countryMapping = baseMapping[rawCountryName];
|
|
150
|
+
if (!countryMapping) {
|
|
151
|
+
const foundKey = Object.keys(baseMapping).find(k => k.toLowerCase() === rawCountryName.toLowerCase() || k.toLowerCase() === countryKey.toLowerCase());
|
|
152
|
+
if (foundKey) countryMapping = baseMapping[foundKey];
|
|
153
|
+
}
|
|
154
|
+
if (!countryMapping) { return { authMethod: [], mrzTypes: [], regionMapping: null, key: 'root' }; }
|
|
155
|
+
const regionMapping = countryMapping[rawDocType];
|
|
156
|
+
if (!regionMapping) { return { authMethod: [], mrzTypes: [], regionMapping: null, key: 'root' }; }
|
|
157
|
+
const authMethod: string[] = [];
|
|
158
|
+
const mrzTypes: string[] = [];
|
|
159
|
+
const key = countrySelectionData.region?.trim()?.length > 0 ? countrySelectionData.region.trim() : 'root';
|
|
160
|
+
if (regionMapping?.[key] && Array.isArray(regionMapping[key])) {
|
|
161
|
+
regionMapping[key].forEach((item: any) => {
|
|
162
|
+
if (item[currentSide]) {
|
|
163
|
+
authMethod.push(item[currentSide]);
|
|
164
|
+
if (item?.mrz_type) mrzTypes.push(item?.mrz_type);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
return { authMethod: removeDuplicates(authMethod), mrzTypes: removeDuplicates(mrzTypes), regionMapping, key };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const getCorrespondingMrzType = (templatePath: string, mapping: any, selectedDocumentType: string = "root") => {
|
|
172
|
+
if (!mapping || !mapping[selectedDocumentType]) return null;
|
|
173
|
+
const fileName = templatePath.split("/").pop()?.replace(".jpg", "").replace(".png", "");
|
|
174
|
+
if (!fileName) return null;
|
|
175
|
+
const pyName = `${fileName}.py`;
|
|
176
|
+
const found = mapping[selectedDocumentType].find((item: any) => item.py_file === pyName);
|
|
177
|
+
return found?.mrz_type || null;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const getCorrespondingAuthMethod = (templatePath: string, mapping: any, selectedDocumentType: string = "root", side: 'front' | 'back') => {
|
|
181
|
+
if (!mapping || !mapping[selectedDocumentType]) return null;
|
|
182
|
+
const fileName = templatePath.split("/").pop()?.replace(".jpg", "").replace(".png", "");
|
|
183
|
+
if (!fileName) return null;
|
|
184
|
+
const pyName = `${fileName}.py`;
|
|
185
|
+
const found = mapping[selectedDocumentType].find((item: any) => item.py_file === pyName);
|
|
186
|
+
return found?.[side] || null;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const autoCapture = async (capturePath: string, verified: ISilentCaptureResult) => {
|
|
190
|
+
if (isProcessingCapture) return;
|
|
191
|
+
setIsProcessingCapture(true);
|
|
192
|
+
setProcessingImagePath(capturePath);
|
|
193
|
+
try {
|
|
194
|
+
let imagePathForUpload = capturePath;
|
|
195
|
+
const overlayBbox = cameraConfig.overlay.bbox;
|
|
196
|
+
const uiCropBbox = {
|
|
197
|
+
minX: overlayBbox.xMin / 100,
|
|
198
|
+
minY: overlayBbox.yMin / 100,
|
|
199
|
+
width: (overlayBbox.xMax - overlayBbox.xMin) / 100,
|
|
200
|
+
height: (overlayBbox.yMax - overlayBbox.yMin) / 100,
|
|
201
|
+
};
|
|
202
|
+
try {
|
|
203
|
+
imagePathForUpload = await cropImageWithBBoxWithTolerance(capturePath, uiCropBbox, 0.06);
|
|
204
|
+
} catch (e) {
|
|
205
|
+
console.warn("Crop failed, falling back to original image", e);
|
|
206
|
+
imagePathForUpload = capturePath;
|
|
207
|
+
}
|
|
208
|
+
const base64 = await pathToBase64(imagePathForUpload);
|
|
209
|
+
const newImages = {
|
|
210
|
+
...capturedImages,
|
|
211
|
+
[currentSide]: { dir: imagePathForUpload, file: base64, mrz: verified.mrz || "", templatePath: verified.templatePath },
|
|
212
|
+
};
|
|
213
|
+
setCapturedImages(newImages);
|
|
214
|
+
if (verified.country && verified.documentType) {
|
|
215
|
+
onValueChange({
|
|
216
|
+
...newImages,
|
|
217
|
+
country: verified.country,
|
|
218
|
+
documentType: GovernmentDocumentTypeBackend[verified.documentType as keyof typeof GovernmentDocumentTypeBackend] || '',
|
|
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
|
+
if (result.success && result.path) {
|
|
241
|
+
setSilentCaptureResult((prev) => ({ ...prev, isAnalyzing: true, success: false, error: '' }));
|
|
242
|
+
let templatePath = capturedImages[currentSide]?.templatePath || '';
|
|
243
|
+
let templateBbox: IBbox | undefined;
|
|
244
|
+
let templateResponse: any;
|
|
245
|
+
if (!selectedDocumentType) {
|
|
246
|
+
setSilentCaptureResult((prev) => ({ ...prev, isAnalyzing: false, success: false, error: 'Document type not selected' }));
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
try {
|
|
250
|
+
if (!templatePath) {
|
|
251
|
+
const templateType = await checkTemplateType({ path: result.path || '', docType: selectedDocumentType?.type as GovernmentDocumentType, docRegion: countryData?.code || "", postfix: currentSide }, env);
|
|
252
|
+
templateResponse = templateType;
|
|
253
|
+
if (templateType.template_path) templatePath = templateType.template_path;
|
|
254
|
+
if (templateType.card_obb) {
|
|
255
|
+
const obbConfidence = getObbConfidence((templateType as any).card_obb);
|
|
256
|
+
if (obbConfidence !== null && obbConfidence < OBB_CONFIDENCE_THRESHOLD) {
|
|
257
|
+
setSilentCaptureResult((prev) => ({ ...prev, isAnalyzing: false, success: false, error: t('kyc.idCardCapture.cardNotFullyInFrame') }));
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
try {
|
|
261
|
+
const crop = await cropByObb(result.path, (templateType as any).card_obb);
|
|
262
|
+
templateBbox = crop.bbox;
|
|
263
|
+
} catch { }
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const extractedCountryKey = templatePath ? templatePath.split('/')[0] : (ISO_TO_COUNTRY_NAME[countryData?.code || ''] || 'root');
|
|
267
|
+
const regionMappings = getCurrentSideVerification(currentSide, extractedCountryKey);
|
|
268
|
+
let verificationRes: any;
|
|
269
|
+
if (currentSide === 'front') {
|
|
270
|
+
const matchedAuthMethod = getCorrespondingAuthMethod(templatePath, regionMappings.regionMapping, regionMappings.key || '', 'front');
|
|
271
|
+
const mrzType = getCorrespondingMrzType(templatePath, regionMappings.regionMapping, regionMappings.key || '') || 'TD1';
|
|
272
|
+
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);
|
|
273
|
+
} else {
|
|
274
|
+
let matchedBackAuthMethod = getCorrespondingAuthMethod(templatePath, regionMappings.regionMapping, regionMappings.key || '', 'back');
|
|
275
|
+
if (!matchedBackAuthMethod && currentSide === 'back') { matchedBackAuthMethod = 'MRZ'; }
|
|
276
|
+
const backMrzType = getCorrespondingMrzType(templatePath, regionMappings.regionMapping, regionMappings.key || '') || '';
|
|
277
|
+
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);
|
|
278
|
+
}
|
|
279
|
+
const bbox = verificationRes?.bbox || templateBbox;
|
|
280
|
+
const mrz = verificationRes?.mrz ? JSON.stringify(verificationRes.mrz) : "";
|
|
281
|
+
const verifiedResult: ISilentCaptureResult = { path: result.path, templatePath, bbox, success: true, mrz, isAnalyzing: false, country: countryData?.code, documentType: selectedDocumentType.type };
|
|
282
|
+
setSilentCaptureResult(verifiedResult);
|
|
283
|
+
if (bbox) setBboxBySide(prev => ({ ...prev, [currentSide]: bbox }));
|
|
284
|
+
await autoCapture(result.path, verifiedResult);
|
|
285
|
+
} catch (error: any) {
|
|
286
|
+
console.log("Backend Verification Error:", error);
|
|
287
|
+
const rawMessage = (error?.message || '').toLowerCase();
|
|
288
|
+
let userFriendlyMessage ='Verification failed. Please try again.';
|
|
289
|
+
if (rawMessage.includes('impossible') || rawMessage.includes('unreadable')) {
|
|
290
|
+
userFriendlyMessage = 'Document unreadable. Please hold the camera steady in good light.';
|
|
291
|
+
} else if (rawMessage.includes('country mismatch') || rawMessage.includes('pays sélectionné')) {
|
|
292
|
+
userFriendlyMessage = 'The document does not match your selected country.';
|
|
293
|
+
} else if (rawMessage.includes('card_not_fully_in_frame')) {
|
|
294
|
+
userFriendlyMessage = 'Move closer to the document and ensure all corners are visible.';
|
|
295
|
+
}
|
|
296
|
+
setSilentCaptureResult(prev => ({ ...prev, isAnalyzing: false, success: false, error: userFriendlyMessage }));
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
const handleError = (event: { message: string }) => {
|
|
302
|
+
showAlert('Erreur', event.message);
|
|
303
|
+
setShowCamera(false);
|
|
304
|
+
setIsProcessingCapture(false);
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
useEffect(() => {
|
|
308
|
+
actions.showCustomStepper(!showCamera);
|
|
309
|
+
}, [showCamera]);
|
|
310
|
+
|
|
311
|
+
if (!countrySelectionData || !selectedDocumentType) {
|
|
312
|
+
return (
|
|
313
|
+
<View style={styles.root}>
|
|
314
|
+
<View style={styles.previewContainer}>
|
|
315
|
+
<Text style={styles.title}>{getLocalizedText(component.labels)}</Text>
|
|
316
|
+
<Text style={styles.description}>
|
|
317
|
+
{state.currentLanguage === "en" ? "Please complete the country and document selection first." : "Veuillez d'abord compléter la sélection du pays et du document."}
|
|
318
|
+
</Text>
|
|
319
|
+
</View>
|
|
320
|
+
</View>
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
if (showCamera) {
|
|
325
|
+
const isBusy = isProcessingCapture;
|
|
326
|
+
if (isRebootingCamera) {
|
|
327
|
+
return (
|
|
328
|
+
<View style={[styles.root, { justifyContent: 'center', alignItems: 'center', backgroundColor: '#000' }]}>
|
|
329
|
+
<ActivityIndicator size="large" color="#2DBD60" />
|
|
330
|
+
<Text style={{ color: 'white', marginTop: 20, fontSize: 16 }}>Initializing Camera...</Text>
|
|
331
|
+
</View>
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
return (
|
|
335
|
+
<View style={styles.root}>
|
|
336
|
+
<View style={[styles.cameraWrapper, { flex: 1 }]}>
|
|
337
|
+
<View style={styles.headerContainer}>
|
|
338
|
+
<Text style={styles.headerTitle}>
|
|
339
|
+
{selectedDocumentType ? (locale === 'en' ? getDocumentTypeInfo(selectedDocumentType.type).name.en : getDocumentTypeInfo(selectedDocumentType.type).name.fr) : ''}
|
|
340
|
+
</Text>
|
|
341
|
+
<View style={styles.stepBadge}>
|
|
342
|
+
<Text style={styles.stepText}>
|
|
343
|
+
{t('kyc.idCardCapture.captureTitle', { side: currentSide === 'front' ? locale === 'en' ? 'Front' : 'Recto' : locale === 'en' ? 'Back' : 'Verso' })}
|
|
344
|
+
</Text>
|
|
345
|
+
</View>
|
|
346
|
+
</View>
|
|
347
|
+
|
|
348
|
+
<View style={[styles.cameraFeedContainer, { flex: 1, backgroundColor: '#000' }]}>
|
|
349
|
+
{Platform.OS === 'web' && (
|
|
350
|
+
<View style={styles.webTopControls}>
|
|
351
|
+
<TouchableOpacity style={styles.webFlipButton} onPress={toggleCameraLens}>
|
|
352
|
+
<Text style={styles.webFlipText}>🔄 Flip Lens</Text>
|
|
353
|
+
</TouchableOpacity>
|
|
354
|
+
</View>
|
|
355
|
+
)}
|
|
356
|
+
|
|
357
|
+
<EnhancedCameraView
|
|
358
|
+
key={`${currentSide}-${cameraKey}`}
|
|
359
|
+
showCamera={true}
|
|
360
|
+
isProcessing={isBusy}
|
|
361
|
+
cameraType={cameraConfig.cameraType}
|
|
362
|
+
style={{ ...StyleSheet.absoluteFillObject, ...(Platform.OS === 'web' ? { width: '100%', height: '100%', left: 0, top: 0 } as any : {}) }}
|
|
363
|
+
onError={handleError}
|
|
364
|
+
onSilentCapture={handleSilentCapture}
|
|
365
|
+
silentCaptureResult={silentCaptureResult}
|
|
366
|
+
overlayComponent={
|
|
367
|
+
<>
|
|
368
|
+
<IdCardOverlay
|
|
369
|
+
xMin={cameraConfig.overlay.bbox.xMin} yMin={cameraConfig.overlay.bbox.yMin} xMax={cameraConfig.overlay.bbox.xMax} yMax={cameraConfig.overlay.bbox.yMax}
|
|
370
|
+
instructions={cameraConfig.overlay.guideText}
|
|
371
|
+
cornerOpacity={cameraConfig.overlay.bbox.cornerRadius || 0 as number}
|
|
372
|
+
isSuccess={silentCaptureResult.success}
|
|
373
|
+
language={state.currentLanguage}
|
|
374
|
+
stepperProps={{
|
|
375
|
+
back: () => {
|
|
376
|
+
if (currentSide === 'back') {
|
|
377
|
+
setCurrentSide('front'); setShowCamera(false); setIsProcessingCapture(false); setProcessingImagePath(null);
|
|
378
|
+
if (capturedImages['front']?.dir) {
|
|
379
|
+
const frontImage = capturedImages['front'];
|
|
380
|
+
setSilentCaptureResult((prev) => ({ ...prev, path: frontImage.dir, success: true, isAnalyzing: false, error: '', mrz: frontImage.mrz || '', templatePath: frontImage.templatePath || '', bbox: bboxBySide['front'] }));
|
|
381
|
+
} else { setSilentCaptureResult((prev) => ({ ...prev, path: '', success: false, isAnalyzing: false, error: '', templatePath: '' })); }
|
|
382
|
+
} else { actions.previousComponent(); }
|
|
383
|
+
},
|
|
384
|
+
selectedDocumentType: selectedDocumentType ? (locale === 'en' ? getDocumentTypeInfo(selectedDocumentType.type).name.en : getDocumentTypeInfo(selectedDocumentType.type).name.fr) : '',
|
|
385
|
+
step: state.currentComponentIndex + 1, totalSteps: state.template.components.length, side: currentSide,
|
|
386
|
+
}}
|
|
387
|
+
/>
|
|
388
|
+
</>
|
|
389
|
+
}
|
|
390
|
+
/>
|
|
391
|
+
|
|
392
|
+
{!isBusy && silentCaptureResult.isAnalyzing && (
|
|
393
|
+
<View style={styles.topAnalyzingPillContainer}>
|
|
394
|
+
<View style={styles.topAnalyzingPill}>
|
|
395
|
+
<ActivityIndicator size="small" color="white" />
|
|
396
|
+
<Text style={styles.analyzingPillText}>
|
|
397
|
+
{state.currentLanguage === 'en' ? 'Scanning...' : 'Analyse...'}
|
|
398
|
+
</Text>
|
|
399
|
+
</View>
|
|
400
|
+
</View>
|
|
401
|
+
)}
|
|
402
|
+
|
|
403
|
+
{isBusy && (
|
|
404
|
+
<View style={[StyleSheet.absoluteFillObject, { zIndex: 9999 }]}>
|
|
405
|
+
{processingImagePath && (
|
|
406
|
+
<Image
|
|
407
|
+
source={{ uri: processingImagePath.startsWith('file://') ? processingImagePath : `file://${processingImagePath}` }}
|
|
408
|
+
style={StyleSheet.absoluteFillObject}
|
|
409
|
+
resizeMode="cover"
|
|
410
|
+
/>
|
|
411
|
+
)}
|
|
412
|
+
<View style={styles.processingOverlay}>
|
|
413
|
+
<ActivityIndicator size="large" color="#2DBD60" />
|
|
414
|
+
<Text style={styles.processingText}>
|
|
415
|
+
{state.currentLanguage === 'en' ? 'Perfect!\nProcessing Document...' : 'Parfait!\nTraitement du document...'}
|
|
416
|
+
</Text>
|
|
417
|
+
</View>
|
|
418
|
+
</View>
|
|
419
|
+
)}
|
|
420
|
+
|
|
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
|
+
)}
|
|
428
|
+
<View style={styles.webActionButtonsRow}>
|
|
429
|
+
<TouchableOpacity style={styles.webSecondaryButton} onPress={() => setShowCamera(false)}>
|
|
430
|
+
<Text style={styles.webSecondaryButtonText}>Cancel</Text>
|
|
431
|
+
</TouchableOpacity>
|
|
432
|
+
<TouchableOpacity style={styles.webPrimaryButton} onPress={refreshCamera}>
|
|
433
|
+
<Text style={styles.webPrimaryButtonText}>↻ Refresh Camera</Text>
|
|
434
|
+
</TouchableOpacity>
|
|
435
|
+
</View>
|
|
436
|
+
</View>
|
|
437
|
+
) : !isBusy ? (
|
|
438
|
+
<View style={styles.escapeHatchContainer}>
|
|
439
|
+
<TouchableOpacity style={styles.fallbackRefreshButton} onPress={refreshCamera}>
|
|
440
|
+
<Text style={styles.fallbackRefreshText}>↻ Refresh Camera</Text>
|
|
441
|
+
</TouchableOpacity>
|
|
442
|
+
<TouchableOpacity
|
|
443
|
+
style={[styles.fallbackRefreshButton, { marginTop: 15, backgroundColor: 'rgba(220, 38, 38, 0.8)', borderColor: '#DC2626' }]}
|
|
444
|
+
onPress={() => setShowCamera(false)}
|
|
445
|
+
>
|
|
446
|
+
<Text style={styles.fallbackRefreshText}>Cancel / Go Back</Text>
|
|
447
|
+
</TouchableOpacity>
|
|
448
|
+
</View>
|
|
449
|
+
) : null}
|
|
450
|
+
|
|
451
|
+
{silentCaptureResult.error && !isBusy && Platform.OS !== 'web' ? (
|
|
452
|
+
<View style={[styles.floatingErrorBanner, { zIndex: 10000 }]}>
|
|
453
|
+
<Text style={styles.floatingErrorText}>⚠️ {silentCaptureResult.error}</Text>
|
|
454
|
+
</View>
|
|
455
|
+
) : null}
|
|
456
|
+
</View>
|
|
457
|
+
</View>
|
|
458
|
+
</View>
|
|
459
|
+
);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
return (
|
|
463
|
+
<View style={styles.root}>
|
|
464
|
+
<View style={styles.previewContainer}>
|
|
465
|
+
<ScrollView style={styles.previewItemContainer} showsVerticalScrollIndicator={false}>
|
|
466
|
+
<View key={currentSide} style={styles.sideContainer}>
|
|
467
|
+
<Text style={styles.sideTitle}>
|
|
468
|
+
{t('kyc.idCardCapture.captureTitle', { side: currentSide === 'front' ? locale === 'en' ? 'Front' : 'Recto' : locale === 'en' ? 'Back' : 'Verso' })}
|
|
469
|
+
</Text>
|
|
470
|
+
<Text style={{ fontSize: 14, color: '#666', textAlign: 'center', marginBottom: 16, lineHeight: 22 }}>
|
|
471
|
+
{getLocalizedText(component.instructions)}
|
|
472
|
+
</Text>
|
|
473
|
+
<View style={{ alignItems: 'center', justifyContent: 'center', flexDirection: "column", gap: 16 }}>
|
|
474
|
+
<View style={styles.imagePreviewWrapper}>
|
|
475
|
+
{capturedImages[currentSide]?.dir ? (
|
|
476
|
+
<Image source={{ uri: capturedImages[currentSide].dir }} style={styles.previewImage} />
|
|
477
|
+
) : silentCaptureResult.path ? (
|
|
478
|
+
<Image source={{ uri: silentCaptureResult.path }} style={styles.previewImage} />
|
|
479
|
+
) : null}
|
|
480
|
+
</View>
|
|
481
|
+
{!capturedImages[currentSide]?.dir && (
|
|
482
|
+
<View style={{ width: '100%', gap: 12 }}>
|
|
483
|
+
<Button
|
|
484
|
+
title={state.currentLanguage === "en" ? "Start Scanning" : "Commencer la numérisation"}
|
|
485
|
+
onPress={() => { setShowCamera(true); refreshCamera(); actions.showCustomStepper(false); }}
|
|
486
|
+
variant="primary" size="large" fullWidth
|
|
487
|
+
/>
|
|
488
|
+
{Platform.OS === 'web' && (
|
|
489
|
+
<Button
|
|
490
|
+
title={state.currentLanguage === "en" ? "Continue on Phone" : "Continuer sur le téléphone"}
|
|
491
|
+
onPress={() => setShowQRModal(true)}
|
|
492
|
+
variant="outline" size="large" fullWidth
|
|
493
|
+
/>
|
|
494
|
+
)}
|
|
495
|
+
</View>
|
|
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); refreshCamera(); setCurrentSide('back'); setSilentCaptureResult({ success: false, isAnalyzing: false, path: '', error: '', templatePath: undefined }); setIsProcessingCapture(false); setProcessingImagePath(null);
|
|
506
|
+
}
|
|
507
|
+
}} variant="primary" size="large" fullWidth />
|
|
508
|
+
</>
|
|
509
|
+
)}
|
|
510
|
+
</View>
|
|
511
|
+
</View>
|
|
512
|
+
</ScrollView>
|
|
513
|
+
</View>
|
|
514
|
+
{showQRModal && Platform.OS === 'web' && (
|
|
515
|
+
<View style={styles.qrModalOverlay}>
|
|
516
|
+
<View style={styles.qrModalContainer}>
|
|
517
|
+
<Text style={styles.qrModalTitle}>
|
|
518
|
+
{state.currentLanguage === 'en' ? 'Scan to continue' : 'Scannez pour continuer'}
|
|
519
|
+
</Text>
|
|
520
|
+
<Text style={styles.qrModalText}>
|
|
521
|
+
{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."}
|
|
522
|
+
</Text>
|
|
523
|
+
<View style={styles.qrCodeWrapper}>
|
|
524
|
+
<QRCode value={currentUrl} size={220} backgroundColor="transparent" />
|
|
525
|
+
</View>
|
|
526
|
+
<Button title={state.currentLanguage === 'en' ? "Close" : "Fermer"} onPress={() => setShowQRModal(false)} variant="outline" fullWidth />
|
|
527
|
+
</View>
|
|
528
|
+
</View>
|
|
529
|
+
)}
|
|
530
|
+
</View>
|
|
531
|
+
);
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
const styles = StyleSheet.create({
|
|
535
|
+
root: { flex: 1, width: '100%', backgroundColor: 'transparent', alignSelf: 'center', ...Platform.select({ web: { minHeight: '85vh', justifyContent: 'center', alignItems: 'center' } as any, }) },
|
|
536
|
+
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 } }) },
|
|
537
|
+
// 🚨 UI FIX: flexWrap handles overflowing text perfectly on narrow mobile screens
|
|
538
|
+
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' } }) },
|
|
539
|
+
headerTitle: { fontSize: 18, fontWeight: '700', color: '#0F172A', flexShrink: 1 },
|
|
540
|
+
stepBadge: { backgroundColor: '#F1F5F9', paddingHorizontal: 12, paddingVertical: 6, borderRadius: 20, },
|
|
541
|
+
stepText: { fontSize: 13, fontWeight: '600', color: '#64748B', },
|
|
542
|
+
cameraFeedContainer: { flex: 1, position: 'relative', backgroundColor: '#000', },
|
|
543
|
+
escapeHatchContainer: { position: 'absolute', bottom: 40, left: 0, right: 0, alignItems: 'center', justifyContent: 'center', zIndex: 99999 },
|
|
544
|
+
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 },
|
|
545
|
+
fallbackRefreshText: { color: '#FFFFFF', fontWeight: 'bold', fontSize: 16 },
|
|
546
|
+
webBottomControlBar: { position: 'absolute', bottom: 0, left: 0, right: 0, paddingHorizontal: 24, paddingBottom: 24, paddingTop: 30, backgroundColor: 'rgba(0,0,0,0.6)', zIndex: 99999 },
|
|
547
|
+
webActionButtonsRow: { flexDirection: 'row', justifyContent: 'center', gap: 16, marginTop: 12, maxWidth: 500, alignSelf: 'center', width: '100%' },
|
|
548
|
+
webPrimaryButton: { flex: 1, backgroundColor: '#2DBD60', paddingVertical: 14, borderRadius: 12, alignItems: 'center' },
|
|
549
|
+
webPrimaryButtonText: { color: 'white', fontWeight: 'bold', fontSize: 16 },
|
|
550
|
+
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' },
|
|
551
|
+
webSecondaryButtonText: { color: 'white', fontWeight: 'bold', fontSize: 16 },
|
|
552
|
+
webTopControls: { position: 'absolute', top: Platform.OS === 'ios' ? 70 : 20, right: 20, zIndex: 9999 },
|
|
553
|
+
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 }) },
|
|
554
|
+
webFlipText: { color: 'white', fontWeight: 'bold', fontSize: 14 },
|
|
555
|
+
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%' }}) },
|
|
556
|
+
previewItemContainer: { flexGrow: 1, },
|
|
557
|
+
title: { fontSize: 24, fontWeight: 'bold', color: '#333', marginBottom: 8, textAlign: 'center' },
|
|
558
|
+
description: { fontSize: 16, color: '#666', textAlign: 'center', marginBottom: 24, lineHeight: 22 },
|
|
559
|
+
sideContainer: { marginBottom: 24 },
|
|
560
|
+
sideTitle: { fontSize: 22, fontWeight: 'bold', color: '#000', marginBottom: 12, textAlign: 'center' },
|
|
561
|
+
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 } }) },
|
|
562
|
+
previewImage: { width: '100%', height: '100%', borderRadius: 12, resizeMode: 'cover' },
|
|
563
|
+
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 } }) },
|
|
564
|
+
floatingErrorText: { color: '#991B1B', fontSize: 14, fontWeight: '700', textAlign: 'center' },
|
|
565
|
+
processingOverlay: { flex: 1, backgroundColor: 'rgba(0, 0, 0, 0.7)', justifyContent: 'center', alignItems: 'center', zIndex: 9999, ...Platform.select({ web: { backdropFilter: 'blur(4px)' } as any }) },
|
|
566
|
+
processingText: { color: '#FFF', fontSize: 18, fontWeight: 'bold', marginTop: 16, textAlign: 'center' },
|
|
567
|
+
errorText: { color: '#dc2626', fontSize: 14, marginTop: 8, textAlign: 'center' },
|
|
568
|
+
// 🚨 UI FIX: Dropped the pill slightly lower so it never overlaps the flip lens button
|
|
569
|
+
topAnalyzingPillContainer: { position: 'absolute', top: Platform.OS === 'android' ? 60 : 75, left: 0, right: 0, alignItems: 'center', zIndex: 100 },
|
|
570
|
+
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 },
|
|
571
|
+
analyzingPillText: { color: 'white', fontSize: 14, fontWeight: 'bold' },
|
|
572
|
+
qrModalOverlay: { ...StyleSheet.absoluteFillObject, backgroundColor: 'rgba(0,0,0,0.6)', justifyContent: 'center', alignItems: 'center', zIndex: 999999, ...Platform.select({ web: { backdropFilter: 'blur(5px)' } as any }) },
|
|
573
|
+
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, },
|
|
574
|
+
qrModalTitle: { fontSize: 22, fontWeight: 'bold', color: '#0F172A', marginBottom: 12, textAlign: 'center' },
|
|
575
|
+
qrModalText: { fontSize: 15, color: '#64748B', textAlign: 'center', marginBottom: 24, lineHeight: 22, },
|
|
576
|
+
qrCodeWrapper: { padding: 16, backgroundColor: '#FFFFFF', borderRadius: 16, borderWidth: 1, borderColor: '#E2E8F0', marginBottom: 24, }
|
|
598
577
|
});
|