fix deeplink implementation

This commit is contained in:
turnoffthiscomputer
2025-03-21 23:56:26 +01:00
parent 36a29c9a21
commit c4ec179012
4 changed files with 46 additions and 69 deletions

View File

@@ -42,9 +42,11 @@ import PassportDataInfoScreen from './screens/Settings/PassportDataInfoScreen';
import ShowRecoveryPhraseScreen from './screens/Settings/ShowRecoveryPhraseScreen';
import SettingsScreen from './screens/SettingsScreen';
import SplashScreen from './screens/SplashScreen';
import { ProofProvider } from './stores/proofProvider';
import { useApp } from './stores/appProvider';
import { useProofInfo } from './stores/proofProvider';
import analytics from './utils/analytics';
import { black, slate300, white } from './utils/colors';
import { setupUniversalLinkListenerInNavigation } from './utils/qrCodeNew';
const AppNavigation = createNativeStackNavigator({
initialRouteName: 'Splash',
@@ -349,11 +351,27 @@ const NavigationWithTracking = () => {
}
};
// Add these hooks to get access to the necessary functions
const { setSelectedApp, cleanSelfApp } = useProofInfo();
const { startAppListener } = useApp();
// Setup universal link handling at the navigation level
React.useEffect(() => {
const cleanup = setupUniversalLinkListenerInNavigation(
navigationRef,
setSelectedApp,
cleanSelfApp,
startAppListener,
);
return () => {
cleanup();
};
}, [setSelectedApp, cleanSelfApp, startAppListener]);
return (
<GestureHandlerRootView>
<ProofProvider>
<Navigation ref={navigationRef} onStateChange={trackScreen} />
</ProofProvider>
<Navigation ref={navigationRef} onStateChange={trackScreen} />
</GestureHandlerRootView>
);
};

View File

@@ -48,6 +48,7 @@ const LoadingScreen: React.FC<LoadingScreenProps> = ({}) => {
}, []);
useEffect(() => {
console.log('registrationStatus', registrationStatus);
if (registrationStatus === ProofStatusEnum.SUCCESS) {
setAnimationSource(successAnimation);
goToSuccessScreenWithDelay();

View File

@@ -8,10 +8,6 @@ import React, {
} from 'react';
import { SelfApp } from '../../../common/src/utils/appType';
import { navigationRef } from '../Navigation';
import { useApp } from '../stores/appProvider';
import { setupUniversalLinkListener } from '../utils/qrCodeNew';
import { usePassport } from './passportDataProvider';
export enum ProofStatusEnum {
PENDING = 'pending',
@@ -63,7 +59,6 @@ export let globalSetDisclosureStatus:
store to manage the proof verification process, including app the is requesting, intemidiate status and final result
*/
export function ProofProvider({ children }: PropsWithChildren<{}>) {
const { passportData, secret } = usePassport(false);
const [registrationStatus, setRegistrationStatus] = useState<ProofStatusEnum>(
ProofStatusEnum.PENDING,
);
@@ -75,8 +70,6 @@ export function ProofProvider({ children }: PropsWithChildren<{}>) {
defaults.selectedApp,
);
const { startAppListener } = useApp();
const setSelectedApp = useCallback((app: SelfApp) => {
if (!app || Object.keys(app).length === 0) {
return;
@@ -96,24 +89,6 @@ export function ProofProvider({ children }: PropsWithChildren<{}>) {
setDisclosureStatus(ProofStatusEnum.PENDING);
}, []);
const handleNavigateToProveScreen = useCallback(() => {
if (navigationRef.isReady()) {
navigationRef.navigate('ProveScreen');
} else {
console.log("Navigation not ready yet, couldn't navigate to ProveScreen");
}
}, []);
const handleNavigateToQRCodeTrouble = useCallback(() => {
if (navigationRef.isReady()) {
navigationRef.navigate('QRCodeTrouble');
} else {
console.log(
"Navigation not ready yet, couldn't navigate to QRCodeTrouble",
);
}
}, []);
useEffect(() => {
globalSetRegistrationStatus = setRegistrationStatus;
globalSetDisclosureStatus = setDisclosureStatus;
@@ -123,27 +98,6 @@ export function ProofProvider({ children }: PropsWithChildren<{}>) {
};
}, []);
useEffect(() => {
if (passportData && secret) {
const universalLinkCleanup = setupUniversalLinkListener(
setSelectedApp,
cleanSelfApp,
startAppListener,
handleNavigateToProveScreen,
handleNavigateToQRCodeTrouble,
);
return () => {
universalLinkCleanup();
};
}
}, [
setSelectedApp,
cleanSelfApp,
startAppListener,
handleNavigateToProveScreen,
handleNavigateToQRCodeTrouble,
]);
const publicApi: IProofContext = useMemo(
() => ({
registrationStatus,

View File

@@ -67,35 +67,39 @@ const handleQRCodeData = (
}
};
export const setupUniversalLinkListener = (
export const setupUniversalLinkListenerInNavigation = (
navigation: any,
setApp: (app: SelfApp) => void,
cleanSelfApp: () => void,
startAppListener: (sessionId: string, setApp: (app: SelfApp) => void) => void,
onNavigationNeeded?: () => void,
onErrorCallback?: () => void,
) => {
Linking.getInitialURL().then(url => {
if (url) {
handleQRCodeData(
url,
setApp,
cleanSelfApp,
startAppListener,
onNavigationNeeded,
onErrorCallback,
);
}
});
const linkingEventListener = Linking.addEventListener('url', ({ url }) => {
const handleNavigation = (url: string) => {
handleQRCodeData(
url,
setApp,
cleanSelfApp,
startAppListener,
onNavigationNeeded,
onErrorCallback,
() => {
if (navigation.isReady()) {
navigation.navigate('ProveScreen');
}
},
() => {
if (navigation.isReady()) {
navigation.navigate('QRCodeTrouble');
}
},
);
};
Linking.getInitialURL().then(url => {
if (url) {
handleNavigation(url);
}
});
const linkingEventListener = Linking.addEventListener('url', ({ url }) => {
handleNavigation(url);
});
return () => {