From 006a0f51f367566e5b1edd2634385b7d837faffb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20M=C3=B3rawski?= Date: Mon, 16 Oct 2023 17:46:43 +0200 Subject: [PATCH] dl desktop error fix --- src/libs/Navigation/Navigation.js | 35 +++++++++++++------------------ src/libs/actions/Report.js | 19 +++++++---------- 2 files changed, 23 insertions(+), 31 deletions(-) diff --git a/src/libs/Navigation/Navigation.js b/src/libs/Navigation/Navigation.js index 07b12486b8b2..d6b6812f3e7d 100644 --- a/src/libs/Navigation/Navigation.js +++ b/src/libs/Navigation/Navigation.js @@ -286,34 +286,29 @@ function navContainsProtectedRoutes(state) { * * @function * @returns {Promise} A promise that resolves to `true` when the Concierge route is present. - * Rejects with an error if the navigation is not ready. * * @example * waitForProtectedRoutes() * .then(() => console.log('Protected routes are present!')) - * .catch(error => console.error(error.message)); */ function waitForProtectedRoutes() { - return new Promise((resolve, reject) => { - const isReady = navigationRef.current && navigationRef.current.isReady(); - if (!isReady) { - reject(new Error('[Navigation] is not ready yet!')); - return; - } - const currentState = navigationRef.current.getState(); - if (navContainsProtectedRoutes(currentState)) { - resolve(); - return; - } - let unsubscribe; - const handleStateChange = ({data}) => { - const state = lodashGet(data, 'state'); - if (navContainsProtectedRoutes(state)) { - unsubscribe(); + return new Promise((resolve) => { + isNavigationReady().then(() => { + const currentState = navigationRef.current.getState(); + if (navContainsProtectedRoutes(currentState)) { resolve(); + return; } - }; - unsubscribe = navigationRef.current.addListener('state', handleStateChange); + let unsubscribe; + const handleStateChange = ({data}) => { + const state = lodashGet(data, 'state'); + if (navContainsProtectedRoutes(state)) { + unsubscribe(); + resolve(); + } + }; + unsubscribe = navigationRef.current.addListener('state', handleStateChange); + }); }); } diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index c56e9c567745..f2ceadb64481 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1903,20 +1903,17 @@ function openReportFromDeepLink(url, isAuthenticated) { // If we're not opening a public room (no reportID) or the user is authenticated, we unblock the UI (hide splash screen) Onyx.set(ONYXKEYS.IS_CHECKING_PUBLIC_ROOM, false); } - // Navigate to the report after sign-in/sign-up. InteractionManager.runAfterInteractions(() => { Session.waitForUserSignIn().then(() => { - Navigation.waitForProtectedRoutes() - .then(() => { - const route = ReportUtils.getRouteFromLink(url); - if (route === ROUTES.CONCIERGE) { - navigateToConciergeChat(true); - return; - } - Navigation.navigate(route, CONST.NAVIGATION.TYPE.PUSH); - }) - .catch((error) => Log.warn(error.message)); + Navigation.waitForProtectedRoutes().then(() => { + const route = ReportUtils.getRouteFromLink(url); + if (route === ROUTES.CONCIERGE) { + navigateToConciergeChat(true); + return; + } + Navigation.navigate(route, CONST.NAVIGATION.TYPE.PUSH); + }); }); }); }