From 7275e6a7799eb903d3ca6f97a918220f2d0958c7 Mon Sep 17 00:00:00 2001 From: war-in Date: Fri, 13 Dec 2024 13:55:45 +0100 Subject: [PATCH 1/2] make HybridAppModule methods readable --- src/components/ScreenWrapper.tsx | 2 +- src/libs/TripReservationUtils.ts | 2 +- src/libs/actions/Delegate.ts | 4 ++-- src/libs/actions/Session/index.ts | 2 +- src/libs/actions/Welcome/index.ts | 2 +- src/pages/ErrorPage/SessionExpiredPage.tsx | 2 +- src/pages/settings/InitialSettingsPage.tsx | 2 +- src/types/modules/react-native.d.ts | 6 +++--- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/components/ScreenWrapper.tsx b/src/components/ScreenWrapper.tsx index 09315bfb8a8e..1e3df2a34817 100644 --- a/src/components/ScreenWrapper.tsx +++ b/src/components/ScreenWrapper.tsx @@ -177,7 +177,7 @@ function ScreenWrapper( }, [route?.params]); UNSTABLE_usePreventRemove(shouldReturnToOldDot, () => { - NativeModules.HybridAppModule?.closeReactNativeApp(false, false); + NativeModules.HybridAppModule?.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: false}); }); const panResponder = useRef( diff --git a/src/libs/TripReservationUtils.ts b/src/libs/TripReservationUtils.ts index f2ce5113af81..6379c3612539 100644 --- a/src/libs/TripReservationUtils.ts +++ b/src/libs/TripReservationUtils.ts @@ -108,7 +108,7 @@ function bookATrip(translate: LocaleContextProps['translate'], setCtaErrorMessag } Log.info('[HybridApp] Returning to OldDot after opening TravelDot'); - NativeModules.HybridAppModule.closeReactNativeApp(false, false); + NativeModules.HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: false}); }) ?.catch(() => { setCtaErrorMessage(translate('travel.errorMessage')); diff --git a/src/libs/actions/Delegate.ts b/src/libs/actions/Delegate.ts index f99400d87d3e..3901c63ad8dd 100644 --- a/src/libs/actions/Delegate.ts +++ b/src/libs/actions/Delegate.ts @@ -140,7 +140,7 @@ function connect(email: string) { confirmReadyToOpenApp(); openApp(); - NativeModules.HybridAppModule.switchAccount(email); + NativeModules.HybridAppModule.switchAccount({newDotCurrentAccount: email}); }); }) .catch((error) => { @@ -210,7 +210,7 @@ function disconnect() { confirmReadyToOpenApp(); openApp(); - NativeModules.HybridAppModule.switchAccount(getCurrentUserEmail() ?? ''); + NativeModules.HybridAppModule.switchAccount({newDotCurrentAccount: getCurrentUserEmail() ?? ''}); }); }) .catch((error) => { diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index e50eba7e596f..c4aee9fb91a8 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -218,7 +218,7 @@ function signOutAndRedirectToSignIn(shouldResetToHome?: boolean, shouldStashSess if (!isAnonymousUser()) { // In the HybridApp, we want the Old Dot to handle the sign out process if (NativeModules.HybridAppModule && killHybridApp) { - NativeModules.HybridAppModule.closeReactNativeApp(true, false); + NativeModules.HybridAppModule.closeReactNativeApp({shouldSignOut: true, shouldSetNVP: false}); return; } // We'll only call signOut if we're not stashing the session and this is not a supportal session, diff --git a/src/libs/actions/Welcome/index.ts b/src/libs/actions/Welcome/index.ts index f91ab98f7b1d..6febdf5f3e60 100644 --- a/src/libs/actions/Welcome/index.ts +++ b/src/libs/actions/Welcome/index.ts @@ -145,7 +145,7 @@ function completeHybridAppOnboarding() { // No matter what the response is, we want to mark the onboarding as completed (user saw the explanation modal) Log.info(`[HybridApp] Onboarding status has changed. Propagating new value to OldDot`, true); - NativeModules.HybridAppModule.completeOnboarding(true); + NativeModules.HybridAppModule.completeOnboarding({status: true}); }); } diff --git a/src/pages/ErrorPage/SessionExpiredPage.tsx b/src/pages/ErrorPage/SessionExpiredPage.tsx index 5ccf70c40ab6..906c32dbb102 100644 --- a/src/pages/ErrorPage/SessionExpiredPage.tsx +++ b/src/pages/ErrorPage/SessionExpiredPage.tsx @@ -37,7 +37,7 @@ function SessionExpiredPage() { Navigation.goBack(); return; } - NativeModules.HybridAppModule.closeReactNativeApp(true, false); + NativeModules.HybridAppModule.closeReactNativeApp({shouldSignOut: true, shouldSetNVP: false}); }} > {translate('deeplinkWrapper.signIn')} diff --git a/src/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index a40b14eae4c9..cb5929e54415 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -243,7 +243,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr ...(NativeModules.HybridAppModule ? { action: () => { - NativeModules.HybridAppModule.closeReactNativeApp(false, true); + NativeModules.HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: true}); setInitialURL(undefined); }, } diff --git a/src/types/modules/react-native.d.ts b/src/types/modules/react-native.d.ts index c72d4bf2a653..6340c70167fe 100644 --- a/src/types/modules/react-native.d.ts +++ b/src/types/modules/react-native.d.ts @@ -6,9 +6,9 @@ import type {ShortcutManagerModule} from '@libs/ShortcutManager'; import type StartupTimer from '@libs/StartupTimer/types'; type HybridAppModule = { - closeReactNativeApp: (shouldSignOut: boolean, shouldSetNVP: boolean) => void; - completeOnboarding: (status: boolean) => void; - switchAccount: (newDotCurrentAccount: string) => void; + closeReactNativeApp: ({shouldSignOut: boolean, shouldSetNVP: boolean}) => void; + completeOnboarding: ({status: boolean}) => void; + switchAccount: ({newDotCurrentAccount: string}) => void; exitApp: () => void; }; From 115ee41fe9857c593d55d66d1d7c110fd99732b0 Mon Sep 17 00:00:00 2001 From: war-in Date: Fri, 13 Dec 2024 14:26:18 +0100 Subject: [PATCH 2/2] improve another method --- src/libs/HybridApp.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/libs/HybridApp.ts b/src/libs/HybridApp.ts index 60e6debeec96..85b137bf6d50 100644 --- a/src/libs/HybridApp.ts +++ b/src/libs/HybridApp.ts @@ -70,16 +70,16 @@ function handleChangeInHybridAppSignInFlow(hybridApp: OnyxEntry, tryN if (hybridApp?.newDotSignInState === CONST.HYBRID_APP_SIGN_IN_STATE.FINISHED && tryNewDot !== undefined && !!credentials?.autoGeneratedLogin && !!credentials?.autoGeneratedPassword) { Log.info(`[HybridApp] Performing sign-in${shouldUseOldApp(tryNewDot) ? '' : ' (in background)'} on OldDot side`); - NativeModules.HybridAppModule.signInToOldDot( - credentials.autoGeneratedLogin, - credentials.autoGeneratedPassword, - currentSession?.authToken ?? '', - getCurrentUserEmail() ?? '', - activePolicyID ?? '', - ); + NativeModules.HybridAppModule.signInToOldDot({ + autoGeneratedLogin: credentials.autoGeneratedLogin, + autoGeneratedPassword: credentials.autoGeneratedPassword, + authToken: currentSession?.authToken ?? '', + email: getCurrentUserEmail() ?? '', + policyID: activePolicyID ?? '', + }); HybridAppActions.setUseNewDotSignInPage(false).then(() => { if (shouldUseOldApp(tryNewDot)) { - NativeModules.HybridAppModule.closeReactNativeApp(false, false); + NativeModules.HybridAppModule.closeReactNativeApp({shouldSignOut: false, shouldSetNVP: false}); } else { Log.info('[HybridApp] The user should see NewDot. There is no need to block the user on the `SignInPage` until the sign-in process is completed on the OldDot side.'); HybridAppActions.setReadyToShowAuthScreens(true);