-
Notifications
You must be signed in to change notification settings - Fork 354
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
[LLM][PROTECT-3391/3392/3393/3401/3403] Auto redirection to Recover upsell at the end of Stax/Flex onboarding #8226
Merged
ofreyssinet-ledger
merged 3 commits into
develop
from
feature/protect-3391-3392-3393-3401-3403
Oct 31, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"live-mobile": patch | ||
--- | ||
|
||
Stax/Flex onboarding: | ||
- Hide "Backup with Recover" section | ||
- Auto redirect to Recover upsell between the onboarding and the post onboarding | ||
|
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,6 @@ | ||
--- | ||
"@ledgerhq/types-live": patch | ||
"@ledgerhq/live-common": patch | ||
--- | ||
|
||
Add recoverUpsellRedirection feature flag |
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], | ||
); | ||
} |
73 changes: 73 additions & 0 deletions
73
...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,73 @@ | ||
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]); | ||
|
||
return useCallback(async () => { | ||
const internetConnected = await internetReachable(); | ||
if (internetConnected && protectFeature?.enabled) { | ||
const redirect = (url: string) => { | ||
Linking.openURL(url); | ||
setRedirectionStarted(true); | ||
}; | ||
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, | ||
touchScreenURI, | ||
]); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if there is a risk of us calling again an open because
isFocused
toggles when opening the first time and coming back to the screen using this hookEdit: probably handled here I suppose https://github.com/LedgerHQ/ledger-live/pull/8226/files#diff-3f35818d8304ffbf87ae671eca670437cfc8eade2dfac067406cdb959ae5f496R37-R41
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once the redirection to whatever is done,
shouldRedirectToWhatever
will be false, so it won't trigger again 👍