diff --git a/app/src/screens/MockDataScreen.tsx b/app/src/screens/MockDataScreen.tsx index 7c965f4b..f3ef057b 100644 --- a/app/src/screens/MockDataScreen.tsx +++ b/app/src/screens/MockDataScreen.tsx @@ -20,6 +20,7 @@ import CustomButton from '../components/CustomButton'; import useNavigationStore from '../stores/navigationStore'; import useUserStore from '../stores/userStore'; import { borderColor, textBlack } from '../utils/colors'; +import { parsePassportData } from '../../../common/src/utils/parsePassportData'; interface MockDataScreenProps { onCountryPress: () => void; @@ -70,7 +71,7 @@ const MockDataScreen: React.FC = ({ selectedAlgorithm == 'rsa sha1' ? 'sha1' : 'sha256', selectedAlgorithm == 'rsa sha1' ? 'sha1' : 'sha256', signatureAlgorithmToStrictSignatureAlgorithm[ - selectedAlgorithm as keyof typeof signatureAlgorithmToStrictSignatureAlgorithm + selectedAlgorithm as keyof typeof signatureAlgorithmToStrictSignatureAlgorithm ], selectedCountry as keyof typeof countryCodes, castDate(-age), @@ -84,7 +85,7 @@ const MockDataScreen: React.FC = ({ selectedAlgorithm == 'rsa sha1' ? 'sha1' : 'sha256', selectedAlgorithm == 'rsa sha1' ? 'sha1' : 'sha256', signatureAlgorithmToStrictSignatureAlgorithm[ - selectedAlgorithm as keyof typeof signatureAlgorithmToStrictSignatureAlgorithm + selectedAlgorithm as keyof typeof signatureAlgorithmToStrictSignatureAlgorithm ], selectedCountry as keyof typeof countryCodes, castDate(-age), @@ -93,6 +94,8 @@ const MockDataScreen: React.FC = ({ ); } useUserStore.getState().registerPassportData(mockPassportData); + const parsedPassportData = parsePassportData(mockPassportData); + useUserStore.getState().setPassportMetadata(parsedPassportData); useUserStore.getState().setRegistered(true); resolve(null); }, 0), diff --git a/app/src/screens/NextScreen.tsx b/app/src/screens/NextScreen.tsx index 2bccf674..0f05b459 100644 --- a/app/src/screens/NextScreen.tsx +++ b/app/src/screens/NextScreen.tsx @@ -46,9 +46,9 @@ const NextScreen: React.FC = () => { h={height > 750 ? 190 : 130} borderRadius={height > 750 ? '$7' : '$6'} source={{ - uri: passportData.mockUser + uri: passportData?.mockUser ? USER_PROFILE - : passportData.photoBase64 ?? USER_PROFILE, + : passportData?.photoBase64 ?? USER_PROFILE, }} /> )} @@ -64,8 +64,8 @@ const NextScreen: React.FC = () => { }} > {hideData - ? maskString(getFirstName(passportData.mrz)) - : getFirstName(passportData.mrz)} + ? maskString(getFirstName(passportData?.mrz ?? '')) + : getFirstName(passportData?.mrz ?? '')} @@ -79,11 +79,11 @@ const NextScreen: React.FC = () => { .split(' ') .map((word: string) => word.charAt(0).toUpperCase() + word.slice(1)) .join(' '); - const mrzAttribute = passportData.mrz.slice( + const mrzAttribute = passportData?.mrz?.slice( indexes[0], indexes[1] + 1, ); - const mrzAttributeFormatted = formatAttribute(key_, mrzAttribute); + const mrzAttributeFormatted = formatAttribute(key_, mrzAttribute ?? ''); return (
diff --git a/app/src/stores/navigationStore.ts b/app/src/stores/navigationStore.ts index 441c9d55..99d7a663 100644 --- a/app/src/stores/navigationStore.ts +++ b/app/src/stores/navigationStore.ts @@ -26,7 +26,7 @@ interface NavigationState { } const useNavigationStore = create((set, get) => ({ - zkeyDownloadedPercentage: 100, + zkeyDownloadedPercentage: 0, setZkeyDownloadedPercentage: (percentage: number) => set({ zkeyDownloadedPercentage: percentage }), isZkeyDownloading: { diff --git a/app/src/stores/userStore.ts b/app/src/stores/userStore.ts index c0e62ab3..fee5396e 100644 --- a/app/src/stores/userStore.ts +++ b/app/src/stores/userStore.ts @@ -9,6 +9,7 @@ import { loadSecretOrCreateIt, storePassportData, } from '../utils/keychain'; +import { PassportMetadata } from '../../../common/src/utils/parsePassportData'; interface UserState { passportNumber: string; @@ -17,6 +18,7 @@ interface UserState { countryCode: string; registered: boolean; passportData: PassportData | null; + passportMetadata: PassportMetadata | null; secret: string; cscaProof: Proof | null; localProof: Proof | null; @@ -32,6 +34,7 @@ interface UserState { setRegistered: (registered: boolean) => void; setDscSecret: (dscSecret: string) => void; setUserLoaded: (userLoaded: boolean) => void; + setPassportMetadata: (passportMetadata: PassportMetadata) => void; proofVerificationResult: string; setProofVerificationResult: (proofVerificationResult: string) => void; } @@ -45,6 +48,7 @@ const useUserStore = create((set, get) => ({ dscSecret: null, registered: false, passportData: null, + passportMetadata: null, secret: '', cscaProof: null, localProof: null, @@ -57,6 +61,9 @@ const useUserStore = create((set, get) => ({ setUserLoaded: (userLoaded: boolean) => { set({ userLoaded }); }, + setPassportMetadata: (passportMetadata: PassportMetadata) => { + set({ passportMetadata }); + }, proofVerificationResult: 'null', setProofVerificationResult: (proofVerificationResult: string) => { set({ proofVerificationResult }); diff --git a/app/src/utils/nfcScanner.ts b/app/src/utils/nfcScanner.ts index 27437da1..4f8c1b8c 100644 --- a/app/src/utils/nfcScanner.ts +++ b/app/src/utils/nfcScanner.ts @@ -210,6 +210,7 @@ const handleResponseIOS = async ( mockUser: false, }; const parsedPassportData = parsePassportData(passportData); + useUserStore.getState().setPassportMetadata(parsedPassportData); amplitude.track('nfc_response_parsed', parsedPassportData); try { @@ -318,6 +319,7 @@ const handleResponseAndroid = async ( try { await useUserStore.getState().registerPassportData(passportData); + useUserStore.getState().setPassportMetadata(parsedPassportData); useNavigationStore.getState().setSelectedTab('next'); } catch (e: any) { console.log('error during parsing:', e); diff --git a/app/src/utils/qrCode.ts b/app/src/utils/qrCode.ts index 62df64a9..3b88165c 100644 --- a/app/src/utils/qrCode.ts +++ b/app/src/utils/qrCode.ts @@ -7,7 +7,6 @@ import { getCircuitNameOld } from '../../../common/src/utils/certificate_parsing import useNavigationStore from '../stores/navigationStore'; import useUserStore from '../stores/userStore'; import { downloadZkey } from './zkeyDownload'; -import { parsePassportData } from '../../../common/src/utils/parsePassportData'; const parseUrlParams = (url: string): Map => { const [, queryString] = url.split('?'); @@ -109,8 +108,8 @@ const handleQRCodeScan = ( setSelectedTab: any, ) => { try { - const passportData = useUserStore.getState().passportData; - if (passportData) { + const { passportData, passportMetadata } = useUserStore.getState(); + if (passportData && passportMetadata) { const decodedResult = atob(result); const uint8Array = new Uint8Array( decodedResult.split('').map(char => char.charCodeAt(0)), @@ -119,16 +118,15 @@ const handleQRCodeScan = ( const unpackedData = msgpack.decode(decompressedData); const openPassportApp: OpenPassportApp = unpackedData; setSelectedApp(openPassportApp); - const passportMetadata = parsePassportData(passportData); const circuitName = openPassportApp.mode === 'vc_and_disclose' ? 'vc_and_disclose' : getCircuitNameOld( - 'prove' as Mode, - passportMetadata.signatureAlgorithm, - passportMetadata.signedAttrHashFunction, - ); + 'prove' as Mode, + passportMetadata.signatureAlgorithm, + passportMetadata.signedAttrHashFunction, + ); downloadZkey(circuitName as any); setSelectedTab('prove'); diff --git a/app/src/utils/zkeyDownload.ts b/app/src/utils/zkeyDownload.ts index 18ab35bd..0ab271a0 100644 --- a/app/src/utils/zkeyDownload.ts +++ b/app/src/utils/zkeyDownload.ts @@ -198,8 +198,8 @@ export async function fetchZkeyAndDat(circuit: CircuitName) { console.log( 'zkey and dat download succeeded, took ' + - (Date.now() - startTime) / 1000 + - ' seconds', + (Date.now() - startTime) / 1000 + + ' seconds', ); await saveFileSize(circuit, 'zkey');