Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HybridApp] Do not use query params in AppProp URL #125

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ import {ReportAttachmentsProvider} from './pages/home/report/ReportAttachmentsCo
import type {Route} from './ROUTES';
import {SplashScreenStateContextProvider} from './SplashScreenStateContext';

/**
* URL and settings passed to our top-level React Native component by HybridApp. Will always be undefined in "pure" NewDot builds.
*/
type AppProps = {
/** URL passed to our top-level React Native component by HybridApp. Will always be undefined in "pure" NewDot builds. */
war-in marked this conversation as resolved.
Show resolved Hide resolved
url?: Route;
hybridAppSettings?: string;
};

LogBox.ignoreLogs([
Expand All @@ -59,15 +62,18 @@ const fill = {flex: 1};

const StrictModeWrapper = CONFIG.USE_REACT_STRICT_MODE_IN_DEV ? React.StrictMode : ({children}: {children: React.ReactElement}) => children;

function App({url}: AppProps) {
function App({url, hybridAppSettings}: AppProps) {
useDefaultDragAndDrop();
OnyxUpdateManager();
HybridApp.init();

return (
<StrictModeWrapper>
<SplashScreenStateContextProvider>
<InitialURLContextProvider url={url}>
<InitialURLContextProvider
url={url}
hybridAppSettings={hybridAppSettings}
>
war-in marked this conversation as resolved.
Show resolved Hide resolved
<GestureHandlerRootView style={fill}>
<ComposeProviders
components={[
Expand Down
4 changes: 2 additions & 2 deletions src/Expensify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ function Expensify() {
const isAuthenticated = useMemo(() => !!(session?.authToken ?? null), [session]);
const autoAuthState = useMemo(() => session?.autoAuthState ?? '', [session]);

const shouldInit = !!NativeModules.HybridAppModule
const shouldInit = NativeModules.HybridAppModule
? !hybridApp?.loggedOutFromOldDot && isNavigationReady && hasAttemptedToOpenPublicRoom
: isNavigationReady && hasAttemptedToOpenPublicRoom;
const shouldHideSplash =
shouldInit &&
(!!NativeModules.HybridAppModule
(NativeModules.HybridAppModule
? splashScreenState === CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN && (isAuthenticated || !!hybridApp?.useNewDotSignInPage)
: splashScreenState === CONST.BOOT_SPLASH_STATE.VISIBLE);

Expand Down
4 changes: 0 additions & 4 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,6 @@ const ONYXKEYS = {
/** Stores recently used currencies */
RECENTLY_USED_CURRENCIES: 'nvp_recentlyUsedCurrencies',

/** States whether we transitioned from OldDot to show only certain group of screens. It should be undefined on pure NewDot. */
IS_SINGLE_NEW_DOT_ENTRY: 'isSingleNewDotEntry',

/** Company cards custom names */
NVP_EXPENSIFY_COMPANY_CARDS_CUSTOM_NAMES: 'nvp_expensify_ccCustomNames',

Expand Down Expand Up @@ -1026,7 +1023,6 @@ type OnyxValuesMapping = {
[ONYXKEYS.APPROVAL_WORKFLOW]: OnyxTypes.ApprovalWorkflowOnyx;
[ONYXKEYS.IMPORTED_SPREADSHEET]: OnyxTypes.ImportedSpreadsheet;
[ONYXKEYS.LAST_ROUTE]: string;
[ONYXKEYS.IS_SINGLE_NEW_DOT_ENTRY]: boolean | undefined;
[ONYXKEYS.IS_USING_IMPORTED_STATE]: boolean;
[ONYXKEYS.SHOULD_SHOW_SAVED_SEARCH_RENAME_TOOLTIP]: boolean;
[ONYXKEYS.NVP_EXPENSIFY_COMPANY_CARDS_CUSTOM_NAMES]: Record<string, string>;
Expand Down
13 changes: 7 additions & 6 deletions src/components/InitialURLContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@ const InitialURLContext = createContext<InitialUrlContextType>({
});

type InitialURLContextProviderProps = {
/** URL passed to our top-level React Native component by HybridApp. Will always be undefined in "pure" NewDot builds. */
url?: Route;

hybridAppSettings?: string;

/** Children passed to the context provider */
children: ReactNode;
};

function InitialURLContextProvider({children, url}: InitialURLContextProviderProps) {
const [initialURL, setInitialURL] = useState<Route | undefined>();
function InitialURLContextProvider({children, url, hybridAppSettings}: InitialURLContextProviderProps) {
war-in marked this conversation as resolved.
Show resolved Hide resolved
const [initialURL, setInitialURL] = useState<Route | undefined>(url);
const {setSplashScreenState} = useSplashScreenStateContext();

useEffect(() => {
if (url) {
signInAfterTransitionFromOldDot(url).then((route) => {
if (url && hybridAppSettings) {
signInAfterTransitionFromOldDot(url, hybridAppSettings).then((route) => {
setInitialURL(route);
setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN);
});
Expand All @@ -40,7 +41,7 @@ function InitialURLContextProvider({children, url}: InitialURLContextProviderPro
Linking.getInitialURL().then((initURL) => {
setInitialURL(initURL as Route);
});
}, [setSplashScreenState, url]);
}, [hybridAppSettings, setSplashScreenState, url]);

const initialUrlContext = useMemo(
() => ({
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useOnboardingFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function useOnboardingFlowRouter() {
selector: hasCompletedHybridAppOnboardingFlowSelector,
});

const [isSingleNewDotEntry, isSingleNewDotEntryMetadata] = useOnyx(ONYXKEYS.IS_SINGLE_NEW_DOT_ENTRY);
const [isSingleNewDotEntry, isSingleNewDotEntryMetadata] = useOnyx(ONYXKEYS.HYBRID_APP, {selector: (data) => data?.isSingleNewDotEntry});

useEffect(() => {
if (isLoadingOnyxValue(isOnboardingCompletedMetadata)) {
Expand Down
4 changes: 2 additions & 2 deletions src/libs/TripReservationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ Onyx.connect({

let isSingleNewDotEntry: boolean | undefined;
Onyx.connect({
key: ONYXKEYS.IS_SINGLE_NEW_DOT_ENTRY,
key: ONYXKEYS.HYBRID_APP,
callback: (val) => {
isSingleNewDotEntry = val;
isSingleNewDotEntry = val?.isSingleNewDotEntry;
},
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import Onyx from 'react-native-onyx';
import ONYXKEYS from '@src/ONYXKEYS';
import type HybridAppSettings from './types';

function parseHybridAppSettings(hybridAppSettings: string): HybridAppSettings {
return JSON.parse(hybridAppSettings) as HybridAppSettings;
}

function setIsSigningIn(isSigningIn: boolean) {
Onyx.merge(ONYXKEYS.HYBRID_APP, {isSigningIn});
Expand Down Expand Up @@ -29,4 +34,13 @@ function setLoggedOutFromOldDot(loggedOutFromOldDot: boolean) {
Onyx.merge(ONYXKEYS.HYBRID_APP, {loggedOutFromOldDot});
}

export {setOldDotSignInError, setIsSigningIn, setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience, setShouldResetSigningInLogic, setUseNewDotSignInPage, setLoggedOutFromOldDot};
export {
parseHybridAppSettings,
setOldDotSignInError,
setIsSigningIn,
setReadyToShowAuthScreens,
setReadyToSwitchToClassicExperience,
setShouldResetSigningInLogic,
setUseNewDotSignInPage,
setLoggedOutFromOldDot,
};
12 changes: 12 additions & 0 deletions src/libs/actions/HybridApp/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type ONYXKEYS from '@src/ONYXKEYS';
import type {TryNewDot} from '@src/types/onyx';
import type HybridApp from '@src/types/onyx/HybridApp';

type HybridAppSettings = {
initialOnyxValues: {
[ONYXKEYS.HYBRID_APP]: HybridApp;
[ONYXKEYS.NVP_TRYNEWDOT]?: TryNewDot;
};
};

export default HybridAppSettings;
37 changes: 17 additions & 20 deletions src/libs/actions/Session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import * as App from '@userActions/App';
import {KEYS_TO_PRESERVE, openApp} from '@userActions/App';
import {KEYS_TO_PRESERVE_DELEGATE_ACCESS} from '@userActions/Delegate';
import * as Device from '@userActions/Device';
import {setLoggedOutFromOldDot, setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience, setUseNewDotSignInPage} from '@userActions/HybridApp';
import {parseHybridAppSettings, setLoggedOutFromOldDot, setReadyToShowAuthScreens, setReadyToSwitchToClassicExperience, setUseNewDotSignInPage} from '@userActions/HybridApp';
import * as PriorityMode from '@userActions/PriorityMode';
import redirectToSignIn from '@userActions/SignInRedirect';
import Timing from '@userActions/Timing';
Expand Down Expand Up @@ -481,19 +481,13 @@ function signUpUser() {
API.write(WRITE_COMMANDS.SIGN_UP_USER, params, {optimisticData, successData, failureData});
}

function signInAfterTransitionFromOldDot(transitionURL: string) {
const [route, queryParams] = transitionURL.split('?');
const {useNewDotSignInPage, isSingleNewDotEntry, loggedOutFromOldDot, shouldRemoveDelegatedAccess} = queryParams
? Object.fromEntries(
queryParams.split('&').map((param) => {
const [key, value] = param.split('=');
return [key, value];
}),
)
: {useNewDotSignInPage: undefined, isSingleNewDotEntry: undefined, loggedOutFromOldDot: undefined, shouldRemoveDelegatedAccess: undefined};
function signInAfterTransitionFromOldDot(route: Route, hybridAppSettings: string) {
const parsedHybridAppSettings = parseHybridAppSettings(hybridAppSettings);
const {initialOnyxValues} = parsedHybridAppSettings;
const {hybridApp, ...newDotOnyxValues} = initialOnyxValues;

const clearOnyxBeforeSignIn = () => {
if (useNewDotSignInPage !== 'true') {
if (!hybridApp.useNewDotSignInPage) {
setReadyToShowAuthScreens(true);
setReadyToSwitchToClassicExperience(true);
return Promise.resolve();
Expand All @@ -503,7 +497,7 @@ function signInAfterTransitionFromOldDot(transitionURL: string) {
};

const initAppAfterTransition = () => {
if (useNewDotSignInPage === 'true') {
if (hybridApp.useNewDotSignInPage) {
return Promise.resolve();
}

Expand All @@ -512,27 +506,30 @@ function signInAfterTransitionFromOldDot(transitionURL: string) {

return new Promise<Route>((resolve) => {
clearOnyxBeforeSignIn()
.then(() => Onyx.merge(ONYXKEYS.HYBRID_APP, hybridApp))
.then(() => Onyx.multiSet(newDotOnyxValues))
.then(() => {
if (!shouldRemoveDelegatedAccess) {
if (!hybridApp.shouldRemoveDelegatedAccess) {
return;
}
return Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS);
})
.then(() => {
setUseNewDotSignInPage(useNewDotSignInPage === 'true');
setLoggedOutFromOldDot(loggedOutFromOldDot === 'true');
// This data is mocked and should be returned by BeginSignUp/SignInUser API commands
setUseNewDotSignInPage(!!hybridApp.useNewDotSignInPage);
setLoggedOutFromOldDot(!!hybridApp.loggedOutFromOldDot);
const useOldDot = 'true';
const dismissed = useNewDotSignInPage === 'true' ? useOldDot : 'false';
Onyx.multiSet({
[ONYXKEYS.NVP_TRYNEWDOT]: {classicRedirect: {dismissed}}, // This data is mocked and should be returned by BeginSignUp/SignInUser API commands
const dismissed = hybridApp.useNewDotSignInPage ? useOldDot : 'false';
return Onyx.multiSet({
[ONYXKEYS.NVP_TRYNEWDOT]: {classicRedirect: {dismissed}},
});
})
.then(initAppAfterTransition)
.catch((error) => {
Log.hmmm('[HybridApp] Initialization of HybridApp has failed. Forcing transition', {error});
})
.finally(() => {
resolve(`${route}?singleNewDotEntry=${isSingleNewDotEntry}` as Route);
resolve(`${route}?singleNewDotEntry=${hybridApp.isSingleNewDotEntry}` as Route);
});
});
}
Expand Down
6 changes: 6 additions & 0 deletions src/types/onyx/HybridApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ type HybridApp = {
/** */
shouldResetSigningInLogic?: boolean;

/** States whether we transitioned from OldDot to show only certain group of screens. It should be undefined on pure NewDot. */
isSingleNewDotEntry?: boolean;
war-in marked this conversation as resolved.
Show resolved Hide resolved

/** stores infromation if last log out was performed from OldDot */
loggedOutFromOldDot?: boolean;

/** */
shouldRemoveDelegatedAccess?: boolean;
};

export default HybridApp;
Loading