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
8 changes: 4 additions & 4 deletions app/src/screens/document/DocumentCameraScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { Title } from '@/components/typography/Title';
import useHapticNavigation from '@/hooks/useHapticNavigation';
import Scan from '@/images/icons/passport_camera_scan.svg';
import { ExpandableBottomLayout } from '@/layouts/ExpandableBottomLayout';
import useUserStore from '@/stores/userStore';
import analytics from '@/utils/analytics';
import { black, slate400, slate800, white } from '@/utils/colors';
import { dinot } from '@/utils/fonts';
Expand All @@ -35,9 +34,10 @@ const { trackEvent } = analytics();

const DocumentCameraScreen: React.FC = () => {
const client = useSelfClient();
const { useMRZStore } = client;
const { setMRZForNFC } = useMRZStore();
const navigation = useNavigation();
const isFocused = useIsFocused();
const store = useUserStore();

// Add a ref to track when the camera screen is mounted
const scanStartTimeRef = useRef(Date.now());
Expand Down Expand Up @@ -102,7 +102,7 @@ const DocumentCameraScreen: React.FC = () => {
return;
}

store.update({
setMRZForNFC({
passportNumber: documentNumber,
dateOfBirth: formattedDateOfBirth,
dateOfExpiry: formattedDateOfExpiry,
Expand All @@ -116,7 +116,7 @@ const DocumentCameraScreen: React.FC = () => {

navigation.navigate('DocumentNFCScan');
},
[store, navigation],
[setMRZForNFC, navigation],
);
const navigateToLaunch = useHapticNavigation('Launch', {
action: 'cancel',
Expand Down
17 changes: 9 additions & 8 deletions app/src/screens/document/DocumentNFCMethodSelectionScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import { Platform, ScrollView } from 'react-native';
import { Input, YStack } from 'tamagui';
import { useNavigation } from '@react-navigation/native';

import { useSelfClient } from '@selfxyz/mobile-sdk-alpha';

import { PrimaryButton } from '@/components/buttons/PrimaryButton';
import { SecondaryButton } from '@/components/buttons/SecondaryButton';
import ButtonsContainer from '@/components/ButtonsContainer';
import { BodyText } from '@/components/typography/BodyText';
import Description from '@/components/typography/Description';
import { Title } from '@/components/typography/Title';
import { ExpandableBottomLayout } from '@/layouts/ExpandableBottomLayout';
import useUserStore from '@/stores/userStore';
import { white } from '@/utils/colors';

type NFCParams = {
Expand Down Expand Up @@ -93,26 +94,26 @@ const DocumentNFCMethodSelectionScreen: React.FC = () => {
const [selectedMethod, setSelectedMethod] = useState('standard');
const [canValue, setCanValue] = useState('');
const [error, setError] = useState('');
const updatePassport = useUserStore(state => state.update);
const passportNumber = useUserStore(state => state.passportNumber);
const dateOfBirth = useUserStore(state => state.dateOfBirth);
const dateOfExpiry = useUserStore(state => state.dateOfExpiry);

const selfClient = useSelfClient();
const { useMRZStore } = selfClient;
const { update, passportNumber, dateOfBirth, dateOfExpiry } = useMRZStore();

const handleSelect = (key: string) => {
setSelectedMethod(key);
setError('');
};

const onPassportNumberChange = (text: string) => {
updatePassport({ passportNumber: text });
update({ passportNumber: text });
};

const onDateOfBirthChange = (text: string) => {
updatePassport({ dateOfBirth: text });
update({ dateOfBirth: text });
};

const onDateOfExpiryChange = (text: string) => {
updatePassport({ dateOfExpiry: text });
update({ dateOfExpiry: text });
};

const handleProceed = () => {
Expand Down
7 changes: 4 additions & 3 deletions app/src/screens/document/DocumentNFCScanScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import { CircleHelp } from '@tamagui/lucide-icons';

import type { PassportData } from '@selfxyz/common/types';
import { getSKIPEM } from '@selfxyz/common/utils/csca';

Check warning on line 34 in app/src/screens/document/DocumentNFCScanScreen.tsx

View workflow job for this annotation

GitHub Actions / build-deps

'getSKIPEM' is defined but never used

Check warning on line 34 in app/src/screens/document/DocumentNFCScanScreen.tsx

View workflow job for this annotation

GitHub Actions / workspace-lint

'getSKIPEM' is defined but never used
import { initPassportDataParsing } from '@selfxyz/common/utils/passports';

Check warning on line 35 in app/src/screens/document/DocumentNFCScanScreen.tsx

View workflow job for this annotation

GitHub Actions / build-deps

'initPassportDataParsing' is defined but never used

Check warning on line 35 in app/src/screens/document/DocumentNFCScanScreen.tsx

View workflow job for this annotation

GitHub Actions / workspace-lint

'initPassportDataParsing' is defined but never used
import {
hasAnyValidRegisteredDocument,
useSelfClient,
Expand All @@ -53,8 +53,8 @@
import { useFeedback } from '@/providers/feedbackProvider';
import { storePassportData } from '@/providers/passportDataProvider';
import { logNFCEvent } from '@/Sentry';
import useUserStore from '@/stores/userStore';
import {
configureNfcAnalytics,
flushAllAnalytics,
setNfcScanningActive,
trackNfcEvent,
Expand Down Expand Up @@ -92,7 +92,7 @@

const DocumentNFCScanScreen: React.FC = () => {
const selfClient = useSelfClient();
const { trackEvent } = selfClient;
const { trackEvent, useMRZStore } = selfClient;

const navigation = useNavigation();
const route = useRoute<DocumentNFCScanRoute>();
Expand All @@ -104,7 +104,7 @@
dateOfExpiry,
documentType,
countryCode,
} = useUserStore();
} = useMRZStore();

const [isNfcSupported, setIsNfcSupported] = useState(true);
const [isNfcEnabled, setIsNfcEnabled] = useState(true);
Expand Down Expand Up @@ -324,6 +324,7 @@
const { canNumber, useCan, skipPACE, skipCA, extendedMode } =
route.params ?? {};

await configureNfcAnalytics();
const scanResponse = await scan({
passportNumber,
dateOfBirth,
Expand Down
21 changes: 0 additions & 21 deletions app/src/stores/userStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,17 @@
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.

import { create } from 'zustand';
import { DEFAULT_DOB, DEFAULT_DOE, DEFAULT_PNUMBER } from '@env';

import type { IdDocInput } from '@selfxyz/common/utils';

interface UserState {
documentType: string;
countryCode: string;
passportNumber: string;
dateOfBirth: string;
dateOfExpiry: string;
deepLinkName?: string;
deepLinkSurname?: string;
deepLinkNationality?: IdDocInput['nationality'];
deepLinkBirthDate?: string;
deepLinkGender?: string;
idDetailsDocumentId?: string;
update: (patch: Partial<UserState>) => void;
deleteMrzFields: () => void;
setIdDetailsDocumentId: (documentId: string) => void;
setDeepLinkUserDetails: (details: {
name?: string;
Expand All @@ -33,11 +26,6 @@ interface UserState {
}

const useUserStore = create<UserState>((set, _get) => ({
passportNumber: DEFAULT_PNUMBER ?? '',
documentType: '',
countryCode: '',
dateOfBirth: DEFAULT_DOB ?? '',
dateOfExpiry: DEFAULT_DOE ?? '',
deepLinkName: undefined,
deepLinkSurname: undefined,
deepLinkNationality: undefined,
Expand All @@ -49,15 +37,6 @@ const useUserStore = create<UserState>((set, _get) => ({
set(state => ({ ...state, ...patch }));
},

deleteMrzFields: () =>
set({
documentType: '',
passportNumber: '',
countryCode: '',
dateOfBirth: '',
dateOfExpiry: '',
}),

setDeepLinkUserDetails: details =>
set({
deepLinkName: details.name,
Expand Down
2 changes: 0 additions & 2 deletions app/src/utils/nfcScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ export const parseScanResponse = (response: unknown) => {
};

export const scan = async (inputs: Inputs) => {
await configureNfcAnalytics();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is now called before calling scan as preparation to move the code over to the SDK


const baseContext = {
sessionId: inputs.sessionId,
userId: inputs.userId,
Expand Down
2 changes: 0 additions & 2 deletions app/tests/utils/nfcScanner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,6 @@ describe('scan', () => {

await scan(mockInputs);

// Should configure analytics before scanning
expect(mockConfigureNfcAnalytics).toHaveBeenCalled();
expect(mockScanPassport).toHaveBeenCalled();
});
});
Expand Down
5 changes: 5 additions & 0 deletions packages/mobile-sdk-alpha/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { notImplemented } from './errors';
import { extractMRZInfo as parseMRZInfo } from './processing/mrz';
import { ProofContext } from './proving/internal/logging';
import { useProvingStore } from './proving/provingMachine';
import { useMRZStore } from './stores/mrzStore';
import { useProtocolStore } from './stores/protocolStore';
import { useSelfAppStore } from './stores/selfAppStore';
import { SDKEvent, SDKEventMap, SdkEvents } from './types/events';
Expand Down Expand Up @@ -180,10 +181,14 @@ export function createSelfClient({
getProtocolState: () => {
return useProtocolStore.getState();
},
getMRZState: () => {
return useMRZStore.getState();
},

// for reactivity (if needed)
useProvingStore,
useSelfAppStore,
useProtocolStore,
useMRZStore,
};
}
60 changes: 60 additions & 0 deletions packages/mobile-sdk-alpha/src/stores/mrzStore.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-FileCopyrightText: 2025 Social Connect Labs, Inc.
// SPDX-License-Identifier: BUSL-1.1
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.

import { create } from 'zustand';

export interface MRZState {
// Fields needed for NFC scanning
passportNumber: string;
dateOfBirth: string;
dateOfExpiry: string;
countryCode: string;
documentType: string;

// Store actions
setMRZForNFC: (data: {
passportNumber: string;
dateOfBirth: string;
dateOfExpiry: string;
countryCode: string;
documentType: string;
}) => void;
clearMRZ: () => void;
update: (patch: Partial<MRZState>) => void;
}

// TODO: what about the defaults from @env?
const initialState = {
passportNumber: '',
dateOfBirth: '',
dateOfExpiry: '',
countryCode: '',
documentType: '',
};

/*
Never export outside of the mobile sdk. It can cause multiple instances of the store to be created.
interact with the store thru the self client
*/
export const useMRZStore = create<MRZState>(set => ({
...initialState,

setMRZForNFC: data => {
set({
passportNumber: data.passportNumber,
dateOfBirth: data.dateOfBirth,
dateOfExpiry: data.dateOfExpiry,
countryCode: data.countryCode,
documentType: data.documentType,
});
},

clearMRZ: () => {
set(initialState);
},

update: (patch: Partial<MRZState>) => {
set(state => ({ ...state, ...patch }));
},
}));
3 changes: 3 additions & 0 deletions packages/mobile-sdk-alpha/src/types/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { DocumentCatalog, IDDocument, PassportData } from '@selfxyz/common'

import type { ProofContext } from '../proving/internal/logging';
import { ProvingState } from '../proving/provingMachine';
import { MRZState } from '../stores/mrzStore';
import { ProtocolState } from '../stores/protocolStore';
import { SelfAppState } from '../stores/selfAppStore';
import { SDKEvent, SDKEventMap } from './events';
Expand Down Expand Up @@ -183,10 +184,12 @@ export interface SelfClient {
getProvingState: () => ProvingState;
getSelfAppState: () => SelfAppState;
getProtocolState: () => ProtocolState;
getMRZState: () => MRZState;

useProvingStore: ReturnType<typeof create<ProvingState, []>>;
useSelfAppStore: ReturnType<typeof create<SelfAppState, []>>;
useProtocolStore: ReturnType<typeof create<ProtocolState, []>>;
useMRZStore: ReturnType<typeof create<MRZState, []>>;
}
export type Unsubscribe = () => void;
export interface StorageAdapter {
Expand Down
Loading