UNPKG

viettel-ekyc-sdk

Version:
89 lines 5.2 kB
/* eslint-disable react-native/no-inline-styles */ import React, { useState } from 'react'; import { View } from 'react-native'; import { callToast, CustomeAlert } from '../components/CustomeAlert'; import { Header } from '../components/Header'; import { MashBackground } from '../components/MashBackground'; import navigator from '../navigation/navigator'; import { faceMatchingPost, ocrIdCardPost } from '../utils/api'; import { getBase64FromUri } from '../utils/utils'; import { FaceComponent } from './FaceComponent'; export const FaceScreen = (props) => { var _a; const params = navigator.getParam('params', (_a = props === null || props === void 0 ? void 0 : props.route) === null || _a === void 0 ? void 0 : _a.params); const { initialCamera, faceLivenessConfiguration, enableAutoCaptureFace, enableCheckSanity, enableCheckTempering, showResultScreen, getResult, imageList, } = params; const { navigation } = props; let imageFront = imageList !== undefined ? imageList[0] : null; const [errorMessage, setErrorMessage] = useState(''); const actionGetOcr = async (faceMatching) => { var _a, _b, _c; const imageFrontBase64 = await getBase64FromUri(imageList[0]); let cardInfoPost; if (imageList.length > 1) { const imageBackBase64 = await getBase64FromUri(imageList[1]); cardInfoPost = await ocrIdCardPost(imageFrontBase64, imageBackBase64); } else { cardInfoPost = await ocrIdCardPost(imageFrontBase64, null); } if (((_a = cardInfoPost === null || cardInfoPost === void 0 ? void 0 : cardInfoPost.data) === null || _a === void 0 ? void 0 : _a.code) === 1) { if (showResultScreen) { navigation.replace('ResultScreen', { params: { card: { ...(_b = cardInfoPost === null || cardInfoPost === void 0 ? void 0 : cardInfoPost.data) === null || _b === void 0 ? void 0 : _b.information, frontImage: imageList[0], backImage: imageList[1], }, faceMatching, headerComponent: () => { return React.createElement(Header, { title: 'Bước 3: Kết quả xác thực' }); }, }, }); } getResult({ cardInfo: { ...(_c = cardInfoPost === null || cardInfoPost === void 0 ? void 0 : cardInfoPost.data) === null || _c === void 0 ? void 0 : _c.information, frontImage: imageList[0], backImage: imageList[1], }, faceMatching: faceMatching, }); } else { console.log(cardInfoPost === null || cardInfoPost === void 0 ? void 0 : cardInfoPost.data); } }; return (React.createElement(View, { style: { flex: 1, position: 'relative' } }, React.createElement(FaceComponent, { initialCamera: initialCamera, faceLivenessConfiguration: faceLivenessConfiguration, warningFrame: null, afterTakePictureAction: async (response) => { var _a, _b, _c; if (response.errorMessage !== '') { setErrorMessage(response.errorMessage); callToast(() => { setErrorMessage(''); }); } else { if (response.images.length > 0) { const imageFrontBase64 = await getBase64FromUri(imageFront); const liveBase64 = await getBase64FromUri(response.images[0]); const faceMatchingResponse = await faceMatchingPost(imageFrontBase64, liveBase64); if (((_a = faceMatchingResponse === null || faceMatchingResponse === void 0 ? void 0 : faceMatchingResponse.data) === null || _a === void 0 ? void 0 : _a.code) === 1) { let faceMatching = { faceImage: response.images[0], isMatching: (_b = faceMatchingResponse === null || faceMatchingResponse === void 0 ? void 0 : faceMatchingResponse.data) === null || _b === void 0 ? void 0 : _b.verify_result, scoreMatching: (_c = faceMatchingResponse === null || faceMatchingResponse === void 0 ? void 0 : faceMatchingResponse.data) === null || _c === void 0 ? void 0 : _c.score, }; actionGetOcr(faceMatching); } else { console.log('Error: ', faceMatchingResponse.data); } } } }, enableFaceDetect: enableAutoCaptureFace, enableCheckSanity: enableCheckSanity, enableCheckTempering: enableCheckTempering }), errorMessage !== '' ? React.createElement(MashBackground, null) : null, React.createElement(CustomeAlert, { message: errorMessage }))); }; //# sourceMappingURL=FaceScreen.js.map