-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6802 from LedgerHQ/feat/post-onboarding-deeplink
LLM / LLD - Post Onboarding Deeplink
- Loading branch information
Showing
11 changed files
with
205 additions
and
1 deletion.
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,7 @@ | ||
--- | ||
"ledger-live-desktop": minor | ||
"live-mobile": minor | ||
"@ledgerhq/live-common": minor | ||
--- | ||
|
||
LLM / LLD - Add a deeplink redirecting to 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
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
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
32 changes: 32 additions & 0 deletions
32
apps/ledger-live-mobile/src/screens/PostOnboarding/PostOnboardingDeeplinkHandler.tsx
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,32 @@ | ||
import React, { useEffect } from "react"; | ||
import { NavigatorName, ScreenName } from "~/const"; | ||
import { BaseComposite, StackNavigatorProps } from "~/components/RootNavigator/types/helpers"; | ||
import { PostOnboardingNavigatorParamList } from "~/components/RootNavigator/types/PostOnboardingNavigator"; | ||
import { usePostOnboardingDeeplinkHandler } from "@ledgerhq/live-common/postOnboarding/hooks/index"; | ||
import { useNavigateToPostOnboardingHubCallback } from "~/logic/postOnboarding/useNavigateToPostOnboardingHubCallback"; | ||
import { Loading } from "~/components/Loading"; | ||
|
||
type Props = BaseComposite< | ||
StackNavigatorProps<PostOnboardingNavigatorParamList, ScreenName.PostOnboardingDeeplinkHandler> | ||
>; | ||
const PostOnboardingDeeplinkHandler = ({ route, navigation }: Props) => { | ||
const navigateToHome = () => { | ||
navigation.navigate(NavigatorName.Base, { | ||
screen: NavigatorName.Main, | ||
}); | ||
}; | ||
const navigateToPostOnboardingHub = useNavigateToPostOnboardingHubCallback(); | ||
const postOnboardingDeeplinkHandler = usePostOnboardingDeeplinkHandler( | ||
navigateToHome, | ||
navigateToPostOnboardingHub, | ||
); | ||
|
||
useEffect(() => { | ||
postOnboardingDeeplinkHandler(route.params?.device); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
return <Loading />; | ||
}; | ||
|
||
export default PostOnboardingDeeplinkHandler; |
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
93 changes: 93 additions & 0 deletions
93
libs/ledger-live-common/src/postOnboarding/hooks/usePostOnboardingDeeplinkHandler.test.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,93 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
|
||
import { renderHook, act } from "@testing-library/react"; | ||
import { usePostOnboardingDeeplinkHandler } from "./usePostOnboardingDeeplinkHandler"; | ||
|
||
import { PostOnboardingHubState } from "@ledgerhq/types-live"; | ||
import { DeviceModelId } from "@ledgerhq/devices"; | ||
|
||
import { | ||
postOnboardingDeviceModelIdSelector, | ||
walletPostOnboardingEntryPointDismissedSelector, | ||
} from "../reducer"; | ||
import { useAllPostOnboardingActionsCompleted } from "./useAllPostOnboardingActionsCompleted"; | ||
import { usePostOnboardingHubState } from "./usePostOnboardingHubState"; | ||
import { claimTestMock, personalizeTestMock, migrateAssetsTestMock } from "../mock"; | ||
|
||
const mockedDispatch = jest.fn(); | ||
jest.mock("react-redux", () => ({ | ||
useSelector: fun => fun(), | ||
useDispatch: () => mockedDispatch, | ||
})); | ||
|
||
jest.mock("../reducer"); | ||
jest.mock("./useAllPostOnboardingActionsCompleted"); | ||
jest.mock("./usePostOnboardingHubState"); | ||
|
||
const mockedUseAllCompleted = jest.mocked(useAllPostOnboardingActionsCompleted); | ||
const mockedDismissedSelector = jest.mocked(walletPostOnboardingEntryPointDismissedSelector); | ||
const mockedDeviceModelIdSelector = jest.mocked(postOnboardingDeviceModelIdSelector); | ||
const mockedUsePostOnboardingHubState = jest.mocked(usePostOnboardingHubState); | ||
|
||
const mockedStateNoActionsCompleted: PostOnboardingHubState = { | ||
deviceModelId: DeviceModelId.stax, | ||
lastActionCompleted: null, | ||
actionsState: [ | ||
{ ...claimTestMock, completed: false }, | ||
{ ...personalizeTestMock, completed: false }, | ||
{ ...migrateAssetsTestMock, completed: false }, | ||
], | ||
postOnboardingInProgress: false, | ||
}; | ||
|
||
describe("usePostOnboardingDeeplinkHandler", () => { | ||
beforeEach(() => { | ||
mockedUseAllCompleted.mockClear(); | ||
mockedDismissedSelector.mockClear(); | ||
mockedDeviceModelIdSelector.mockClear(); | ||
mockedDispatch.mockClear(); | ||
mockedUsePostOnboardingHubState.mockClear(); | ||
}); | ||
|
||
test("should navigate to the post onboarding hub when called with a stax device model id", () => { | ||
mockedDismissedSelector.mockReturnValue(false); | ||
mockedUseAllCompleted.mockReturnValue(false); | ||
mockedDeviceModelIdSelector.mockReturnValue(DeviceModelId.stax); | ||
mockedUsePostOnboardingHubState.mockReturnValue(mockedStateNoActionsCompleted); | ||
|
||
const navigateToHome = jest.fn(); | ||
const navigateToPostOnboardingHub = jest.fn(); | ||
const { result } = renderHook(() => | ||
usePostOnboardingDeeplinkHandler(navigateToHome, navigateToPostOnboardingHub), | ||
); | ||
|
||
act(() => { | ||
result.current("stax"); | ||
}); | ||
|
||
expect(navigateToPostOnboardingHub).toHaveBeenCalled(); | ||
expect(navigateToHome).not.toHaveBeenCalled(); | ||
}); | ||
|
||
test("should navigate to the home when called with no device parameter", () => { | ||
mockedDismissedSelector.mockReturnValue(false); | ||
mockedUseAllCompleted.mockReturnValue(false); | ||
mockedDeviceModelIdSelector.mockReturnValue(DeviceModelId.nanoSP); | ||
mockedUsePostOnboardingHubState.mockReturnValue(mockedStateNoActionsCompleted); | ||
|
||
const navigateToHome = jest.fn(); | ||
const navigateToPostOnboardingHub = jest.fn(); | ||
const { result } = renderHook(() => | ||
usePostOnboardingDeeplinkHandler(navigateToHome, navigateToPostOnboardingHub), | ||
); | ||
|
||
act(() => { | ||
result.current(); | ||
}); | ||
|
||
expect(navigateToPostOnboardingHub).not.toHaveBeenCalled(); | ||
expect(navigateToHome).toHaveBeenCalled(); | ||
}); | ||
}); |
38 changes: 38 additions & 0 deletions
38
libs/ledger-live-common/src/postOnboarding/hooks/usePostOnboardingDeeplinkHandler.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,38 @@ | ||
import { useCallback } from "react"; | ||
import { DeviceModelId } from "@ledgerhq/devices"; | ||
import { useStartPostOnboardingCallback } from "./useStartPostOnboardingCallback"; | ||
import { usePostOnboardingEntryPointVisibleOnWallet } from "./usePostOnboardingEntryPointVisibleOnWallet"; | ||
import { usePostOnboardingHubState } from "./usePostOnboardingHubState"; | ||
|
||
export function usePostOnboardingDeeplinkHandler(navigateToHome, navigateToPostOnboardingHub) { | ||
const handleInitPostOnboarding = useStartPostOnboardingCallback(); | ||
const isPostOnboardingVisible = usePostOnboardingEntryPointVisibleOnWallet(); | ||
const { deviceModelId: postOnboardingDeviceModelId } = usePostOnboardingHubState(); | ||
|
||
return useCallback( | ||
(device?: string) => { | ||
if (!device) { | ||
navigateToHome(); | ||
return; | ||
} | ||
if (isPostOnboardingVisible && device === postOnboardingDeviceModelId) { | ||
navigateToPostOnboardingHub(); | ||
} else if (device in DeviceModelId) { | ||
handleInitPostOnboarding({ | ||
deviceModelId: device as DeviceModelId, | ||
mock: false, | ||
fallbackIfNoAction: () => navigateToHome(), | ||
}); | ||
} else { | ||
navigateToHome(); | ||
} | ||
}, | ||
[ | ||
handleInitPostOnboarding, | ||
isPostOnboardingVisible, | ||
navigateToHome, | ||
navigateToPostOnboardingHub, | ||
postOnboardingDeviceModelId, | ||
], | ||
); | ||
} |