From 892dec22757fa20e7b0b2ec6776480a468a0a926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Warcho=C5=82?= <61014013+war-in@users.noreply.github.com> Date: Fri, 13 Dec 2024 14:50:49 +0100 Subject: [PATCH] Add named params in HybridAppModule methods (#153) * make HybridAppModule methods readable * improve another method --------- Co-authored-by: war-in --- src/components/ScreenWrapper.tsx | 2 +- src/libs/HybridApp.ts | 16 ++++++++-------- src/libs/TripReservationUtils.ts | 2 +- src/libs/actions/Delegate.ts | 4 ++-- 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 | 8 ++++---- 8 files changed, 19 insertions(+), 19 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/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); diff --git a/src/libs/TripReservationUtils.ts b/src/libs/TripReservationUtils.ts index 9c9947644e7f..275a0a965c24 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/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 07071736cd10..0bc86426455a 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -244,7 +244,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 cfab342c5c26..d3a17c73fced 100644 --- a/src/types/modules/react-native.d.ts +++ b/src/types/modules/react-native.d.ts @@ -6,10 +6,10 @@ 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; - signInToOldDot: (autoGeneratedLogin: string, autoGeneratedPassword: string, authToken: string, email: string, policyID: string) => void; + closeReactNativeApp: ({shouldSignOut: boolean, shouldSetNVP: boolean}) => void; + completeOnboarding: ({status: boolean}) => void; + switchAccount: ({newDotCurrentAccount: string}) => void; + signInToOldDot: ({autoGeneratedLogin: string, autoGeneratedPassword: string, authToken: string, email: string, policyID: string}) => void; signOutFromOldDot: () => void; exitApp: () => void; };