@transfergratis/react-native-sdk 0.1.29 → 0.1.31

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.
@@ -44,8 +44,7 @@ export const IDCardCapture: React.FC<IDCardCaptureProps> = ({
44
44
  const [showCamera, setShowCamera] = useState(false);
45
45
  const [capturedImages, setCapturedImages] = useState<Record<string, IIDCardPayload>>(value || {});
46
46
  // const [cropImageUri, setCropImageUri] = useState<string>('');
47
- const [currentSide, setCurrentSide] = useState<string>('front');
48
- // Stocker les bbox par côté pour pouvoir restaurer les images croppées
47
+ const [currentSide, setCurrentSide] = useState<'front' | 'back'>('front');
49
48
  const [bboxBySide, setBboxBySide] = useState<Record<string, IBbox>>({});
50
49
  const [silentCaptureResult, setSilentCaptureResult] = useState<ISilentCaptureResult>({ success: false, isAnalyzing: false });
51
50
  const [showQRModal, setShowQRModal] = useState(false);
@@ -169,24 +168,34 @@ export const IDCardCapture: React.FC<IDCardCaptureProps> = ({
169
168
  };
170
169
  }, [selectedDocumentType, locale, component.instructions]);
171
170
 
172
- const retakePicture = (currentSide: string) => {
171
+ const retakePicture = (sideToRetake: 'front' | 'back') => {
172
+ // 1. Turn the camera back on and hide the stepper
173
173
  setShowCamera(true);
174
174
  actions.showCustomStepper(false);
175
- setCapturedImages({ ...capturedImages, [currentSide]: { dir: '', file: '', mrz: '' } });
176
-
177
- setSilentCaptureResult((prev) => ({
178
- ...prev,
179
- path: '',
180
- success: false,
181
- isAnalyzing: false,
182
- error: '',
183
- templatePath: '',
184
- bbox: undefined,
185
- mrz: ''
186
- }));
175
+
176
+ // 2. WIPE LOCAL STATE: Use functional update to prevent stale closures
177
+ setCapturedImages((prev) => {
178
+ const newState = { ...prev };
179
+ delete newState[sideToRetake];
180
+ return newState;
181
+ });
182
+
183
+ setSilentCaptureResult({
184
+ path: '',
185
+ success: false,
186
+ isAnalyzing: false,
187
+ error: '',
188
+ templatePath: '',
189
+ mrz: '',
190
+ bbox: undefined,
191
+ });
192
+
187
193
 
188
- // setCropImageUri('');
189
- onValueChange({ ...value, [currentSide]: { dir: '', file: '', mrz: '' } });
194
+ if (value) {
195
+ const newValue = { ...value };
196
+ delete newValue[sideToRetake];
197
+ onValueChange(newValue);
198
+ }
190
199
  };
191
200
 
192
201
 
@@ -315,26 +324,33 @@ export const IDCardCapture: React.FC<IDCardCaptureProps> = ({
315
324
  };
316
325
  console.log("frontVerification params", verificationParams);
317
326
  console.log("About to call frontVerification function");
327
+
318
328
  const promise = frontVerification(verificationParams, env);
319
329
  console.log("frontVerification promise created", promise);
320
- promise.then((mrz) => {
321
- logger.log("front verification result", truncateFields(mrz));
322
- const bbox = (mrz as any)?.bbox || templateBbox;
330
+
331
+ promise.then((res: any) => {
332
+ logger.log("front verification result", truncateFields(res));
333
+ const bbox = res?.bbox || templateBbox;
334
+
323
335
  setSilentCaptureResult((prev) => ({
324
336
  ...prev,
325
337
  path: result.path,
326
338
  templatePath: templatePath,
327
- bbox: bbox, success: true,
328
- mrz: JSON.stringify(mrz), isAnalyzing: false,
339
+ bbox: bbox,
340
+ success: true,
341
+ mrz: res?.mrz ? JSON.stringify(res.mrz) : "",
342
+ isAnalyzing: false,
329
343
  country: countryData?.code,
330
344
  documentType: selectedDocumentType.type,
331
- }),
332
- );
345
+ }));
346
+
333
347
  // Stocker le bbox pour ce côté
334
348
  if (bbox && typeof bbox === 'object') {
335
349
  setBboxBySide((prev) => ({ ...prev, [currentSide]: bbox }));
336
350
  }
337
351
 
352
+ }).catch((e: any) => {
353
+
338
354
  }).catch((e: any) => {
339
355
  console.log("error front verification", e);
340
356
  logger.log("error front verification", truncateFields(e));
@@ -354,6 +370,7 @@ export const IDCardCapture: React.FC<IDCardCaptureProps> = ({
354
370
  } else {
355
371
  const backRegionMappings = getCurrentSideVerification(currentSide);
356
372
  logger.log("Calling backVerification", { templatePath, selectedDocumentType: selectedDocumentType.type, backRegionMappings });
373
+
357
374
  backVerification({
358
375
  path: result.path,
359
376
  regionMapping: {
@@ -365,16 +382,21 @@ export const IDCardCapture: React.FC<IDCardCaptureProps> = ({
365
382
  currentSide: currentSide,
366
383
  templatePath: templatePath,
367
384
  mrzType: getCorrespondingMrzType(templatePath, backRegionMappings.regionMapping, backRegionMappings.key || '') || '',
368
- }, env).then((mrz) => {
369
- logger.log("back verification result", truncateFields(mrz));
370
- const bbox = (mrz as any)?.bbox || templateBbox;
385
+ }, env).then((res: any) => {
386
+ logger.log("back verification result", truncateFields(res));
387
+ const bbox = res?.bbox || templateBbox;
388
+
371
389
  setSilentCaptureResult((prev) => ({
372
- ...prev, path: result.path, bbox: bbox,
373
- success: true, mrz: JSON.stringify(mrz), isAnalyzing: false,
390
+ ...prev,
391
+ path: result.path,
392
+ bbox: bbox,
393
+ success: true,
394
+ mrz: res?.mrz ? JSON.stringify(res.mrz) : "",
395
+ isAnalyzing: false,
374
396
  country: countryData?.code,
375
397
  documentType: selectedDocumentType.type,
376
-
377
398
  }));
399
+
378
400
  // Stocker le bbox pour ce côté
379
401
  if (bbox && typeof bbox === 'object') {
380
402
  setBboxBySide((prev) => ({ ...prev, [currentSide]: bbox }));
@@ -389,7 +411,7 @@ export const IDCardCapture: React.FC<IDCardCaptureProps> = ({
389
411
  ? t('kyc.idCardCapture.cardNotFullyInFrame')
390
412
  : (e?.message || 'Erreur de détection du MRZ');
391
413
  setSilentCaptureResult((prev) => ({ ...prev, isAnalyzing: false, templatePath: templatePath, success: false, error: errorMessage }));
392
- })
414
+ });
393
415
  }
394
416
 
395
417
  }
@@ -633,6 +655,26 @@ export const IDCardCapture: React.FC<IDCardCaptureProps> = ({
633
655
  </Text>
634
656
 
635
657
  <View style={{ alignItems: 'center', justifyContent: 'center', flexDirection: "column", gap: 16 }}>
658
+ {silentCaptureResult?.error === 'TOO_FAR_AWAY' && (
659
+ <View style={{
660
+ backgroundColor: '#FF9500',
661
+ padding: 12,
662
+ borderRadius: 8,
663
+ width: '100%',
664
+ shadowColor: '#000',
665
+ shadowOffset: { width: 0, height: 2 },
666
+ shadowOpacity: 0.2,
667
+ shadowRadius: 4,
668
+ elevation: 4
669
+ }}>
670
+ <Text style={{ color: 'white', fontWeight: 'bold', textAlign: 'center', fontSize: 16 }}>
671
+ {state.currentLanguage === "en"
672
+ ? "Move the document closer to the camera."
673
+ : "Veuillez rapprocher le document de la caméra."}
674
+ </Text>
675
+ </View>
676
+ )}
677
+
636
678
  <View
637
679
  style={{
638
680
  width: '100%',
@@ -645,18 +687,17 @@ export const IDCardCapture: React.FC<IDCardCaptureProps> = ({
645
687
  shadowOpacity: 0.18,
646
688
  shadowRadius: 8,
647
689
  elevation: 8,
648
- backgroundColor: '#fff',
690
+ backgroundColor: '#000',
649
691
  }}
650
692
  >
651
- {/* Simplified logic: Always show the saved, pre-cropped capture! */}
652
693
  {capturedImages[currentSide]?.dir ? (
653
694
  <Image
654
695
  source={{ uri: capturedImages[currentSide].dir }}
655
696
  style={{
656
697
  width: '100%',
657
- height: 200,
698
+ height: '100%',
658
699
  borderRadius: 12,
659
- resizeMode: 'cover',
700
+ resizeMode: 'contain',
660
701
  }}
661
702
  />
662
703
  ) : silentCaptureResult.path ? (
@@ -664,9 +705,9 @@ export const IDCardCapture: React.FC<IDCardCaptureProps> = ({
664
705
  source={{ uri: silentCaptureResult.path }}
665
706
  style={{
666
707
  width: '100%',
667
- height: 200,
708
+ height: '100%',
668
709
  borderRadius: 12,
669
- resizeMode: 'cover',
710
+ resizeMode: 'contain',
670
711
  }}
671
712
  />
672
713
  ) : null}
@@ -73,7 +73,7 @@
73
73
  "identity_card": {
74
74
  "root": [
75
75
  {
76
- "py_file": "cameroon_id_back_1_1.py",
76
+ "py_file": "cameroon_id_back_1_1_new.py",
77
77
  "back": "MRZ",
78
78
  "mrz_type": "TD1"
79
79
  },
@@ -96,11 +96,7 @@
96
96
  "mrz_type": "TD1"
97
97
  },
98
98
  {
99
- "py_file": "cameroon_id_front_1_1.py",
100
- "keys_found": null
101
- },
102
- {
103
- "py_file": "cameroon_id_front_2_1.py",
99
+ "py_file": "cameroon_id_front_1_1_new.py",
104
100
  "keys_found": null
105
101
  },
106
102
  {
@@ -599,30 +595,26 @@
599
595
  "identity_card": {
600
596
  "root": [
601
597
  {
602
- "py_file": "back_1.py",
598
+ "py_file": "back_2.py",
603
599
  "back": "MRZ",
604
600
  "mrz_type": "TD1"
605
601
  },
606
602
  {
607
- "py_file": "back_2.py",
608
- "back": "MRZ",
609
- "mrz_type": "TD1"
603
+ "py_file": "front_3.py",
604
+ "keys_found": null
610
605
  },
611
606
  {
612
- "py_file": "back_3.py",
607
+ "py_file": "kenya_back_1.py",
613
608
  "back": "MRZ",
614
609
  "mrz_type": "TD1"
615
610
  },
616
611
  {
617
- "py_file": "front_1.py",
618
- "keys_found": null
619
- },
620
- {
621
- "py_file": "front_2.py",
622
- "keys_found": null
612
+ "py_file": "kenya_back_3.py",
613
+ "back": "MRZ",
614
+ "mrz_type": "TD1"
623
615
  },
624
616
  {
625
- "py_file": "front_3.py",
617
+ "py_file": "kenya_front_2.py",
626
618
  "keys_found": null
627
619
  }
628
620
  ]
@@ -75,7 +75,7 @@ export const countryMapping: Record<string, Record<string, Record<string, ICount
75
75
  "identity_card": {
76
76
  "root": [
77
77
  {
78
- "py_file": "cameroon_id_back_1_1.py",
78
+ "py_file": "cameroon_id_back_1_1_new.py",
79
79
  "back": "MRZ",
80
80
  "mrz_type": "TD1"
81
81
  },
@@ -98,11 +98,7 @@ export const countryMapping: Record<string, Record<string, Record<string, ICount
98
98
  "mrz_type": "TD1"
99
99
  },
100
100
  {
101
- "py_file": "cameroon_id_front_1_1.py",
102
- "keys_found": null
103
- },
104
- {
105
- "py_file": "cameroon_id_front_2_1.py",
101
+ "py_file": "cameroon_id_front_1_1_new.py",
106
102
  "keys_found": null
107
103
  },
108
104
  {
@@ -601,30 +597,26 @@ export const countryMapping: Record<string, Record<string, Record<string, ICount
601
597
  "identity_card": {
602
598
  "root": [
603
599
  {
604
- "py_file": "back_1.py",
600
+ "py_file": "back_2.py",
605
601
  "back": "MRZ",
606
602
  "mrz_type": "TD1"
607
603
  },
608
604
  {
609
- "py_file": "back_2.py",
610
- "back": "MRZ",
611
- "mrz_type": "TD1"
605
+ "py_file": "front_3.py",
606
+ "keys_found": null
612
607
  },
613
608
  {
614
- "py_file": "back_3.py",
609
+ "py_file": "kenya_back_1.py",
615
610
  "back": "MRZ",
616
611
  "mrz_type": "TD1"
617
612
  },
618
613
  {
619
- "py_file": "front_1.py",
620
- "keys_found": null
621
- },
622
- {
623
- "py_file": "front_2.py",
624
- "keys_found": null
614
+ "py_file": "kenya_back_3.py",
615
+ "back": "MRZ",
616
+ "mrz_type": "TD1"
625
617
  },
626
618
  {
627
- "py_file": "front_3.py",
619
+ "py_file": "kenya_front_2.py",
628
620
  "keys_found": null
629
621
  }
630
622
  ]