mirror of
https://github.com/selfxyz/self.git
synced 2026-04-05 03:00:53 -04:00
separate MRZ data from userStore (#1187)
This commit is contained in:
committed by
GitHub
parent
0c6a6cb2e6
commit
c1d30d153a
@@ -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';
|
||||
@@ -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());
|
||||
@@ -102,7 +102,7 @@ const DocumentCameraScreen: React.FC = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
store.update({
|
||||
setMRZForNFC({
|
||||
passportNumber: documentNumber,
|
||||
dateOfBirth: formattedDateOfBirth,
|
||||
dateOfExpiry: formattedDateOfExpiry,
|
||||
@@ -116,7 +116,7 @@ const DocumentCameraScreen: React.FC = () => {
|
||||
|
||||
navigation.navigate('DocumentNFCScan');
|
||||
},
|
||||
[store, navigation],
|
||||
[setMRZForNFC, navigation],
|
||||
);
|
||||
const navigateToLaunch = useHapticNavigation('Launch', {
|
||||
action: 'cancel',
|
||||
|
||||
@@ -7,6 +7,8 @@ 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';
|
||||
@@ -14,7 +16,6 @@ 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 = {
|
||||
@@ -93,10 +94,10 @@ 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);
|
||||
@@ -104,15 +105,15 @@ const DocumentNFCMethodSelectionScreen: React.FC = () => {
|
||||
};
|
||||
|
||||
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 = () => {
|
||||
|
||||
@@ -53,8 +53,8 @@ import { ExpandableBottomLayout } from '@/layouts/ExpandableBottomLayout';
|
||||
import { useFeedback } from '@/providers/feedbackProvider';
|
||||
import { storePassportData } from '@/providers/passportDataProvider';
|
||||
import { logNFCEvent } from '@/Sentry';
|
||||
import useUserStore from '@/stores/userStore';
|
||||
import {
|
||||
configureNfcAnalytics,
|
||||
flushAllAnalytics,
|
||||
setNfcScanningActive,
|
||||
trackNfcEvent,
|
||||
@@ -92,7 +92,7 @@ type DocumentNFCScanRoute = RouteProp<
|
||||
|
||||
const DocumentNFCScanScreen: React.FC = () => {
|
||||
const selfClient = useSelfClient();
|
||||
const { trackEvent } = selfClient;
|
||||
const { trackEvent, useMRZStore } = selfClient;
|
||||
|
||||
const navigation = useNavigation();
|
||||
const route = useRoute<DocumentNFCScanRoute>();
|
||||
@@ -104,7 +104,7 @@ const DocumentNFCScanScreen: React.FC = () => {
|
||||
dateOfExpiry,
|
||||
documentType,
|
||||
countryCode,
|
||||
} = useUserStore();
|
||||
} = useMRZStore();
|
||||
|
||||
const [isNfcSupported, setIsNfcSupported] = useState(true);
|
||||
const [isNfcEnabled, setIsNfcEnabled] = useState(true);
|
||||
@@ -324,6 +324,7 @@ const DocumentNFCScanScreen: React.FC = () => {
|
||||
const { canNumber, useCan, skipPACE, skipCA, extendedMode } =
|
||||
route.params ?? {};
|
||||
|
||||
await configureNfcAnalytics();
|
||||
const scanResponse = await scan({
|
||||
passportNumber,
|
||||
dateOfBirth,
|
||||
|
||||
@@ -3,16 +3,10 @@
|
||||
// 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'];
|
||||
@@ -20,7 +14,6 @@ interface UserState {
|
||||
deepLinkGender?: string;
|
||||
idDetailsDocumentId?: string;
|
||||
update: (patch: Partial<UserState>) => void;
|
||||
deleteMrzFields: () => void;
|
||||
setIdDetailsDocumentId: (documentId: string) => void;
|
||||
setDeepLinkUserDetails: (details: {
|
||||
name?: string;
|
||||
@@ -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,
|
||||
@@ -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,
|
||||
|
||||
@@ -52,8 +52,6 @@ export const parseScanResponse = (response: unknown) => {
|
||||
};
|
||||
|
||||
export const scan = async (inputs: Inputs) => {
|
||||
await configureNfcAnalytics();
|
||||
|
||||
const baseContext = {
|
||||
sessionId: inputs.sessionId,
|
||||
userId: inputs.userId,
|
||||
|
||||
Reference in New Issue
Block a user