Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/src/navigation/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ const documentScreens = {
headerShown: false,
} as NativeStackNavigationOptions,
initialParams: {
passportData: null,
countryCode: null,
documentCategory: null,
},
},
DocumentNFCMethodSelection: {
Expand Down
5 changes: 3 additions & 2 deletions app/src/providers/selfClientProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,11 @@ export const SelfClientProvider = ({ children }: PropsWithChildren) => {

addListener(
SdkEvents.PROVING_PASSPORT_NOT_SUPPORTED,
({ passportData }) => {
({ countryCode, documentCategory }) => {
if (navigationRef.isReady()) {
navigationRef.navigate('UnsupportedDocument', {
passportData,
countryCode,
documentCategory,
} as any);
}
},
Expand Down
16 changes: 8 additions & 8 deletions app/src/screens/document/UnsupportedDocumentScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { XStack, YStack } from 'tamagui';
import type { RouteProp } from '@react-navigation/native';

import { countryCodes } from '@selfxyz/common/constants';
import type { PassportData } from '@selfxyz/common/types';
import type { DocumentCategory } from '@selfxyz/common/types';
import {
hasAnyValidRegisteredDocument,
useSelfClient,
Expand Down Expand Up @@ -39,7 +39,8 @@ type CountryFlagsRecord = Record<string, CountryFlagComponent>;
type UnsupportedDocumentScreenRouteProp = RouteProp<
{
UnsupportedDocument: {
passportData: PassportData | null;
countryCode: string | null;
documentCategory: DocumentCategory | null;
};
},
'UnsupportedDocument'
Expand All @@ -55,11 +56,10 @@ const UnsupportedDocumentScreen: React.FC<UnsupportedDocumentScreenProps> = ({
const selfClient = useSelfClient();
const navigateToLaunch = useHapticNavigation('Launch');
const navigateToHome = useHapticNavigation('Home');
const passportData = route.params?.passportData;

const { countryName, country2AlphaCode, documentTypeText } = useMemo(() => {
try {
const countryCode = passportData?.passportMetadata?.countryCode;
const countryCode = route.params?.countryCode;
if (countryCode) {
// Handle Germany corner case where country code is "D<<" instead of "DEU"
let normalizedCountryCode = countryCode;
Expand All @@ -74,7 +74,7 @@ const UnsupportedDocumentScreen: React.FC<UnsupportedDocumentScreenProps> = ({
const name =
countryCodes[normalizedCountryCode as keyof typeof countryCodes];
const docType =
passportData?.documentCategory === 'id_card'
route.params?.documentCategory === 'id_card'
? 'ID Cards'
: 'Passports';
return {
Expand All @@ -87,13 +87,13 @@ const UnsupportedDocumentScreen: React.FC<UnsupportedDocumentScreenProps> = ({
console.error('Error extracting country from passport data:', error);
}
const docType =
passportData?.documentCategory === 'id_card' ? 'ID Cards' : 'Passports';
route.params?.documentCategory === 'id_card' ? 'ID Cards' : 'Passports';
return {
countryName: 'Unknown',
country2AlphaCode: 'Unknown',
documentTypeText: docType,
};
}, [passportData]);
}, [route.params?.documentCategory, route.params?.countryCode]);

// Get country flag component dynamically
const getCountryFlag = (code: string) => {
Expand Down Expand Up @@ -127,7 +127,7 @@ const UnsupportedDocumentScreen: React.FC<UnsupportedDocumentScreenProps> = ({
countryName,
countryCode:
country2AlphaCode !== 'Unknown' ? country2AlphaCode : undefined,
documentCategory: passportData?.documentCategory,
documentCategory: route.params?.documentCategory ?? '',
});
} catch (error) {
console.error('Failed to open email client:', error);
Expand Down
7 changes: 6 additions & 1 deletion app/src/utils/proving/provingMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1096,8 +1096,13 @@ export const useProvingStore = create<ProvingState>((set, get) => {
},

_handlePassportNotSupported: (selfClient: SelfClient) => {
const passportData = get().passportData;
const countryCode = passportData?.passportMetadata?.countryCode;
const documentCategory = passportData?.documentCategory;

selfClient.emit(SdkEvents.PROVING_PASSPORT_NOT_SUPPORTED, {
passportData: get().passportData as PassportData,
countryCode: countryCode ?? null,
documentCategory: documentCategory ?? null,
});
},

Expand Down
31 changes: 30 additions & 1 deletion app/tests/utils/proving/provingMachine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,34 @@ describe('events', () => {
eContent: [1, 2, 3],
signedAttr: [1, 2, 3],
encryptedDigest: [1, 2, 3],
passportMetadata: {
countryCode: 'test',
},
documentCategory: 'passport',
} as PassportData;

const selfClient = {
emit: emitMock,
} as unknown as SelfClient;

await act(async () => {
useProvingStore.setState({ passportData: mockPassportData });
useProvingStore.getState()._handlePassportNotSupported(selfClient);
});

expect(emitMock).toHaveBeenCalledWith(
SdkEvents.PROVING_PASSPORT_NOT_SUPPORTED,
{
countryCode: 'test',
documentCategory: 'passport',
},
);
});

it('emits PROVING_MACHINE_PASSPORT_NOT_SUPPORTED with no passport data', async () => {
const emitMock = jest.fn();
const mockPassportData = {
passportMetadata: {},
} as PassportData;

const selfClient = {
Expand All @@ -81,7 +109,8 @@ describe('events', () => {
expect(emitMock).toHaveBeenCalledWith(
SdkEvents.PROVING_PASSPORT_NOT_SUPPORTED,
{
passportData: mockPassportData,
countryCode: null,
documentCategory: null,
},
);
});
Expand Down
7 changes: 5 additions & 2 deletions packages/mobile-sdk-alpha/src/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// SPDX-License-Identifier: BUSL-1.1
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.

import type { PassportData, Progress } from './public';
import { DocumentCategory } from '@selfxyz/common/types';

import type { Progress } from './public';

export enum SdkEvents {
ERROR = 'ERROR',
Expand All @@ -23,7 +25,8 @@ export interface SDKEventMap {
hasValidDocument: boolean;
};
[SdkEvents.PROVING_PASSPORT_NOT_SUPPORTED]: {
passportData: PassportData;
countryCode: string | null;
documentCategory: DocumentCategory | null;
};
[SdkEvents.PROVING_ACCOUNT_RECOVERY_REQUIRED]: undefined;

Expand Down
8 changes: 4 additions & 4 deletions packages/mobile-sdk-alpha/tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { describe, expect, it, vi } from 'vitest';

import type { CryptoAdapter, DocumentsAdapter, NetworkAdapter, ScannerAdapter } from '../src';
import { createListenersMap, createSelfClient, SdkEvents } from '../src/index';
import { AuthAdapter, PassportData } from '../src/types/public';
import { AuthAdapter } from '../src/types/public';

describe('createSelfClient', () => {
// Test eager validation during client creation
Expand Down Expand Up @@ -111,7 +111,7 @@ describe('createSelfClient', () => {
listeners: listeners.map,
});

client.emit(SdkEvents.PROVING_PASSPORT_NOT_SUPPORTED, { passportData: { mrz: 'test' } as PassportData });
client.emit(SdkEvents.PROVING_PASSPORT_NOT_SUPPORTED, { countryCode: 'test', documentCategory: 'passport' });
client.emit(SdkEvents.PROVING_ACCOUNT_RECOVERY_REQUIRED);
client.emit(SdkEvents.PROVING_REGISTER_ERROR_OR_FAILURE, { hasValidDocument: true });

Expand All @@ -120,10 +120,10 @@ describe('createSelfClient', () => {
expect(anotherAccountRecoveryChoiceListener).toHaveBeenCalledTimes(1);
expect(anotherAccountRecoveryChoiceListener).toHaveBeenCalledWith(undefined);

expect(passportNotSupportedListener).toHaveBeenCalledWith({ passportData: { mrz: 'test' } });
expect(passportNotSupportedListener).toHaveBeenCalledWith({ countryCode: 'test', documentCategory: 'passport' });
expect(passportNotSupportedListener).toHaveBeenCalledTimes(1);

client.emit(SdkEvents.PROVING_PASSPORT_NOT_SUPPORTED, { passportData: { mrz: 'test' } as PassportData });
client.emit(SdkEvents.PROVING_PASSPORT_NOT_SUPPORTED, { countryCode: 'test', documentCategory: 'passport' });
client.emit(SdkEvents.PROVING_ACCOUNT_RECOVERY_REQUIRED);
client.emit(SdkEvents.PROVING_REGISTER_ERROR_OR_FAILURE, { hasValidDocument: true });

Expand Down
Loading