From cde8353a57d92d330624353fb1e89574d19b458c Mon Sep 17 00:00:00 2001 From: Theophile Sandoz Date: Wed, 28 Aug 2024 12:47:32 +0200 Subject: [PATCH 1/4] Create LLDs /ledgersync deeplink --- .../src/renderer/hooks/useDeeplinking.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/ledger-live-desktop/src/renderer/hooks/useDeeplinking.ts b/apps/ledger-live-desktop/src/renderer/hooks/useDeeplinking.ts index 5e98962531f6..0834195f8231 100644 --- a/apps/ledger-live-desktop/src/renderer/hooks/useDeeplinking.ts +++ b/apps/ledger-live-desktop/src/renderer/hooks/useDeeplinking.ts @@ -18,6 +18,7 @@ import { Account, SubAccount } from "@ledgerhq/types-live"; import { useStorylyContext } from "~/storyly/StorylyProvider"; import { useNavigateToPostOnboardingHubCallback } from "~/renderer/components/PostOnboardingHub/logic/useNavigateToPostOnboardingHubCallback"; import { usePostOnboardingDeeplinkHandler } from "@ledgerhq/live-common/postOnboarding/hooks/index"; +import { setDrawerVisibility as setLedgerSyncDrawerVisibility } from "../actions/walletSync"; const getAccountsOrSubAccountsByCurrency = ( currency: CryptoOrTokenCurrency, @@ -346,6 +347,11 @@ export function useDeepLinkHandler() { postOnboardingDeeplinkHandler(query.device); break; } + case "ledgersync": { + navigate("/settings/display"); + dispatch(setLedgerSyncDrawerVisibility(true)); + break; + } case "portfolio": default: navigate("/"); From fcdbc7cc047cf64d58b7d6b1b8c647655df04193 Mon Sep 17 00:00:00 2001 From: Theophile Sandoz Date: Thu, 29 Aug 2024 11:38:00 +0200 Subject: [PATCH 2/4] Use redux to show the ledger sync activation drawer --- apps/ledger-live-mobile/src/actions/types.ts | 4 +++- .../src/actions/walletSync.ts | 6 +++++- apps/ledger-live-mobile/src/reducers/types.ts | 1 + .../src/reducers/walletSync.ts | 16 ++++++++++++++-- .../screens/Settings/General/WalletSyncRow.tsx | 18 +++++++++++------- 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/apps/ledger-live-mobile/src/actions/types.ts b/apps/ledger-live-mobile/src/actions/types.ts index e7ba9100ff4f..bc1686033660 100644 --- a/apps/ledger-live-mobile/src/actions/types.ts +++ b/apps/ledger-live-mobile/src/actions/types.ts @@ -529,10 +529,12 @@ export type MarketPayload = // === WALLETSYNC ACTIONS === export enum WalletSyncActionTypes { WALLET_SYNC_SET_MANAGE_KEY_DRAWER = "WALLET_SYNC_SET_MANAGE_KEY_DRAWER", + LEDGER_SYNC_SET_ACTIVATE_DRAWER = "LEDGER_SYNC_SET_ACTIVATE_DRAWER", } export type WalletSyncSetManageKeyDrawerPayload = boolean; -export type WalletSyncPayload = WalletSyncSetManageKeyDrawerPayload; +export type WalletSyncSetActivateDrawer = boolean; +export type WalletSyncPayload = WalletSyncSetManageKeyDrawerPayload | WalletSyncSetActivateDrawer; // === PAYLOADS === diff --git a/apps/ledger-live-mobile/src/actions/walletSync.ts b/apps/ledger-live-mobile/src/actions/walletSync.ts index 8cde4b6c877e..49563fdbcc15 100644 --- a/apps/ledger-live-mobile/src/actions/walletSync.ts +++ b/apps/ledger-live-mobile/src/actions/walletSync.ts @@ -1,7 +1,11 @@ import { createAction } from "redux-actions"; import { WalletSyncActionTypes } from "./types"; -import type { WalletSyncSetManageKeyDrawerPayload } from "./types"; +import type { WalletSyncSetActivateDrawer, WalletSyncSetManageKeyDrawerPayload } from "./types"; export const setWallectSyncManageKeyDrawer = createAction( WalletSyncActionTypes.WALLET_SYNC_SET_MANAGE_KEY_DRAWER, ); + +export const setLedgerSyncActivateDrawer = createAction( + WalletSyncActionTypes.LEDGER_SYNC_SET_ACTIVATE_DRAWER, +); diff --git a/apps/ledger-live-mobile/src/reducers/types.ts b/apps/ledger-live-mobile/src/reducers/types.ts index 1d4778f26b8b..e5b9fa1af111 100644 --- a/apps/ledger-live-mobile/src/reducers/types.ts +++ b/apps/ledger-live-mobile/src/reducers/types.ts @@ -346,6 +346,7 @@ export type MarketState = { export type WalletSyncState = { isManageKeyDrawerOpen: boolean; + isActivateDrawerOpen: boolean; }; // === ROOT STATE === diff --git a/apps/ledger-live-mobile/src/reducers/walletSync.ts b/apps/ledger-live-mobile/src/reducers/walletSync.ts index 7a137c19c4b2..7253382342aa 100644 --- a/apps/ledger-live-mobile/src/reducers/walletSync.ts +++ b/apps/ledger-live-mobile/src/reducers/walletSync.ts @@ -1,21 +1,33 @@ import { handleActions } from "redux-actions"; import type { Action, ReducerMap } from "redux-actions"; import type { State, WalletSyncState } from "./types"; -import { WalletSyncPayload, WalletSyncSetManageKeyDrawerPayload } from "../actions/types"; +import { + WalletSyncActionTypes, + WalletSyncPayload, + WalletSyncSetActivateDrawer, + WalletSyncSetManageKeyDrawerPayload, +} from "../actions/types"; export const INITIAL_STATE: WalletSyncState = { isManageKeyDrawerOpen: false, + isActivateDrawerOpen: false, }; const handlers: ReducerMap = { - WALLET_SYNC_SET_MANAGE_KEY_DRAWER: (state, action) => ({ + [WalletSyncActionTypes.WALLET_SYNC_SET_MANAGE_KEY_DRAWER]: (state, action) => ({ ...state, isManageKeyDrawerOpen: (action as Action).payload, }), + [WalletSyncActionTypes.LEDGER_SYNC_SET_ACTIVATE_DRAWER]: (state, action) => ({ + ...state, + isActivateDrawerOpen: (action as Action).payload, + }), }; export const storeSelector = (state: State): WalletSyncState => state.walletSync; export const manageKeyDrawerSelector = (state: State): boolean => state.walletSync.isManageKeyDrawerOpen; +export const activateDrawerSelector = (state: State): boolean => + state.walletSync.isActivateDrawerOpen; export default handleActions(handlers, INITIAL_STATE); diff --git a/apps/ledger-live-mobile/src/screens/Settings/General/WalletSyncRow.tsx b/apps/ledger-live-mobile/src/screens/Settings/General/WalletSyncRow.tsx index d7ae699d017c..d93c667bd6b1 100644 --- a/apps/ledger-live-mobile/src/screens/Settings/General/WalletSyncRow.tsx +++ b/apps/ledger-live-mobile/src/screens/Settings/General/WalletSyncRow.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useState } from "react"; +import React, { useCallback } from "react"; import SettingsRow from "~/components/SettingsRow"; import { useTranslation } from "react-i18next"; import { useNavigation } from "@react-navigation/native"; @@ -8,20 +8,24 @@ import { AnalyticsPage, AnalyticsButton, } from "LLM/features/WalletSync/hooks/useLedgerSyncAnalytics"; -import { useSelector } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import { trustchainSelector } from "@ledgerhq/trustchain/store"; import ActivationDrawer from "LLM/features/WalletSync/screens/Activation/ActivationDrawer"; import { Steps } from "LLM/features/WalletSync/types/Activation"; +import { activateDrawerSelector } from "~/reducers/walletSync"; +import { setLedgerSyncActivateDrawer } from "~/actions/walletSync"; const WalletSyncRow = () => { const { t } = useTranslation(); const { onClickTrack } = useLedgerSyncAnalytics(); const navigation = useNavigation(); - const [isDrawerVisible, setIsDrawerVisible] = useState(false); + + const isDrawerVisible = useSelector(activateDrawerSelector); + const dispatch = useDispatch(); const closeDrawer = useCallback(() => { - setIsDrawerVisible(false); - }, []); + dispatch(setLedgerSyncActivateDrawer(false)); + }, [dispatch]); const trustchain = useSelector(trustchainSelector); const navigateToWalletSyncActivationScreen = useCallback(() => { @@ -33,9 +37,9 @@ const WalletSyncRow = () => { screen: ScreenName.WalletSyncActivated, }); } else { - setIsDrawerVisible(true); + dispatch(setLedgerSyncActivateDrawer(true)); } - }, [navigation, onClickTrack, trustchain?.rootId]); + }, [navigation, onClickTrack, trustchain?.rootId, dispatch]); return ( <> From f9c8b514a50c7834c8ee024da47ded208840be1a Mon Sep 17 00:00:00 2001 From: Theophile Sandoz Date: Thu, 29 Aug 2024 11:53:56 +0200 Subject: [PATCH 3/4] Create LLMs /ledgersync deeplink --- .../types/WalletSyncNavigator.ts | 2 ++ .../src/const/navigation.ts | 1 + .../src/navigation/DeeplinksProvider.tsx | 6 +++++ .../WalletSync/WalletSyncNavigator.tsx | 9 +++++++ .../screens/LedgerSyncDeepLinkHandler.tsx | 27 +++++++++++++++++++ 5 files changed, 45 insertions(+) create mode 100644 apps/ledger-live-mobile/src/newArch/features/WalletSync/screens/LedgerSyncDeepLinkHandler.tsx diff --git a/apps/ledger-live-mobile/src/components/RootNavigator/types/WalletSyncNavigator.ts b/apps/ledger-live-mobile/src/components/RootNavigator/types/WalletSyncNavigator.ts index 3c235e807c66..83fb5ecf2683 100644 --- a/apps/ledger-live-mobile/src/components/RootNavigator/types/WalletSyncNavigator.ts +++ b/apps/ledger-live-mobile/src/components/RootNavigator/types/WalletSyncNavigator.ts @@ -2,6 +2,8 @@ import { TrustchainMember } from "@ledgerhq/trustchain/types"; import { ScreenName } from "~/const"; export type WalletSyncNavigatorStackParamList = { + [ScreenName.LedgerSyncDeepLinkHandler]: undefined; + [ScreenName.WalletSyncActivationInit]: undefined; [ScreenName.WalletSyncSuccess]: { diff --git a/apps/ledger-live-mobile/src/const/navigation.ts b/apps/ledger-live-mobile/src/const/navigation.ts index 18276c9d3d7b..a621351af992 100644 --- a/apps/ledger-live-mobile/src/const/navigation.ts +++ b/apps/ledger-live-mobile/src/const/navigation.ts @@ -520,6 +520,7 @@ export enum ScreenName { WalletSyncUnSynchSuccess = "WalletSyncUnSynchSuccess", WalletSyncManageInstancesProcess = "WalletSyncManageInstancesProcess", WalletSyncManageInstancesSuccess = "WalletSyncManageInstancesSuccess", + LedgerSyncDeepLinkHandler = "LedgerSyncDeepLinkHandler", MockedAddAssetButton = "MockedAddAssetButton", GenericLandingPage = "GenericLandingPage", diff --git a/apps/ledger-live-mobile/src/navigation/DeeplinksProvider.tsx b/apps/ledger-live-mobile/src/navigation/DeeplinksProvider.tsx index 3c8e694c21df..4698bb825333 100644 --- a/apps/ledger-live-mobile/src/navigation/DeeplinksProvider.tsx +++ b/apps/ledger-live-mobile/src/navigation/DeeplinksProvider.tsx @@ -359,6 +359,12 @@ const linkingOptions = () => ({ [ScreenName.GenericLandingPage]: "landing-page", }, }, + + [NavigatorName.WalletSync]: { + screens: { + [ScreenName.LedgerSyncDeepLinkHandler]: "ledgersync", + }, + }, }, }, }, diff --git a/apps/ledger-live-mobile/src/newArch/features/WalletSync/WalletSyncNavigator.tsx b/apps/ledger-live-mobile/src/newArch/features/WalletSync/WalletSyncNavigator.tsx index 4569adcf6a7c..a16759c17175 100644 --- a/apps/ledger-live-mobile/src/newArch/features/WalletSync/WalletSyncNavigator.tsx +++ b/apps/ledger-live-mobile/src/newArch/features/WalletSync/WalletSyncNavigator.tsx @@ -14,6 +14,7 @@ import { useTranslation } from "react-i18next"; import { WalletSyncManageKeyDeletionSuccess } from "./screens/ManageKey/DeletionSuccess"; import { ManageInstancesProcess } from "./screens/ManageInstances/ManageInstancesProcess"; import { WalletSyncManageInstanceDeletionSuccess } from "./screens/ManageInstances/DeletionSuccess"; +import { LedgerSyncDeepLinkHandler } from "./screens/LedgerSyncDeepLinkHandler"; import { NavigationHeaderCloseButton } from "~/components/NavigationHeaderCloseButton"; const Stack = createStackNavigator(); @@ -99,6 +100,14 @@ export default function WalletSyncNavigator() { headerLeft: () => null, }} /> + null, + }} + /> ); } diff --git a/apps/ledger-live-mobile/src/newArch/features/WalletSync/screens/LedgerSyncDeepLinkHandler.tsx b/apps/ledger-live-mobile/src/newArch/features/WalletSync/screens/LedgerSyncDeepLinkHandler.tsx new file mode 100644 index 000000000000..95f118a04497 --- /dev/null +++ b/apps/ledger-live-mobile/src/newArch/features/WalletSync/screens/LedgerSyncDeepLinkHandler.tsx @@ -0,0 +1,27 @@ +import { StackActions, useNavigation } from "@react-navigation/native"; +import { useEffect } from "react"; +import { useDispatch, useSelector } from "react-redux"; +import { trustchainSelector } from "@ledgerhq/trustchain/store"; +import { setLedgerSyncActivateDrawer } from "~/actions/walletSync"; +import { NavigatorName, ScreenName } from "~/const"; + +export function LedgerSyncDeepLinkHandler() { + const hasTrustchain = !!useSelector(trustchainSelector)?.rootId; + const navigation = useNavigation(); + const dispatch = useDispatch(); + + useEffect(() => { + if (hasTrustchain) { + const routeName = NavigatorName.WalletSync; + const screen = ScreenName.WalletSyncActivated; + navigation.dispatch(StackActions.replace(routeName, { screen })); + } else { + const routeName = NavigatorName.Settings; + const screen = ScreenName.GeneralSettings; + navigation.dispatch(StackActions.replace(routeName, { screen })); + dispatch(setLedgerSyncActivateDrawer(true)); + } + }, [hasTrustchain, navigation, dispatch]); + + return null; +} From e7e854974093bcb8a3e77792c2387496813eba88 Mon Sep 17 00:00:00 2001 From: Theophile Sandoz Date: Thu, 29 Aug 2024 09:43:22 +0200 Subject: [PATCH 4/4] Update change log --- .changeset/wise-brooms-enjoy.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/wise-brooms-enjoy.md diff --git a/.changeset/wise-brooms-enjoy.md b/.changeset/wise-brooms-enjoy.md new file mode 100644 index 000000000000..edcfcb92c926 --- /dev/null +++ b/.changeset/wise-brooms-enjoy.md @@ -0,0 +1,6 @@ +--- +"ledger-live-desktop": minor +"live-mobile": minor +--- + +Create the `/ledgersync` deeplink