diff --git a/app/src/screens/prove/ConfirmBelongingScreen.tsx b/app/src/screens/prove/ConfirmBelongingScreen.tsx index 0dab5f525..390c98d02 100644 --- a/app/src/screens/prove/ConfirmBelongingScreen.tsx +++ b/app/src/screens/prove/ConfirmBelongingScreen.tsx @@ -6,6 +6,8 @@ import { ActivityIndicator, View } from 'react-native'; import type { StaticScreenProps } from '@react-navigation/native'; import { usePreventRemove } from '@react-navigation/native'; +import { useSelfClient } from '@selfxyz/mobile-sdk-alpha'; + import successAnimation from '@/assets/animations/loading/success.json'; import { PrimaryButton } from '@/components/buttons/PrimaryButton'; import Description from '@/components/typography/Description'; @@ -37,11 +39,11 @@ const ConfirmBelongingScreen: React.FC = () => { const setFcmToken = useProvingStore(state => state.setFcmToken); const setUserConfirmed = useProvingStore(state => state.setUserConfirmed); const isReadyToProve = currentState === 'ready_to_prove'; - + const selfClient = useSelfClient(); useEffect(() => { notificationSuccess(); - init('dsc'); - }, [init]); + init(selfClient, 'dsc'); + }, [init, selfClient]); const onOkPress = async () => { try { diff --git a/app/src/screens/prove/ProveScreen.tsx b/app/src/screens/prove/ProveScreen.tsx index 8259162fe..a4d20ffe8 100644 --- a/app/src/screens/prove/ProveScreen.tsx +++ b/app/src/screens/prove/ProveScreen.tsx @@ -20,6 +20,7 @@ import { Eye, EyeOff } from '@tamagui/lucide-icons'; import type { SelfAppDisclosureConfig } from '@selfxyz/common/utils/appType'; import { formatEndpoint } from '@selfxyz/common/utils/scope'; +import { useSelfClient } from '@selfxyz/mobile-sdk-alpha'; import miscAnimation from '@/assets/animations/loading/misc.json'; import { HeldPrimaryButtonProveScreen } from '@/components/buttons/HeldPrimaryButtonProveScreen'; @@ -56,7 +57,7 @@ const ProveScreen: React.FC = () => { () => scrollViewContentHeight <= scrollViewHeight, [scrollViewContentHeight, scrollViewHeight], ); - + const selfClient = useSelfClient(); const provingStore = useProvingStore(); const currentState = useProvingStore(state => state.currentState); const isReadyToProve = currentState === 'ready_to_prove'; @@ -94,10 +95,10 @@ const ProveScreen: React.FC = () => { setDefaultDocumentTypeIfNeeded(); if (selectedAppRef.current?.sessionId !== selectedApp.sessionId) { - provingStore.init('disclose'); + provingStore.init(selfClient, 'disclose'); } selectedAppRef.current = selectedApp; - }, [selectedApp, isFocused, provingStore]); + }, [selectedApp, isFocused, provingStore, selfClient]); const disclosureOptions = useMemo(() => { return (selectedApp?.disclosures as SelfAppDisclosureConfig) || []; diff --git a/app/src/utils/proving/provingMachine.ts b/app/src/utils/proving/provingMachine.ts index ac6234b91..1d79e392b 100644 --- a/app/src/utils/proving/provingMachine.ts +++ b/app/src/utils/proving/provingMachine.ts @@ -14,10 +14,14 @@ import { getCircuitNameFromPassportData, getSolidityPackedUserContextData, } from '@selfxyz/common/utils'; +import { SelfClient } from '@selfxyz/mobile-sdk-alpha'; import { PassportEvents, ProofEvents } from '@/consts/analytics'; +// import { navigationRef } from '@/navigation'; +// this will be pass as property of from selfClient import { unsafe_getPrivateKey } from '@/providers/authProvider'; +// will need to be passed in from selfClient import { clearPassportData, loadSelectedDocument, @@ -177,14 +181,15 @@ interface ProvingState { env: 'prod' | 'stg' | null; setFcmToken: (token: string) => void; init: ( + selfClient: SelfClient, circuitType: 'dsc' | 'disclose' | 'register', userConfirmed?: boolean, ) => Promise; startFetchingData: () => Promise; - validatingDocument: () => Promise; + validatingDocument: (selfClient: SelfClient) => Promise; initTeeConnection: () => Promise; startProving: () => Promise; - postProving: () => void; + postProving: (selfClient: SelfClient) => void; setUserConfirmed: () => void; _closeConnections: () => void; _generatePayload: () => Promise; @@ -202,7 +207,10 @@ interface ProvingState { export const useProvingStore = create((set, get) => { let actor: AnyActorRef | null = null; - function setupActorSubscriptions(newActor: AnyActorRef) { + function setupActorSubscriptions( + newActor: AnyActorRef, + selfClient: SelfClient, + ) { newActor.subscribe((state: StateFrom) => { console.log(`State transition: ${state.value}`); trackEvent(ProofEvents.PROVING_STATE_CHANGE, { state: state.value }); @@ -212,7 +220,7 @@ export const useProvingStore = create((set, get) => { get().startFetchingData(); } if (state.value === 'validating_document') { - get().validatingDocument(); + get().validatingDocument(selfClient); } if (state.value === 'init_tee_connexion') { @@ -224,7 +232,7 @@ export const useProvingStore = create((set, get) => { } if (state.value === 'post_proving') { - get().postProving(); + get().postProving(selfClient); } if ( get().circuitType !== 'disclose' && @@ -416,7 +424,6 @@ export const useProvingStore = create((set, get) => { try { // TODO: call hasAnyValidRegisteredDocument(selfClient) from @selfxyz/mobile-sdk-alpha const hasValid = await hasAnyValidRegisteredDocument(); - if (navigationRef.isReady()) { if (hasValid) { navigationRef.navigate('Home'); @@ -590,6 +597,7 @@ export const useProvingStore = create((set, get) => { }, init: async ( + selfClient: SelfClient, circuitType: 'dsc' | 'disclose' | 'register', userConfirmed: boolean = false, ) => { @@ -620,10 +628,11 @@ export const useProvingStore = create((set, get) => { }); actor = createActor(provingMachine); - setupActorSubscriptions(actor); + setupActorSubscriptions(actor, selfClient); actor.start(); trackEvent(ProofEvents.DOCUMENT_LOAD_STARTED); + // TODO call on self client const selectedDocument = await loadSelectedDocument(); if (!selectedDocument) { console.error('No document found for proving'); @@ -634,6 +643,7 @@ export const useProvingStore = create((set, get) => { const { data: passportData } = selectedDocument; + // TODO call on self client const secret = await unsafe_getPrivateKey(); if (!secret) { console.error('Could not load secret'); @@ -676,7 +686,7 @@ export const useProvingStore = create((set, get) => { } }, - validatingDocument: async () => { + validatingDocument: async (selfClient: SelfClient) => { _checkActorInitialized(actor); // TODO: for the disclosure, we could check that the selfApp is a valid one. trackEvent(ProofEvents.VALIDATION_STARTED); @@ -919,7 +929,7 @@ export const useProvingStore = create((set, get) => { } }, - postProving: () => { + postProving: (selfClient: SelfClient) => { _checkActorInitialized(actor); const { circuitType } = get(); trackEvent(ProofEvents.POST_PROVING_STARTED); @@ -929,7 +939,7 @@ export const useProvingStore = create((set, get) => { from: 'dsc', to: 'register', }); - get().init('register', true); + get().init(selfClient, 'register', true); }, 1500); } else if (circuitType === 'register') { trackEvent(ProofEvents.POST_PROVING_COMPLETED);