UNPKG

viettel-ekyc-sdk

Version:
149 lines 6.15 kB
/* eslint-disable react-native/no-inline-styles */ import React from 'react'; import { Dimensions, Image, StyleSheet, Text, TouchableOpacity, View, } from 'react-native'; import { Header } from '../components/Header'; import { SizedBox } from '../components/SizedBox'; import { OCR_FRONT_AND_BACK_TYPE, OCR_FULL } from '../constants/camera'; import navigator from '../navigation/navigator'; import { ocrIdCardPost } from '../utils/api'; import { getBase64FromUri } from '../utils/utils'; export const StepResultScreen = (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 { navigation } = props; const { type, imageList, headerComponent, showResultScreen, getResult } = params; const imageFile = imageList !== undefined ? imageList[imageList.length - 1] : null; const actionGetOcr = async () => { 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], }, headerComponent: () => { return (React.createElement(Header, { title: 'Thông tin giấy tờ', style: { backgroundColor: 'white', paddingVertical: 15 }, leftComponent: () => { return (React.createElement(View, null, React.createElement(Text, null, "Fuck"))); } })); }, }, }); } else { 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: null, }); } } else { console.log(cardInfoPost === null || cardInfoPost === void 0 ? void 0 : cardInfoPost.data); } }; const actionContinues = () => { if (imageList.length === 1 && (type === OCR_FRONT_AND_BACK_TYPE || type === OCR_FULL)) { navigation.replace('IdCardScreen', { params: { ...params, imageList, }, }); } else if (type !== OCR_FULL) { actionGetOcr(); } else { navigation.replace('FaceScreen', { params: { ...params, imageList, }, }); } }; return (React.createElement(View, { style: styles.container }, headerComponent !== undefined ? headerComponent() : null, headerComponent !== undefined ? (React.createElement(SizedBox, { width: 0, height: 20 })) : null, React.createElement(View, { style: styles.imageContainer }, React.createElement(Image, { source: { uri: imageFile }, style: styles.image, resizeMode: 'contain' }), React.createElement(SizedBox, { width: 0, height: 20 })), React.createElement(View, { style: styles.actionContainer }, React.createElement(TouchableOpacity, { onPress: () => { imageList.pop(); navigation.replace('IdCardScreen', { params: { ...params, imageList, }, }); }, style: styles.button }, React.createElement(Text, { style: styles.buttonText }, "Ch\u1EE5p l\u1EA1i")), React.createElement(TouchableOpacity, { onPress: async () => { actionContinues(); }, style: styles.button }, React.createElement(Text, { style: { ...styles.buttonText, fontWeight: 'bold', } }, "Ti\u1EBFp t\u1EE5c"))))); }; const styles = StyleSheet.create({ container: { flex: 1, position: 'relative', backgroundColor: 'white', flexDirection: 'column', justifyContent: 'center', alignContent: 'flex-start', alignItems: 'center', }, imageContainer: { width: Dimensions.get('screen').width, paddingHorizontal: 10, flexDirection: 'column', alignItems: 'center', justifyContent: 'center', }, image: { width: Dimensions.get('screen').width - 20, height: '100%', }, actionContainer: { position: 'absolute', bottom: 0, left: 0, right: 0, flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', alignContent: 'center', paddingHorizontal: 10, }, button: { paddingVertical: 20, paddingHorizontal: 40, }, buttonText: { fontSize: 20, letterSpacing: -0.41, color: '#007AFF', }, }); //# sourceMappingURL=StepResultScreen.js.map