-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,691 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,65 @@ | ||
import * as amplitude from '@amplitude/analytics-react-native'; | ||
import { NativeModules, Platform } from 'react-native'; | ||
|
||
import useNavigationStore from '../stores/navigationStore'; | ||
import useUserStore from '../stores/userStore'; | ||
import { extractMRZInfo, formatDateToYYMMDD } from './utils'; | ||
|
||
export const startCameraScan = async () => { | ||
const { toast, setSelectedTab } = useNavigationStore.getState(); | ||
const { toast, setSelectedTab, trackEvent } = useNavigationStore.getState(); | ||
const startTime = Date.now(); | ||
|
||
trackEvent('Camera Launched'); | ||
|
||
if (Platform.OS === 'ios') { | ||
try { | ||
const result = await NativeModules.MRZScannerModule.startScanning(); | ||
console.log('Scan result:', result); | ||
console.log( | ||
`Document Number: ${result.documentNumber}, Expiry Date: ${result.expiryDate}, Birth Date: ${result.birthDate}`, | ||
); | ||
|
||
setSelectedTab('nfc'); | ||
trackEvent('Camera Success', { | ||
duration_ms: Date.now() - startTime, | ||
}); | ||
useUserStore.setState({ | ||
passportNumber: result.documentNumber, | ||
dateOfBirth: formatDateToYYMMDD(result.birthDate), | ||
dateOfExpiry: formatDateToYYMMDD(result.expiryDate), | ||
}); | ||
|
||
setSelectedTab('nfc'); | ||
toast.show('✔︎', { | ||
message: 'Scan successful', | ||
customData: { | ||
type: 'success', | ||
}, | ||
}); | ||
trackEvent('MRZ Success'); | ||
toast.show('✔︎', { message: 'Scan successful', customData: { type: 'success' } }); | ||
} catch (e) { | ||
console.error(e); | ||
amplitude.track('camera_scan_error', { error: e }); | ||
trackEvent('Camera Failed', { | ||
duration_ms: Date.now() - startTime, | ||
error: e?.toString(), | ||
}); | ||
} | ||
} else { | ||
NativeModules.CameraActivityModule.startCameraActivity() | ||
.then((mrzInfo: string) => { | ||
try { | ||
const { documentNumber, birthDate, expiryDate } = | ||
extractMRZInfo(mrzInfo); | ||
|
||
trackEvent('Camera Success', { | ||
duration_ms: Date.now() - startTime, | ||
}); | ||
const { documentNumber, birthDate, expiryDate } = extractMRZInfo(mrzInfo); | ||
useUserStore.setState({ | ||
passportNumber: documentNumber, | ||
dateOfBirth: birthDate, | ||
dateOfExpiry: expiryDate, | ||
}); | ||
|
||
setSelectedTab('nfc'); | ||
toast.show('✔︎', { | ||
message: 'Scan successful', | ||
customData: { | ||
type: 'success', | ||
}, | ||
}); | ||
trackEvent('MRZ Success'); | ||
toast.show('✔︎', { message: 'Scan successful', customData: { type: 'success' } }); | ||
} catch (error: any) { | ||
console.error('Invalid MRZ format:', error.message); | ||
amplitude.track('invalid_mrz_format', { error: error.message }); | ||
trackEvent('MRZ Error', { | ||
error: error.message, | ||
}); | ||
} | ||
}) | ||
.catch((error: any) => { | ||
console.error('Camera Activity Error:', error); | ||
amplitude.track('camera_scan_error', { error: error.message }); | ||
trackEvent('Camera Failed', { | ||
duration_ms: Date.now() - startTime, | ||
error: error.message, | ||
}); | ||
}); | ||
} | ||
}; |
Oops, something went wrong.