From 1b307397b00e8df308eb129845c66e36afdd5352 Mon Sep 17 00:00:00 2001 From: Tomas Martykan Date: Mon, 3 Feb 2025 16:16:52 +0100 Subject: [PATCH] chore(suite-native): simplify connect popup deeplink callback --- .../src/hooks/useConnectPopupNavigation.ts | 39 ++++++------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/suite-native/module-connect-popup/src/hooks/useConnectPopupNavigation.ts b/suite-native/module-connect-popup/src/hooks/useConnectPopupNavigation.ts index 1e778613922..0f56e42a048 100644 --- a/suite-native/module-connect-popup/src/hooks/useConnectPopupNavigation.ts +++ b/suite-native/module-connect-popup/src/hooks/useConnectPopupNavigation.ts @@ -1,4 +1,4 @@ -import { useCallback, useEffect } from 'react'; +import { useEffect } from 'react'; import { useNavigation } from '@react-navigation/native'; import * as Linking from 'expo-linking'; @@ -34,33 +34,16 @@ export const useConnectPopupNavigation = () => { const featureFlagEnabled = useFeatureFlag(FeatureFlag.IsConnectPopupEnabled); const navigation = useNavigation(); - const navigateToConnectPopup = useCallback( - (url: string) => { - if (!featureFlagEnabled) return; - if (!isConnectPopupUrl(url)) return; - const parsedUrl = Linking.parse(url); - navigation.navigate(RootStackRoutes.ConnectPopup, { parsedUrl }); - }, - [navigation, featureFlagEnabled], - ); - - useEffect(() => { - const navigateToInitalUrl = async () => { - const currentUrl = await Linking.getInitialURL(); - if (currentUrl) { - navigateToConnectPopup(currentUrl); - } - }; - navigateToInitalUrl(); - }, [navigateToConnectPopup]); + const url = Linking.useURL(); useEffect(() => { - // there could be when you open same deep link for second time and in that case it will be ignored - // this could be probably handed by Linking.addEventListener - const subscription = Linking.addEventListener('url', event => { - navigateToConnectPopup(event.url); - }); - - return () => subscription?.remove(); - }, [navigateToConnectPopup]); + if (!featureFlagEnabled) return; + if (!url || !isConnectPopupUrl(url)) return; + try { + const parsedUrl = Linking.parse(url); + navigation.navigate(RootStackRoutes.ConnectPopup, { parsedUrl }); + } catch (error) { + console.warn('Invalid deeplink URL', { error, url }); + } + }, [url, navigation, featureFlagEnabled]); };