mirror of
https://github.com/selfxyz/self.git
synced 2026-04-05 03:00:53 -04:00
Fix/ios nfc scanning (#95)
This commit is contained in:
committed by
GitHub
parent
f5d0456193
commit
c166bd8496
@@ -31,10 +31,17 @@ class MRZScannerModule: NSObject, RCTBridgeModule {
|
||||
let lottieView = LottieView(animationFileName: "passport", loopMode: .loop)
|
||||
|
||||
scannerView.onScanResult = { scanResult in
|
||||
// Format dates to YYMMDD format
|
||||
let dateFormatter = DateFormatter()
|
||||
dateFormatter.dateFormat = "yyMMdd"
|
||||
|
||||
let birthDate = scanResult.birthdate.map { dateFormatter.string(from: $0) } ?? ""
|
||||
let expiryDate = scanResult.expiryDate.map { dateFormatter.string(from: $0) } ?? ""
|
||||
|
||||
let resultDict: [String: Any] = [
|
||||
"documentNumber": scanResult.documentNumber,
|
||||
"expiryDate": scanResult.expiryDate?.description ?? "",
|
||||
"birthDate": scanResult.birthdate?.description ?? ""
|
||||
"expiryDate": expiryDate,
|
||||
"birthDate": birthDate
|
||||
]
|
||||
resolve(resultDict)
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { useCallback } from 'react';
|
||||
import { StyleSheet } from 'react-native';
|
||||
import { Platform, StyleSheet } from 'react-native';
|
||||
|
||||
import { useIsFocused, useNavigation } from '@react-navigation/native';
|
||||
import LottieView from 'lottie-react-native';
|
||||
@@ -20,6 +20,7 @@ import Scan from '../../images/icons/passport_camera_scan.svg';
|
||||
import { ExpandableBottomLayout } from '../../layouts/ExpandableBottomLayout';
|
||||
import useUserStore from '../../stores/userStore';
|
||||
import { black, slate800, white } from '../../utils/colors';
|
||||
import { formatDateToYYMMDD } from '../../utils/utils';
|
||||
|
||||
interface PassportNFCScanScreen {}
|
||||
|
||||
@@ -27,16 +28,48 @@ const PassportCameraScreen: React.FC<PassportNFCScanScreen> = ({}) => {
|
||||
const navigation = useNavigation();
|
||||
const isFocused = useIsFocused();
|
||||
const store = useUserStore();
|
||||
|
||||
const onPassportRead = useCallback<PassportCameraProps['onPassportRead']>(
|
||||
(error, result) => {
|
||||
if (error) {
|
||||
// TODO: handle error better
|
||||
console.error(error);
|
||||
} else {
|
||||
const { passportNumber, dateOfBirth, dateOfExpiry } = result!;
|
||||
store.update({ passportNumber, dateOfBirth, dateOfExpiry });
|
||||
navigation.navigate('PassportNFCScan');
|
||||
//TODO: Add error handling here
|
||||
return;
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
console.error('No result from passport scan');
|
||||
return;
|
||||
}
|
||||
|
||||
const { passportNumber, dateOfBirth, dateOfExpiry } = result;
|
||||
|
||||
if (Platform.OS === 'ios') {
|
||||
store.update({
|
||||
passportNumber,
|
||||
dateOfBirth: formatDateToYYMMDD(dateOfBirth),
|
||||
dateOfExpiry: formatDateToYYMMDD(dateOfExpiry),
|
||||
});
|
||||
// Explicitly log the update
|
||||
console.log('Updated store with:', {
|
||||
passportNumber,
|
||||
dateOfBirth: formatDateToYYMMDD(dateOfBirth),
|
||||
dateOfExpiry: formatDateToYYMMDD(dateOfExpiry),
|
||||
});
|
||||
} else {
|
||||
store.update({
|
||||
passportNumber,
|
||||
dateOfBirth,
|
||||
dateOfExpiry,
|
||||
});
|
||||
// Explicitly log the update
|
||||
console.log('Updated store with:', {
|
||||
passportNumber,
|
||||
dateOfBirth,
|
||||
dateOfExpiry,
|
||||
});
|
||||
}
|
||||
navigation.navigate('PassportNFCScan');
|
||||
},
|
||||
[store, navigation],
|
||||
);
|
||||
|
||||
@@ -22,10 +22,16 @@ interface Inputs {
|
||||
|
||||
export const scan = async (inputs: Inputs) => {
|
||||
const { passportNumber, dateOfBirth, dateOfExpiry } = inputs;
|
||||
console.log('passportNumber', passportNumber);
|
||||
console.log('dateOfBirth', dateOfBirth);
|
||||
console.log('dateOfExpiry', dateOfExpiry);
|
||||
const check = checkInputs(passportNumber, dateOfBirth, dateOfExpiry);
|
||||
if (!check.success) {
|
||||
amplitude.track('inputs_invalid', { error: check.message });
|
||||
return;
|
||||
throw new Error(
|
||||
'Invalid inputs, please rescan the passport with the camera',
|
||||
); // TODO: toast message
|
||||
//useHapticNavigation('PassportCamera', 'cancel'); TODO: move user back to the previous screen
|
||||
}
|
||||
console.log('SCANNING');
|
||||
if (Platform.OS === 'android') {
|
||||
|
||||
Reference in New Issue
Block a user