-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(llm/post onboarding): auto redirection to Recover upsell & post …
…onboarding
- Loading branch information
1 parent
ac8696f
commit 46fea4c
Showing
22 changed files
with
557 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
apps/ledger-live-mobile/src/hooks/useAutoRedirectToPostOnboarding/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useEffect } from "react"; | ||
import { useSelector } from "react-redux"; | ||
import { lastConnectedDeviceSelector } from "~/reducers/settings"; | ||
import { useOpenPostOnboardingCallback } from "./useOpenPostOnboardingCallback"; | ||
import { useShouldRedirect } from "./useShouldRedirect"; | ||
import { useOpenProtectUpsellCallback } from "./useOpenProtectUpsellCallback"; | ||
import { useIsFocused } from "@react-navigation/core"; | ||
|
||
/** | ||
* Redirects the user to the post onboarding or the protect (Ledger Recover) upsell if needed | ||
* */ | ||
export function useAutoRedirectToPostOnboarding() { | ||
const focused = useIsFocused(); | ||
const lastConnectedDevice = useSelector(lastConnectedDeviceSelector); | ||
|
||
const { shouldRedirectToProtectUpsell, shouldRedirectToPostOnboarding } = useShouldRedirect(); | ||
|
||
const openProtectUpsell = useOpenProtectUpsellCallback(); | ||
const openPostOnboarding = useOpenPostOnboardingCallback(); | ||
|
||
const isFocused = useIsFocused(); | ||
|
||
useEffect(() => { | ||
if (!isFocused) return; | ||
if (shouldRedirectToProtectUpsell) { | ||
openProtectUpsell(); | ||
} else if (shouldRedirectToPostOnboarding && lastConnectedDevice) { | ||
openPostOnboarding(lastConnectedDevice.modelId); | ||
} | ||
}, [ | ||
lastConnectedDevice, | ||
openPostOnboarding, | ||
openProtectUpsell, | ||
shouldRedirectToPostOnboarding, | ||
shouldRedirectToProtectUpsell, | ||
focused, | ||
isFocused, | ||
]); | ||
} |
19 changes: 19 additions & 0 deletions
19
...er-live-mobile/src/hooks/useAutoRedirectToPostOnboarding/useOpenPostOnboardingCallback.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useStartPostOnboardingCallback } from "@ledgerhq/live-common/postOnboarding/hooks/useStartPostOnboardingCallback"; | ||
import { DeviceModelId } from "@ledgerhq/types-devices"; | ||
import { useCallback } from "react"; | ||
|
||
/** | ||
* Returns a callback to open the post onboarding screen | ||
* */ | ||
export function useOpenPostOnboardingCallback() { | ||
const startPostOnboarding = useStartPostOnboardingCallback(); | ||
return useCallback( | ||
(deviceModelId: DeviceModelId) => { | ||
startPostOnboarding({ | ||
deviceModelId: deviceModelId, | ||
resetNavigationStack: false, | ||
}); | ||
}, | ||
[startPostOnboarding], | ||
); | ||
} |
75 changes: 75 additions & 0 deletions
75
...ger-live-mobile/src/hooks/useAutoRedirectToPostOnboarding/useOpenProtectUpsellCallback.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { useFeature } from "@ledgerhq/live-common/featureFlags/index"; | ||
import { | ||
Source, | ||
useAlreadyOnboardedURI, | ||
useHomeURI, | ||
usePostOnboardingURI, | ||
useTouchScreenOnboardingUpsellURI, | ||
} from "@ledgerhq/live-common/hooks/recoverFeatureFlag"; | ||
import { DeviceModelId } from "@ledgerhq/types-devices"; | ||
import { useIsFocused } from "@react-navigation/core"; | ||
import { useCallback, useEffect, useState } from "react"; | ||
import { Linking } from "react-native"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { setHasBeenUpsoldProtect } from "~/actions/settings"; | ||
import { internetReachable } from "~/logic/internetReachable"; | ||
import { lastConnectedDeviceSelector, onboardingTypeSelector } from "~/reducers/settings"; | ||
import { OnboardingType } from "~/reducers/types"; | ||
|
||
/** | ||
* Returns a callback to open the Protect (Ledger Recover) upsell | ||
* */ | ||
export function useOpenProtectUpsellCallback() { | ||
const lastConnectedDevice = useSelector(lastConnectedDeviceSelector); | ||
const onboardingType = useSelector(onboardingTypeSelector); | ||
const protectFeature = useFeature("protectServicesMobile"); | ||
const recoverAlreadyOnboardedURI = useAlreadyOnboardedURI(protectFeature); | ||
const recoverPostOnboardingURI = usePostOnboardingURI(protectFeature); | ||
const touchScreenURI = useTouchScreenOnboardingUpsellURI( | ||
protectFeature, | ||
Source.LLM_ONBOARDING_24, | ||
); | ||
const recoverHomeURI = useHomeURI(protectFeature); | ||
const dispatch = useDispatch(); | ||
const [redirectionStarted, setRedirectionStarted] = useState(false); | ||
const isFocused = useIsFocused(); | ||
|
||
useEffect(() => { | ||
if (redirectionStarted && !isFocused) { | ||
dispatch(setHasBeenUpsoldProtect(true)); | ||
} | ||
}, [redirectionStarted, isFocused, dispatch]); | ||
|
||
const redirect = useCallback((url: string) => { | ||
Linking.openURL(url); | ||
setRedirectionStarted(true); | ||
}, []); | ||
|
||
return useCallback(async () => { | ||
const internetConnected = await internetReachable(); | ||
if (internetConnected && protectFeature?.enabled) { | ||
if ( | ||
lastConnectedDevice && | ||
touchScreenURI && | ||
[DeviceModelId.stax, DeviceModelId.europa].includes(lastConnectedDevice.modelId) | ||
) { | ||
redirect(touchScreenURI); | ||
} else if (recoverPostOnboardingURI && onboardingType === OnboardingType.restore) { | ||
redirect(recoverPostOnboardingURI); | ||
} else if (recoverHomeURI && onboardingType === OnboardingType.setupNew) { | ||
redirect(recoverHomeURI); | ||
} else if (recoverAlreadyOnboardedURI) { | ||
redirect(recoverAlreadyOnboardedURI); | ||
} | ||
} | ||
}, [ | ||
lastConnectedDevice, | ||
onboardingType, | ||
protectFeature?.enabled, | ||
recoverAlreadyOnboardedURI, | ||
recoverHomeURI, | ||
recoverPostOnboardingURI, | ||
redirect, | ||
touchScreenURI, | ||
]); | ||
} |
Oops, something went wrong.