From f7e14a876043419fc3bde98d0818273d035471b3 Mon Sep 17 00:00:00 2001 From: Marco Toniut Date: Mon, 12 Aug 2024 15:41:08 +0100 Subject: [PATCH 1/2] feat/mobile: enable deep link to discover by category --- .../src/screens/Platform/v2/Catalog/index.tsx | 11 ++++++++++- .../src/screens/Platform/v2/hooks.ts | 5 +++-- libs/ledger-live-common/src/wallet-api/react.ts | 6 ++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/apps/ledger-live-mobile/src/screens/Platform/v2/Catalog/index.tsx b/apps/ledger-live-mobile/src/screens/Platform/v2/Catalog/index.tsx index 658e4f20ff03..b9012e87fd11 100644 --- a/apps/ledger-live-mobile/src/screens/Platform/v2/Catalog/index.tsx +++ b/apps/ledger-live-mobile/src/screens/Platform/v2/Catalog/index.tsx @@ -12,13 +12,22 @@ import { RecentlyUsed } from "./RecentlyUsed"; import { CatalogSection } from "./CatalogSection"; import { DAppDisclaimer } from "./DAppDisclaimer"; import { LocalLiveApp } from "./LocalLiveApp"; +import { useRoute } from "@react-navigation/native"; const AnimatedView = Animatable.View; export function Catalog() { const { t } = useTranslation(); const title = t("browseWeb3.catalog.title"); - const { categories, recentlyUsed, search, disclaimer, localLiveApps } = useCatalog(); + + const { params } = useRoute(); + + const deeplinkInitialCategory = + params && "category" in params && typeof params.category === "string" ? params.category : null; + + const { categories, recentlyUsed, search, disclaimer, localLiveApps } = + useCatalog(deeplinkInitialCategory); + return ( {/* TODO: put under the animation header and style */} diff --git a/apps/ledger-live-mobile/src/screens/Platform/v2/hooks.ts b/apps/ledger-live-mobile/src/screens/Platform/v2/hooks.ts index 96726048f72e..58d7b6e67e7b 100644 --- a/apps/ledger-live-mobile/src/screens/Platform/v2/hooks.ts +++ b/apps/ledger-live-mobile/src/screens/Platform/v2/hooks.ts @@ -5,6 +5,7 @@ import { useDisclaimerRaw, useRecentlyUsed, DisclaimerRaw, + Categories, } from "@ledgerhq/live-common/wallet-api/react"; import { useLocalLiveAppContext } from "@ledgerhq/live-common/wallet-api/LocalLiveAppProvider/index"; @@ -25,13 +26,13 @@ import { readOnlyModeEnabledSelector } from "../../../reducers/settings"; import { NavigationProps } from "./types"; import { useManifests } from "@ledgerhq/live-common/platform/providers/RemoteLiveAppProvider/index"; -export function useCatalog() { +export function useCatalog(initialCategory?: Categories["selected"] | null) { const recentlyUsedDB = useRecentlyUsedDB(); const { state: localLiveApps } = useLocalLiveAppContext(); const allManifests = useManifests(); const completeManifests = useManifests({ visibility: ["complete"] }); const combinedManifests = useManifests({ visibility: ["searchable", "complete"] }); - const categories = useCategories(completeManifests); + const categories = useCategories(completeManifests, initialCategory); const recentlyUsed = useRecentlyUsed(combinedManifests, recentlyUsedDB); const search = useSearch({ diff --git a/libs/ledger-live-common/src/wallet-api/react.ts b/libs/ledger-live-common/src/wallet-api/react.ts index ae2879d7f35e..e20b86e85043 100644 --- a/libs/ledger-live-common/src/wallet-api/react.ts +++ b/libs/ledger-live-common/src/wallet-api/react.ts @@ -797,8 +797,10 @@ export interface Categories { reset: () => void; } -export function useCategories(manifests): Categories { - const [selected, setSelected] = useState(DISCOVER_INITIAL_CATEGORY); +export type CategoryId = Categories["selected"]; + +export function useCategories(manifests, initialCategory?: CategoryId | null): Categories { + const [selected, setSelected] = useState(initialCategory || DISCOVER_INITIAL_CATEGORY); const reset = useCallback(() => { setSelected(DISCOVER_INITIAL_CATEGORY); From 641795937e14908ba9632a7b9744563b7e206be7 Mon Sep 17 00:00:00 2001 From: Marco Toniut Date: Mon, 12 Aug 2024 15:51:07 +0100 Subject: [PATCH 2/2] chore: changelog --- .changeset/soft-kings-live.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/soft-kings-live.md diff --git a/.changeset/soft-kings-live.md b/.changeset/soft-kings-live.md new file mode 100644 index 000000000000..51788c1338cf --- /dev/null +++ b/.changeset/soft-kings-live.md @@ -0,0 +1,6 @@ +--- +"live-mobile": minor +"@ledgerhq/live-common": minor +--- + +Add discover section deep link initial category filter to enable links like `ledgerlive://discover?category=restaking` to load the discover screen with the category pre-selected