@sanctum-key/react-native-sdk 1.0.32 → 1.0.34
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/build/package.json +2 -1
- package/build/src/components/EnhancedCameraView.d.ts.map +1 -1
- package/build/src/components/EnhancedCameraView.js +35 -19
- 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 +91 -39
- package/build/src/components/KYCElements/IDCardCapture.js.map +1 -1
- package/build/src/modules/api/KYCService.d.ts +0 -7
- package/build/src/modules/api/KYCService.d.ts.map +1 -1
- package/build/src/modules/api/KYCService.js +48 -119
- package/build/src/modules/api/KYCService.js.map +1 -1
- package/package.json +2 -1
- package/src/components/EnhancedCameraView.tsx +41 -23
- package/src/components/KYCElements/IDCardCapture.tsx +121 -58
- package/src/modules/api/KYCService.ts +357 -534
package/build/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanctum-key/react-native-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.34",
|
|
4
4
|
"description": "Sanctum Key React Native SDK",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"types": "build/src/index.d.ts",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"i18n-js": "4.5.1",
|
|
55
55
|
"iconsax-react-nativejs": "^0.0.8",
|
|
56
56
|
"react-native-qrcode-svg": "^6.3.21",
|
|
57
|
+
"react-native-worklets-core": "^1.6.3",
|
|
57
58
|
"zustand": "^5.0.8"
|
|
58
59
|
},
|
|
59
60
|
"devDependencies": {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnhancedCameraView.d.ts","sourceRoot":"","sources":["../../../src/components/EnhancedCameraView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmD,MAAM,OAAO,CAAC;AAExE,OAAO,E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EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAiP5D,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
-
import { View, StyleSheet, Text, Platform } from 'react-native';
|
|
2
|
+
import { View, StyleSheet, Text, Platform, AppState } from 'react-native';
|
|
3
3
|
import { Camera, useCameraDevice, useCodeScanner } from 'react-native-vision-camera';
|
|
4
4
|
import VisionCameraModule from '../modules/camera/VisionCameraModule';
|
|
5
5
|
import { useI18n } from '../hooks/useI18n';
|
|
@@ -10,6 +10,9 @@ export const EnhancedCameraView = ({ showCamera, cameraType: initialCameraType =
|
|
|
10
10
|
const webVideoRef = useRef(null);
|
|
11
11
|
const isCapturingRef = useRef(false);
|
|
12
12
|
const isProcessingRef = useRef(isProcessing);
|
|
13
|
+
// Ref-tracked isAnalyzing so captureSilentPhoto always reads the latest
|
|
14
|
+
// value — the prop-based closure goes stale on iOS between renders.
|
|
15
|
+
const isAnalyzingRef = useRef(silentCaptureResult?.isAnalyzing ?? false);
|
|
13
16
|
const [cameraType] = useState(initialCameraType);
|
|
14
17
|
const [hasPermission, setHasPermission] = useState(null);
|
|
15
18
|
const [isInitialized, setIsInitialized] = useState(false);
|
|
@@ -17,26 +20,40 @@ export const EnhancedCameraView = ({ showCamera, cameraType: initialCameraType =
|
|
|
17
20
|
const [isVideoFound, setIsVideoFound] = useState(false);
|
|
18
21
|
const scannedBarcodeRef = useRef(null);
|
|
19
22
|
const containerRef = useRef(null);
|
|
23
|
+
const [appState, setAppState] = useState(AppState.currentState);
|
|
20
24
|
const device = useCameraDevice(cameraType);
|
|
25
|
+
useEffect(() => { isProcessingRef.current = isProcessing; }, [isProcessing]);
|
|
26
|
+
useEffect(() => { isAnalyzingRef.current = silentCaptureResult?.isAnalyzing ?? false; }, [silentCaptureResult?.isAnalyzing]);
|
|
21
27
|
useEffect(() => {
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
const subscription = AppState.addEventListener('change', nextAppState => {
|
|
29
|
+
setAppState(nextAppState);
|
|
30
|
+
});
|
|
31
|
+
return () => {
|
|
32
|
+
subscription.remove();
|
|
33
|
+
};
|
|
34
|
+
}, []);
|
|
24
35
|
const checkPermissions = async () => {
|
|
25
36
|
try {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
// getCameraPermissionStatus is synchronous — no await
|
|
38
|
+
const cameraStatus = Camera.getCameraPermissionStatus();
|
|
39
|
+
if (cameraStatus === 'granted') {
|
|
40
|
+
setHasPermission(true);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (cameraStatus === 'not-determined') {
|
|
44
|
+
const result = await Camera.requestCameraPermission();
|
|
45
|
+
if (result === 'granted') {
|
|
46
|
+
setHasPermission(true);
|
|
36
47
|
return;
|
|
37
48
|
}
|
|
38
49
|
}
|
|
39
|
-
|
|
50
|
+
// 'denied' or 'restricted' — user must enable in Settings
|
|
51
|
+
setHasPermission(false);
|
|
52
|
+
onError?.({
|
|
53
|
+
message: t('camera.permissionRequired'),
|
|
54
|
+
name: 'NotAllowedError',
|
|
55
|
+
code: 'permission-denied'
|
|
56
|
+
});
|
|
40
57
|
}
|
|
41
58
|
catch (e) {
|
|
42
59
|
setHasPermission(false);
|
|
@@ -52,7 +69,6 @@ export const EnhancedCameraView = ({ showCamera, cameraType: initialCameraType =
|
|
|
52
69
|
checkPermissions();
|
|
53
70
|
}, [showCamera, refreshCamera]);
|
|
54
71
|
const onInitialized = useCallback(() => setIsInitialized(true), []);
|
|
55
|
-
// 🚨 UPDATED: Catch Vision Camera deep errors (e.g. session-in-use) and pass them up
|
|
56
72
|
const onCameraError = useCallback((error) => {
|
|
57
73
|
console.warn("🎥 [Vision Camera Error Caught]:", error);
|
|
58
74
|
onError?.({
|
|
@@ -78,7 +94,7 @@ export const EnhancedCameraView = ({ showCamera, cameraType: initialCameraType =
|
|
|
78
94
|
const captureSilentPhoto = useCallback(async () => {
|
|
79
95
|
if (!camera.current || !isInitialized || isProcessingRef.current || isCapturingRef.current)
|
|
80
96
|
return;
|
|
81
|
-
if (
|
|
97
|
+
if (isAnalyzingRef.current)
|
|
82
98
|
return;
|
|
83
99
|
try {
|
|
84
100
|
isCapturingRef.current = true;
|
|
@@ -97,8 +113,8 @@ export const EnhancedCameraView = ({ showCamera, cameraType: initialCameraType =
|
|
|
97
113
|
barcode: scannedBarcodeRef.current
|
|
98
114
|
});
|
|
99
115
|
}
|
|
100
|
-
catch {
|
|
101
|
-
|
|
116
|
+
catch (error) {
|
|
117
|
+
console.log('Silent capture skipped/failed:', error?.message);
|
|
102
118
|
}
|
|
103
119
|
finally {
|
|
104
120
|
isCapturingRef.current = false;
|
|
@@ -173,7 +189,7 @@ export const EnhancedCameraView = ({ showCamera, cameraType: initialCameraType =
|
|
|
173
189
|
if (!device || !showCamera)
|
|
174
190
|
return <View style={[styles.container, style]}/>;
|
|
175
191
|
return (<View ref={containerRef} style={[styles.container, style]}>
|
|
176
|
-
<Camera ref={camera} style={StyleSheet.absoluteFill} device={device} resizeMode="cover" isActive={showCamera && !isProcessing} photo={true} video={false} audio={false} onInitialized={onInitialized} onError={onCameraError} codeScanner={Platform.OS !== 'web' && isScanningBarcode ? codeScanner : undefined}/>
|
|
192
|
+
<Camera ref={camera} style={StyleSheet.absoluteFill} device={device} resizeMode="cover" isActive={showCamera && !isProcessing && appState === 'active'} photo={true} video={false} audio={false} onInitialized={onInitialized} onError={onCameraError} codeScanner={Platform.OS !== 'web' && isScanningBarcode ? codeScanner : undefined}/>
|
|
177
193
|
{Platform.OS === 'web' && isScanningBarcode && isVideoFound && (<WebBarcodeScanner videoRef={webVideoRef} onBarcodeScanned={handleWebBarcodeScanned} active={!isProcessingRef.current}/>)}
|
|
178
194
|
{overlayComponent}
|
|
179
195
|
</View>);
|
|
@@ -1 +1 @@
|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,CAAC;IAC/B,SAAS,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,eAAe,EAAE,OAAO,EAAE;IAChD,iBAAiB,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE;CACrF,CAAC,CAAC","sourcesContent":["import React, { useCallback, useEffect, useRef, useState } from 'react';\nimport { View, StyleSheet, Text, Platform } from 'react-native';\nimport { Camera, CodeType, useCameraDevice, useCodeScanner } from 'react-native-vision-camera';\nimport VisionCameraModule from '../modules/camera/VisionCameraModule';\nimport { useI18n } from '../hooks/useI18n';\nimport { EnhancedCameraViewProps } from './OverLay/type';\nimport { WebBarcodeScanner } from './WebBarcodeScanner';\n\nexport interface ExtendedCameraProps extends Omit<EnhancedCameraViewProps, 'onError'> {\n isScanningBarcode?: boolean;\n onBarcodeScanned?: (data: string) => void;\n barcodeTypes?: CodeType[];\n onError?: (error: { message: string; name?: string; code?: string }) => void; \n}\n\nexport const EnhancedCameraView: React.FC<ExtendedCameraProps> = ({\n showCamera,\n cameraType: initialCameraType = 'front',\n style,\n onError,\n onSilentCapture,\n silentCaptureResult,\n isProcessing = false,\n overlayComponent,\n isScanningBarcode = false,\n onBarcodeScanned,\n barcodeTypes\n}) => {\n const { t } = useI18n();\n const camera = useRef<Camera>(null);\n const webVideoRef = useRef<HTMLVideoElement | null>(null);\n \n const isCapturingRef = useRef(false);\n const isProcessingRef = useRef(isProcessing);\n \n const [cameraType] = useState<'front' | 'back'>(initialCameraType);\n const [hasPermission, setHasPermission] = useState<boolean | null>(null);\n const [isInitialized, setIsInitialized] = useState(false);\n const [refreshCamera] = useState(false);\n \n const [isVideoFound, setIsVideoFound] = useState(false);\n const scannedBarcodeRef = useRef<string | null>(null);\n const containerRef = useRef<any>(null);\n\n const device = useCameraDevice(cameraType);\n\n useEffect(() => {\n isProcessingRef.current = isProcessing;\n }, [isProcessing]);\n\n const checkPermissions = async () => {\n try {\n let cameraStatus = Camera.getCameraPermissionStatus();\n \n if (cameraStatus !== 'granted') {\n cameraStatus = await Camera.requestCameraPermission();\n \n if (cameraStatus !== 'granted') {\n setHasPermission(false);\n onError?.({ \n message: t('camera.permissionRequired'),\n name: 'NotAllowedError', \n code: 'permission-denied'\n });\n return;\n }\n }\n setHasPermission(true);\n } catch (e: any) {\n setHasPermission(false);\n onError?.({ \n message: e.message || t('camera.errorOccurred'),\n name: e.name || 'UnknownError',\n code: e.code || 'unknown'\n });\n }\n };\n\n useEffect(() => {\n if (showCamera) checkPermissions();\n }, [showCamera, refreshCamera]);\n\n const onInitialized = useCallback(() => setIsInitialized(true), []);\n\n // 🚨 UPDATED: Catch Vision Camera deep errors (e.g. session-in-use) and pass them up\n const onCameraError = useCallback((error: any) => {\n console.warn(\"🎥 [Vision Camera Error Caught]:\", error);\n onError?.({ \n message: error.message || t('camera.errorOccurred'),\n code: error.code, // Contains specific RNVC codes (e.g., 'session/camera-in-use')\n name: error.name // Contains Web standard names (e.g., 'NotReadableError')\n });\n }, [onError, t]);\n\n const codeScanner = useCodeScanner({\n codeTypes: barcodeTypes || ['pdf-417', 'qr', 'code-128', 'code-39'],\n onCodeScanned: (codes) => {\n if (!isProcessingRef.current && isScanningBarcode) {\n for (const code of codes) {\n if (code.value && scannedBarcodeRef.current !== code.value) {\n scannedBarcodeRef.current = code.value;\n onBarcodeScanned?.(code.value);\n break;\n }\n }\n }\n }\n });\n\n const captureSilentPhoto = useCallback(async () => {\n if (!camera.current || !isInitialized || isProcessingRef.current || isCapturingRef.current) return;\n if (silentCaptureResult?.isAnalyzing) return;\n\n try {\n isCapturingRef.current = true;\n const photo = await camera.current.takePhoto({\n enableShutterSound: false,\n flash: 'off',\n\n ...(Platform.OS === 'ios' ? {\n photoCodec: 'jpeg', \n qualityPrioritization: 'speed', \n } : {})\n });\n \n const result = await VisionCameraModule.processPhotoResult(photo);\n onSilentCapture?.({ \n ...result, \n path: result.path || photo.path,\n barcode: scannedBarcodeRef.current \n });\n } catch {\n // Intentionally swallow silent capture errors so we don't spam the UI\n } finally {\n isCapturingRef.current = false;\n }\n }, [isInitialized, onSilentCapture, silentCaptureResult]);\n\n useEffect(() => {\n if (!showCamera || !isInitialized || isProcessing) return;\n let active = true;\n let id: ReturnType<typeof setInterval>;\n \n const timer = setTimeout(() => {\n if (!active) return;\n const intervalDelay = isScanningBarcode ? 3000 : 1500;\n id = setInterval(captureSilentPhoto, intervalDelay);\n }, 1500);\n\n return () => {\n active = false;\n clearTimeout(timer);\n if (id) clearInterval(id);\n };\n }, [showCamera, isInitialized, isProcessing, captureSilentPhoto, isScanningBarcode]);\n\n useEffect(() => {\n if (Platform.OS !== 'web' || !showCamera) return;\n \n let timeoutId: ReturnType<typeof setTimeout>;\n \n const findVideo = () => {\n let video: HTMLVideoElement | null = null;\n if (containerRef.current?.querySelector) {\n video = containerRef.current.querySelector('video');\n }\n if (!video) {\n video = document.querySelector('video');\n }\n \n if (video) {\n webVideoRef.current = video;\n setIsVideoFound(true);\n } else {\n timeoutId = setTimeout(findVideo, 500);\n }\n };\n \n findVideo();\n return () => clearTimeout(timeoutId);\n }, [showCamera]);\n\n const handleWebBarcodeScanned = useCallback((value: string) => {\n if (!isProcessingRef.current && value !== scannedBarcodeRef.current) {\n scannedBarcodeRef.current = value;\n onBarcodeScanned?.(value);\n }\n }, [onBarcodeScanned]);\n\n if (hasPermission === null) return <View style={[styles.container, style]} />;\n \n if (hasPermission === false) return (\n <View style={[styles.container, style]}>\n <Text style={styles.permissionMessage}>{t('camera.permissionRequired')}</Text>\n </View>\n );\n\n if (!device && showCamera) {\n // We delay the missing device error slightly to account for the camera mounting delay\n setTimeout(() => {\n if (!device) {\n onError?.({ \n message: \"No camera detected\", \n name: \"NotFoundError\", \n code: \"device/not-found\" \n });\n }\n }, 1000);\n return <View style={[styles.container, style]} />;\n }\n\n if (!device || !showCamera) return <View style={[styles.container, style]} />;\n\n return (\n <View ref={containerRef} style={[styles.container, style]}>\n <Camera\n ref={camera}\n style={StyleSheet.absoluteFill}\n device={device}\n resizeMode=\"cover\"\n isActive={showCamera && !isProcessing}\n photo={true}\n video={false}\n audio={false}\n onInitialized={onInitialized}\n onError={onCameraError}\n codeScanner={Platform.OS !== 'web' && isScanningBarcode ? codeScanner : undefined}\n />\n {Platform.OS === 'web' && isScanningBarcode && isVideoFound && (\n <WebBarcodeScanner\n videoRef={webVideoRef as React.RefObject<HTMLVideoElement>}\n onBarcodeScanned={handleWebBarcodeScanned}\n active={!isProcessingRef.current}\n />\n )}\n {overlayComponent}\n </View>\n );\n};\n\nconst styles = StyleSheet.create({\n container: { flex: 1, backgroundColor: 'black' },\n permissionMessage: { color: 'white', textAlign: 'center', margin: 20, fontSize: 16 },\n});"]}
|
|
1
|
+
{"version":3,"file":"EnhancedCameraView.js","sourceRoot":"","sources":["../../../src/components/EnhancedCameraView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACxE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAkB,MAAM,cAAc,CAAC;AAC1F,OAAO,EAAE,MAAM,EAAY,eAAe,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC/F,OAAO,kBAAkB,MAAM,sCAAsC,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AASxD,MAAM,CAAC,MAAM,kBAAkB,GAAkC,CAAC,EAChE,UAAU,EACV,UAAU,EAAE,iBAAiB,GAAG,OAAO,EACvC,KAAK,EACL,OAAO,EACP,eAAe,EACf,mBAAmB,EACnB,YAAY,GAAG,KAAK,EACpB,gBAAgB,EAChB,iBAAiB,GAAG,KAAK,EACzB,gBAAgB,EAChB,YAAY,EACb,EAAE,EAA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ACH,CACD;MAAA,CAAC,gBAAgB,CACnB;IAAA,EAAE,IAAI,CAAC,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IAC/B,SAAS,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,eAAe,EAAE,OAAO,EAAE;IAChD,iBAAiB,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE;CACrF,CAAC,CAAC","sourcesContent":["import React, { useCallback, useEffect, useRef, useState } from 'react';\nimport { View, StyleSheet, Text, Platform, AppState, AppStateStatus } from 'react-native';\nimport { Camera, CodeType, useCameraDevice, useCodeScanner } from 'react-native-vision-camera';\nimport VisionCameraModule from '../modules/camera/VisionCameraModule';\nimport { useI18n } from '../hooks/useI18n';\nimport { EnhancedCameraViewProps } from './OverLay/type';\nimport { WebBarcodeScanner } from './WebBarcodeScanner';\n\nexport interface ExtendedCameraProps extends Omit<EnhancedCameraViewProps, 'onError'> {\n isScanningBarcode?: boolean;\n onBarcodeScanned?: (data: string) => void;\n barcodeTypes?: CodeType[];\n onError?: (error: { message: string; name?: string; code?: string }) => void; \n}\n\nexport const EnhancedCameraView: React.FC<ExtendedCameraProps> = ({\n showCamera,\n cameraType: initialCameraType = 'front',\n style,\n onError,\n onSilentCapture,\n silentCaptureResult,\n isProcessing = false,\n overlayComponent,\n isScanningBarcode = false,\n onBarcodeScanned,\n barcodeTypes\n}) => {\n const { t } = useI18n();\n const camera = useRef<Camera>(null);\n const webVideoRef = useRef<HTMLVideoElement | null>(null);\n \n const isCapturingRef = useRef(false);\n const isProcessingRef = useRef(isProcessing);\n // Ref-tracked isAnalyzing so captureSilentPhoto always reads the latest\n // value — the prop-based closure goes stale on iOS between renders.\n const isAnalyzingRef = useRef(silentCaptureResult?.isAnalyzing ?? false);\n \n const [cameraType] = useState<'front' | 'back'>(initialCameraType);\n const [hasPermission, setHasPermission] = useState<boolean | null>(null);\n const [isInitialized, setIsInitialized] = useState(false);\n const [refreshCamera] = useState(false);\n \n const [isVideoFound, setIsVideoFound] = useState(false);\n const scannedBarcodeRef = useRef<string | null>(null);\n const containerRef = useRef<any>(null);\n\n const [appState, setAppState] = useState<AppStateStatus>(AppState.currentState);\n\n const device = useCameraDevice(cameraType);\n\n useEffect(() => { isProcessingRef.current = isProcessing; }, [isProcessing]);\n useEffect(() => { isAnalyzingRef.current = silentCaptureResult?.isAnalyzing ?? false; }, [silentCaptureResult?.isAnalyzing]);\n\n useEffect(() => {\n const subscription = AppState.addEventListener('change', nextAppState => {\n setAppState(nextAppState);\n });\n return () => {\n subscription.remove();\n };\n }, []);\n\n const checkPermissions = async () => {\n try {\n // getCameraPermissionStatus is synchronous — no await\n const cameraStatus = Camera.getCameraPermissionStatus();\n\n if (cameraStatus === 'granted') {\n setHasPermission(true);\n return;\n }\n\n if (cameraStatus === 'not-determined') {\n const result = await Camera.requestCameraPermission();\n if (result === 'granted') {\n setHasPermission(true);\n return;\n }\n }\n\n // 'denied' or 'restricted' — user must enable in Settings\n setHasPermission(false);\n onError?.({\n message: t('camera.permissionRequired'),\n name: 'NotAllowedError',\n code: 'permission-denied'\n });\n } catch (e: any) {\n setHasPermission(false);\n onError?.({\n message: e.message || t('camera.errorOccurred'),\n name: e.name || 'UnknownError',\n code: e.code || 'unknown'\n });\n }\n };\n\n useEffect(() => {\n if (showCamera) checkPermissions();\n }, [showCamera, refreshCamera]);\n\n const onInitialized = useCallback(() => setIsInitialized(true), []);\n\n const onCameraError = useCallback((error: any) => {\n console.warn(\"🎥 [Vision Camera Error Caught]:\", error);\n onError?.({ \n message: error.message || t('camera.errorOccurred'),\n code: error.code, // Contains specific RNVC codes (e.g., 'session/camera-in-use')\n name: error.name // Contains Web standard names (e.g., 'NotReadableError')\n });\n }, [onError, t]);\n\n const codeScanner = useCodeScanner({\n codeTypes: barcodeTypes || ['pdf-417', 'qr', 'code-128', 'code-39'],\n onCodeScanned: (codes) => {\n if (!isProcessingRef.current && isScanningBarcode) {\n for (const code of codes) {\n if (code.value && scannedBarcodeRef.current !== code.value) {\n scannedBarcodeRef.current = code.value;\n onBarcodeScanned?.(code.value);\n break;\n }\n }\n }\n }\n });\n\n const captureSilentPhoto = useCallback(async () => {\n if (!camera.current || !isInitialized || isProcessingRef.current || isCapturingRef.current) return;\n if (isAnalyzingRef.current) return;\n\n try {\n isCapturingRef.current = true;\n const photo = await camera.current.takePhoto({\n enableShutterSound: false,\n flash: 'off',\n\n ...(Platform.OS === 'ios' ? {\n photoCodec: 'jpeg', \n qualityPrioritization: 'speed', \n } : {})\n });\n const result = await VisionCameraModule.processPhotoResult(photo);\n onSilentCapture?.({ \n ...result, \n path: result.path || photo.path,\n barcode: scannedBarcodeRef.current \n });\n } catch (error: any) { \n console.log('Silent capture skipped/failed:', error?.message);\n } finally {\n isCapturingRef.current = false;\n }\n }, [isInitialized, onSilentCapture, silentCaptureResult]);\n\n useEffect(() => {\n if (!showCamera || !isInitialized || isProcessing) return;\n let active = true;\n let id: ReturnType<typeof setInterval>;\n \n const timer = setTimeout(() => {\n if (!active) return;\n const intervalDelay = isScanningBarcode ? 3000 : 1500;\n id = setInterval(captureSilentPhoto, intervalDelay);\n }, 1500);\n\n return () => {\n active = false;\n clearTimeout(timer);\n if (id) clearInterval(id);\n };\n }, [showCamera, isInitialized, isProcessing, captureSilentPhoto, isScanningBarcode]);\n\n useEffect(() => {\n if (Platform.OS !== 'web' || !showCamera) return;\n \n let timeoutId: ReturnType<typeof setTimeout>;\n \n const findVideo = () => {\n let video: HTMLVideoElement | null = null;\n if (containerRef.current?.querySelector) {\n video = containerRef.current.querySelector('video');\n }\n if (!video) {\n video = document.querySelector('video');\n }\n \n if (video) {\n webVideoRef.current = video;\n setIsVideoFound(true);\n } else {\n timeoutId = setTimeout(findVideo, 500);\n }\n };\n \n findVideo();\n return () => clearTimeout(timeoutId);\n }, [showCamera]);\n\n const handleWebBarcodeScanned = useCallback((value: string) => {\n if (!isProcessingRef.current && value !== scannedBarcodeRef.current) {\n scannedBarcodeRef.current = value;\n onBarcodeScanned?.(value);\n }\n }, [onBarcodeScanned]);\n\n if (hasPermission === null) return <View style={[styles.container, style]} />;\n \n if (hasPermission === false) return (\n <View style={[styles.container, style]}>\n <Text style={styles.permissionMessage}>{t('camera.permissionRequired')}</Text>\n </View>\n );\n\n if (!device && showCamera) {\n // We delay the missing device error slightly to account for the camera mounting delay\n setTimeout(() => {\n if (!device) {\n onError?.({ \n message: \"No camera detected\", \n name: \"NotFoundError\", \n code: \"device/not-found\" \n });\n }\n }, 1000);\n return <View style={[styles.container, style]} />;\n }\n\n if (!device || !showCamera) return <View style={[styles.container, style]} />;\n\n return (\n <View ref={containerRef} style={[styles.container, style]}>\n <Camera\n ref={camera}\n style={StyleSheet.absoluteFill}\n device={device}\n resizeMode=\"cover\"\n isActive={showCamera && !isProcessing && appState === 'active'}\n photo={true}\n video={false}\n audio={false}\n onInitialized={onInitialized}\n onError={onCameraError}\n codeScanner={Platform.OS !== 'web' && isScanningBarcode ? codeScanner : undefined}\n />\n {Platform.OS === 'web' && isScanningBarcode && isVideoFound && (\n <WebBarcodeScanner\n videoRef={webVideoRef as React.RefObject<HTMLVideoElement>}\n onBarcodeScanned={handleWebBarcodeScanned}\n active={!isProcessingRef.current}\n />\n )}\n {overlayComponent}\n </View>\n );\n};\n\nconst styles = StyleSheet.create({\n container: { flex: 1, backgroundColor: 'black' },\n permissionMessage: { color: 'white', textAlign: 'center', margin: 20, fontSize: 16 },\n});"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IDCardCapture.d.ts","sourceRoot":"","sources":["../../../../src/components/KYCElements/IDCardCapture.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA+C,MAAM,OAAO,CAAC;AAIpE,OAAO,EAAE,iBAAiB,EAAoI,MAAM,uBAAuB,CAAC;AAsB5L,UAAU,cAAc;IACtB,GAAG,EAAE,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K,CAAC,EAAE,CAAC,kBAAkB,CAsoCtD,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
-
import { View, Text, StyleSheet, Image, ScrollView, Platform, ActivityIndicator, TouchableOpacity, useWindowDimensions } from 'react-native';
|
|
2
|
+
import { View, Text, StyleSheet, Image, ScrollView, Platform, ActivityIndicator, TouchableOpacity, useWindowDimensions, Alert } from 'react-native';
|
|
3
3
|
import { showAlert } from '../../utils/platformAlert';
|
|
4
4
|
import { EnhancedCameraView } from '../EnhancedCameraView';
|
|
5
5
|
import { GovernmentDocumentTypeShorted, GovernmentDocumentTypeBackend } from '../../types/KYC.types';
|
|
@@ -70,6 +70,10 @@ export const IDCardCapture = ({ component, value = {}, onValueChange, error, lan
|
|
|
70
70
|
const [scanPhase, setScanPhase] = useState('image');
|
|
71
71
|
const [pendingCAImage, setPendingCAImage] = useState(null);
|
|
72
72
|
const scannedBarcodeRef = useRef(null);
|
|
73
|
+
// Ref mirrors — prevent stale closure reads in handleSilentCapture on iOS
|
|
74
|
+
const isAnalyzingRef = useRef(false);
|
|
75
|
+
const isProcessingCaptureRef = useRef(false);
|
|
76
|
+
const scanPhaseRef = useRef('image');
|
|
73
77
|
const [generatedCode, setGeneratedCode] = useState(null);
|
|
74
78
|
const [isGeneratingCode, setIsGeneratingCode] = useState(false);
|
|
75
79
|
const handleGenerateCode = async () => {
|
|
@@ -208,6 +212,10 @@ export const IDCardCapture = ({ component, value = {}, onValueChange, error, lan
|
|
|
208
212
|
}
|
|
209
213
|
}
|
|
210
214
|
}, [value, currentSide]);
|
|
215
|
+
// Keep refs in sync with state so handleSilentCapture always reads current values
|
|
216
|
+
useEffect(() => { isAnalyzingRef.current = silentCaptureResult.isAnalyzing ?? false; }, [silentCaptureResult.isAnalyzing]);
|
|
217
|
+
useEffect(() => { isProcessingCaptureRef.current = isProcessingCapture; }, [isProcessingCapture]);
|
|
218
|
+
useEffect(() => { scanPhaseRef.current = scanPhase; }, [scanPhase]);
|
|
211
219
|
const cameraConfig = useMemo(() => {
|
|
212
220
|
let instructions = selectedDocumentType
|
|
213
221
|
? (locale === 'en' ? getDocumentTypeInfo(selectedDocumentType.type).instructions.en : getDocumentTypeInfo(selectedDocumentType.type).instructions.fr)
|
|
@@ -355,7 +363,9 @@ export const IDCardCapture = ({ component, value = {}, onValueChange, error, lan
|
|
|
355
363
|
const base64 = await pathToBase64(safeCroppedPath);
|
|
356
364
|
const newImages = {
|
|
357
365
|
...capturedImages,
|
|
358
|
-
|
|
366
|
+
// Store safeCroppedPath (guaranteed file:// on iOS) as dir so
|
|
367
|
+
// Image source={{ uri }} never receives a bare path on iOS.
|
|
368
|
+
[currentSide]: { dir: safeCroppedPath, file: base64, mrz: verified.mrz || "", templatePath: verified.templatePath },
|
|
359
369
|
};
|
|
360
370
|
setCapturedImages(newImages);
|
|
361
371
|
if (verified.country && verified.documentType) {
|
|
@@ -466,11 +476,11 @@ export const IDCardCapture = ({ component, value = {}, onValueChange, error, lan
|
|
|
466
476
|
}
|
|
467
477
|
};
|
|
468
478
|
const handleSilentCapture = async (result) => {
|
|
469
|
-
if (
|
|
479
|
+
if (isProcessingCaptureRef.current)
|
|
470
480
|
return;
|
|
471
|
-
if (
|
|
481
|
+
if (scanPhaseRef.current === 'barcode')
|
|
472
482
|
return;
|
|
473
|
-
if (
|
|
483
|
+
if (isAnalyzingRef.current)
|
|
474
484
|
return;
|
|
475
485
|
if (result.success && result.path) {
|
|
476
486
|
setSilentCaptureResult((prev) => ({ ...prev, isAnalyzing: true, success: false, error: '' }));
|
|
@@ -482,11 +492,25 @@ export const IDCardCapture = ({ component, value = {}, onValueChange, error, lan
|
|
|
482
492
|
return;
|
|
483
493
|
}
|
|
484
494
|
const issuingSubdivision = selectedDocumentType.region !== 'root' ? selectedDocumentType.region : undefined;
|
|
495
|
+
const safeCapturePath = (Platform.OS === 'ios' && !result.path.startsWith('file://')) ? `file://${result.path}` : result.path;
|
|
496
|
+
// 🚨 WATCHDOG TIMER: If the iOS network drops and doesn't throw, this guarantees the UI unlocks after 20 seconds.
|
|
497
|
+
const watchdog = setTimeout(() => {
|
|
498
|
+
if (isAnalyzingRef.current) {
|
|
499
|
+
setSilentCaptureResult((prev) => ({
|
|
500
|
+
...prev,
|
|
501
|
+
isAnalyzing: false,
|
|
502
|
+
success: false,
|
|
503
|
+
error: state.currentLanguage === 'en' ? 'Connection timeout. Please try again.' : 'Délai de connexion dépassé. Veuillez réessayer.'
|
|
504
|
+
}));
|
|
505
|
+
Alert.alert(state.currentLanguage === 'en' ? "Timeout" : "Délai dépassé", state.currentLanguage === 'en'
|
|
506
|
+
? "The request took too long. Please verify your network and try again."
|
|
507
|
+
: "La requête a pris trop de temps. Veuillez vérifier votre connexion et réessayer.");
|
|
508
|
+
}
|
|
509
|
+
}, 20000);
|
|
485
510
|
try {
|
|
486
|
-
// 1. Check & Crop the Template visually first
|
|
487
511
|
if (!templatePath) {
|
|
488
512
|
const templateType = await checkTemplateType({
|
|
489
|
-
path:
|
|
513
|
+
path: safeCapturePath,
|
|
490
514
|
docType: selectedDocumentType?.type,
|
|
491
515
|
docRegion: countryData?.code || "",
|
|
492
516
|
postfix: currentSide,
|
|
@@ -498,11 +522,12 @@ export const IDCardCapture = ({ component, value = {}, onValueChange, error, lan
|
|
|
498
522
|
if (templateType.card_obb) {
|
|
499
523
|
const obbConfidence = getObbConfidence(templateType.card_obb);
|
|
500
524
|
if (obbConfidence !== null && obbConfidence < OBB_CONFIDENCE_THRESHOLD) {
|
|
525
|
+
clearTimeout(watchdog);
|
|
501
526
|
setSilentCaptureResult((prev) => ({ ...prev, isAnalyzing: false, success: false, error: t('kyc.idCardCapture.cardNotFullyInFrame') }));
|
|
502
527
|
return;
|
|
503
528
|
}
|
|
504
529
|
try {
|
|
505
|
-
const crop = await cropByObb(
|
|
530
|
+
const crop = await cropByObb(safeCapturePath, templateType.card_obb);
|
|
506
531
|
templateBbox = crop.bbox;
|
|
507
532
|
}
|
|
508
533
|
catch { }
|
|
@@ -515,25 +540,39 @@ export const IDCardCapture = ({ component, value = {}, onValueChange, error, lan
|
|
|
515
540
|
const matchedAuthMethod = getCorrespondingAuthMethod(templatePath, regionMappings.regionMapping, regionMappings.key || '', 'front');
|
|
516
541
|
const mrzType = getCorrespondingMrzType(templatePath, regionMappings.regionMapping, regionMappings.key || '') || 'TD1';
|
|
517
542
|
verificationRes = await frontVerification({
|
|
518
|
-
path:
|
|
519
|
-
regionMapping: {
|
|
543
|
+
path: safeCapturePath,
|
|
544
|
+
regionMapping: {
|
|
545
|
+
authMethod: matchedAuthMethod ? [matchedAuthMethod] : [],
|
|
546
|
+
mrzTypes: mrzType ? [mrzType] : []
|
|
547
|
+
},
|
|
520
548
|
selectedDocumentType: GovernmentDocumentTypeShorted[selectedDocumentType?.type] || '',
|
|
521
|
-
code: countryData?.code || '',
|
|
522
|
-
|
|
549
|
+
code: countryData?.code || '',
|
|
550
|
+
currentSide,
|
|
551
|
+
templatePath,
|
|
552
|
+
mrzType,
|
|
553
|
+
issuingSubdivision: issuingSubdivision,
|
|
554
|
+
clientSideBarcodeData: silentCaptureResult.barcode
|
|
523
555
|
}, env);
|
|
524
556
|
}
|
|
525
557
|
else {
|
|
526
|
-
logger.log("Attempting backVerification with:", { path:
|
|
558
|
+
logger.log("Attempting backVerification with:", { path: safeCapturePath, templatePath, side: currentSide });
|
|
527
559
|
const matchedBackAuthMethod = getCorrespondingAuthMethod(templatePath, regionMappings.regionMapping, regionMappings.key || '', 'back');
|
|
528
560
|
const backMrzType = getCorrespondingMrzType(templatePath, regionMappings.regionMapping, regionMappings.key || '') || '';
|
|
529
561
|
const frontTemplatePath = capturedImages['front']?.templatePath || '';
|
|
530
|
-
// This validates if the back matches the front template!
|
|
531
562
|
verificationRes = await backVerification({
|
|
532
|
-
path:
|
|
533
|
-
regionMapping: {
|
|
563
|
+
path: safeCapturePath,
|
|
564
|
+
regionMapping: {
|
|
565
|
+
authMethod: matchedBackAuthMethod ? [matchedBackAuthMethod] : [],
|
|
566
|
+
mrzTypes: backMrzType ? [backMrzType] : []
|
|
567
|
+
},
|
|
534
568
|
selectedDocumentType: GovernmentDocumentTypeShorted[selectedDocumentType.type] || '',
|
|
535
|
-
code: countryData?.code || '',
|
|
536
|
-
|
|
569
|
+
code: countryData?.code || '',
|
|
570
|
+
currentSide,
|
|
571
|
+
templatePath,
|
|
572
|
+
mrzType: backMrzType,
|
|
573
|
+
templateResponse,
|
|
574
|
+
issuingSubdivision: issuingSubdivision,
|
|
575
|
+
frontTemplatePath: frontTemplatePath
|
|
537
576
|
}, env);
|
|
538
577
|
}
|
|
539
578
|
const bbox = verificationRes?.bbox || templateBbox;
|
|
@@ -543,7 +582,6 @@ export const IDCardCapture = ({ component, value = {}, onValueChange, error, lan
|
|
|
543
582
|
const docTypeStr = selectedDocumentType.type;
|
|
544
583
|
const isHIC = docTypeStr === 'health_insurance_card';
|
|
545
584
|
const isValidScan = typeof barcodeData === 'string' && ((isHIC && barcodeData.length > 0) || barcodeData.length > 50);
|
|
546
|
-
// If the barcode was caught extremely fast in the same frame
|
|
547
585
|
if (isValidScan) {
|
|
548
586
|
logger.log('[CA Barcode] Image captured, verified & barcode ALREADY scanned! Skipping Phase 2.');
|
|
549
587
|
let parsedDictionary;
|
|
@@ -555,53 +593,67 @@ export const IDCardCapture = ({ component, value = {}, onValueChange, error, lan
|
|
|
555
593
|
parsedDictionary = await kycService.formatBarcodeData({ textInput: barcodeData, token }, env);
|
|
556
594
|
}
|
|
557
595
|
const verifiedResult = {
|
|
558
|
-
path:
|
|
596
|
+
path: safeCapturePath, templatePath: templatePath, bbox: bbox, success: true,
|
|
559
597
|
mrz: JSON.stringify(parsedDictionary), barcode: barcodeData, isAnalyzing: false,
|
|
560
598
|
country: countryData?.code, documentType: selectedDocumentType.type,
|
|
561
599
|
region: selectedDocumentType.region !== 'root' ? selectedDocumentType.region : undefined,
|
|
562
600
|
};
|
|
601
|
+
clearTimeout(watchdog);
|
|
563
602
|
setSilentCaptureResult(verifiedResult);
|
|
564
603
|
if (bbox) {
|
|
565
604
|
const safeBbox = bbox;
|
|
566
605
|
setBboxBySide(prev => ({ ...prev, ['back']: safeBbox }));
|
|
567
606
|
}
|
|
568
|
-
await autoCapture(
|
|
607
|
+
await autoCapture(safeCapturePath, verifiedResult);
|
|
569
608
|
return;
|
|
570
609
|
}
|
|
571
|
-
// If validation passed but we still need the barcode, trigger the UI phase!
|
|
572
610
|
logger.log('[CA Barcode] Image captured & template VERIFIED. Switching to Barcode phase.');
|
|
573
|
-
|
|
611
|
+
clearTimeout(watchdog);
|
|
612
|
+
setPendingCAImage({ path: safeCapturePath, templateResponse, templatePath, bbox });
|
|
574
613
|
setScanPhase('barcode');
|
|
575
614
|
setSilentCaptureResult(prev => ({ ...prev, isAnalyzing: false }));
|
|
576
615
|
return;
|
|
577
616
|
}
|
|
578
|
-
// 4. NORMAL COMPLETION (For standard MRZ / Passport / Non-barcode documents)
|
|
579
617
|
const verifiedResult = {
|
|
580
|
-
path:
|
|
581
|
-
country: countryData?.code, documentType: selectedDocumentType.type,
|
|
618
|
+
path: safeCapturePath, templatePath, bbox, success: true, mrz: verifiedMrz,
|
|
619
|
+
isAnalyzing: false, country: countryData?.code, documentType: selectedDocumentType.type,
|
|
620
|
+
region: issuingSubdivision
|
|
582
621
|
};
|
|
622
|
+
clearTimeout(watchdog);
|
|
583
623
|
setSilentCaptureResult(verifiedResult);
|
|
584
624
|
if (bbox)
|
|
585
625
|
setBboxBySide(prev => ({ ...prev, [currentSide]: bbox }));
|
|
586
|
-
await autoCapture(
|
|
626
|
+
await autoCapture(safeCapturePath, verifiedResult);
|
|
587
627
|
}
|
|
588
628
|
catch (error) {
|
|
629
|
+
clearTimeout(watchdog);
|
|
589
630
|
console.log("Backend Verification Error:", error);
|
|
590
|
-
const
|
|
631
|
+
const isNetworkError = !error.response ||
|
|
632
|
+
error.message === 'Network Error' ||
|
|
633
|
+
error.code === 'ECONNABORTED' ||
|
|
634
|
+
error.message?.includes('Network');
|
|
591
635
|
let userFriendlyMessage = 'Verification failed. Please try again.';
|
|
592
|
-
if (
|
|
593
|
-
userFriendlyMessage =
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
636
|
+
if (isNetworkError) {
|
|
637
|
+
userFriendlyMessage = state.currentLanguage === 'en'
|
|
638
|
+
? 'Cannot connect to verification server. Please check your internet connection.'
|
|
639
|
+
: 'Impossible de se connecter au serveur de vérification. Veuillez vérifier votre connexion internet.';
|
|
640
|
+
Alert.alert(state.currentLanguage === 'en' ? "Connection Failed" : "Échec de connexion", userFriendlyMessage);
|
|
597
641
|
}
|
|
598
|
-
else
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
642
|
+
else {
|
|
643
|
+
const rawMessage = (error?.message || '').toLowerCase();
|
|
644
|
+
if (rawMessage.includes('impossible') || rawMessage.includes('unreadable')) {
|
|
645
|
+
userFriendlyMessage = 'Document unreadable. Please hold the camera steady in good light.';
|
|
646
|
+
}
|
|
647
|
+
else if (rawMessage.includes('country mismatch') || rawMessage.includes('pays sélectionné')) {
|
|
648
|
+
userFriendlyMessage = 'The document does not match your selected country.';
|
|
649
|
+
}
|
|
650
|
+
else if (rawMessage.includes('card_not_fully_in_frame')) {
|
|
651
|
+
userFriendlyMessage = 'Move closer to the document and ensure all corners are visible.';
|
|
652
|
+
}
|
|
653
|
+
else if (rawMessage.includes('ne correspond pas au recto')) {
|
|
654
|
+
userFriendlyMessage = 'The back of the document does not match the front. You must scan the same ID.';
|
|
655
|
+
}
|
|
603
656
|
}
|
|
604
|
-
// The error is thrown here, completely blocking the switch to 'barcode' phase
|
|
605
657
|
setSilentCaptureResult(prev => ({ ...prev, isAnalyzing: false, success: false, error: userFriendlyMessage }));
|
|
606
658
|
}
|
|
607
659
|
}
|