From 4b7aa70d5a4d7f0b7ab6c2b4c8b14b0205fafa32 Mon Sep 17 00:00:00 2001 From: sarneijim <38540290+sarneijim@users.noreply.github.com> Date: Mon, 16 Sep 2024 10:21:39 +0100 Subject: [PATCH] Feature/llm card (#7774) * feat: add llm card * refactor: refactor naming * refactor: fix some pr comments (_props, extra dependencies, defaultManifest, undefined type) * refactor: pr comments multiSet and other small changes * refactor: unify ptxApp types * refactor: remove extra setBtnText * refactor: remove extra _props type --- .../RootNavigator/BaseNavigator.tsx | 7 ++ .../RootNavigator/CardLiveAppNavigator.tsx | 57 +++++++++ .../ExchangeLiveAppNavigator.tsx | 109 +++++++++--------- .../RootNavigator/types/BaseNavigator.ts | 67 +++++------ .../types/ExchangeLiveAppNavigator.ts | 35 ------ .../RootNavigator/types/ExchangeNavigator.ts | 34 ------ .../RootNavigator/types/PtxNavigator.ts | 25 ++++ .../src/components/WebPTXPlayer/index.tsx | 68 +++++++---- .../src/const/navigation.ts | 2 + .../src/hooks/useQuickActions.ts | 4 +- .../src/locales/en/common.json | 3 + .../screens/PTX/{BuyAndSell => }/index.tsx | 26 ++++- .../src/screens/Portfolio/Header.tsx | 18 ++- 13 files changed, 257 insertions(+), 198 deletions(-) create mode 100644 apps/ledger-live-mobile/src/components/RootNavigator/CardLiveAppNavigator.tsx delete mode 100644 apps/ledger-live-mobile/src/components/RootNavigator/types/ExchangeLiveAppNavigator.ts delete mode 100644 apps/ledger-live-mobile/src/components/RootNavigator/types/ExchangeNavigator.ts create mode 100644 apps/ledger-live-mobile/src/components/RootNavigator/types/PtxNavigator.ts rename apps/ledger-live-mobile/src/screens/PTX/{BuyAndSell => }/index.tsx (87%) diff --git a/apps/ledger-live-mobile/src/components/RootNavigator/BaseNavigator.tsx b/apps/ledger-live-mobile/src/components/RootNavigator/BaseNavigator.tsx index 53f15b944be0..42491d9234ac 100644 --- a/apps/ledger-live-mobile/src/components/RootNavigator/BaseNavigator.tsx +++ b/apps/ledger-live-mobile/src/components/RootNavigator/BaseNavigator.tsx @@ -30,6 +30,7 @@ import UnfreezeNavigator from "./UnfreezeNavigator"; import ClaimRewardsNavigator from "./ClaimRewardsNavigator"; import AddAccountsNavigator from "./AddAccountsNavigator"; import ExchangeLiveAppNavigator from "./ExchangeLiveAppNavigator"; +import CardLiveAppNavigator from "./CardLiveAppNavigator"; import EarnLiveAppNavigator from "./EarnLiveAppNavigator"; import PlatformExchangeNavigator from "./PlatformExchangeNavigator"; import AccountSettingsNavigator from "./AccountSettingsNavigator"; @@ -299,6 +300,12 @@ export default function BaseNavigator() { }, })} /> + (); + +const Card = (props: StackNavigatorProps) => { + const { t } = useTranslation(); + const { goToURL, lastScreen, platform, referrer } = props.route.params || {}; + return ( + + ); +}; + +export default function CardLiveAppNavigator() { + const { colors } = useTheme(); + + const stackNavigationConfig = useMemo(() => getStackNavigatorConfig(colors, true), [colors]); + return ( + + + {props => } + + + ); +} diff --git a/apps/ledger-live-mobile/src/components/RootNavigator/ExchangeLiveAppNavigator.tsx b/apps/ledger-live-mobile/src/components/RootNavigator/ExchangeLiveAppNavigator.tsx index 6df75f1c7751..c4ff3d5039fe 100644 --- a/apps/ledger-live-mobile/src/components/RootNavigator/ExchangeLiveAppNavigator.tsx +++ b/apps/ledger-live-mobile/src/components/RootNavigator/ExchangeLiveAppNavigator.tsx @@ -4,69 +4,66 @@ import { useTheme } from "styled-components/native"; import { findCryptoCurrencyByKeyword } from "@ledgerhq/live-common/currencies/index"; import { BUY_SELL_UI_APP_ID } from "@ledgerhq/live-common/wallet-api/constants"; import { useFeature } from "@ledgerhq/live-common/featureFlags/index"; -import { ScreenName } from "~/const"; +import { NavigatorName, ScreenName } from "~/const"; import { getStackNavigatorConfig } from "~/navigation/navigatorConfig"; - +import { useTranslation } from "react-i18next"; import styles from "~/navigation/styles"; -import type { ExchangeLiveAppNavigatorParamList } from "./types/ExchangeLiveAppNavigator"; +import type { PtxNavigatorParamList } from "./types/PtxNavigator"; import type { StackNavigatorProps } from "./types/helpers"; -import { BuyAndSellScreen } from "~/screens/PTX/BuyAndSell"; +import { PtxScreen } from "~/screens/PTX"; -const Stack = createStackNavigator(); +const Stack = createStackNavigator(); -const ExchangeBuy = ( - _props: StackNavigatorProps, -) => { - const buySellUiFlag = useFeature("buySellUi"); - const defaultPlatform = buySellUiFlag?.params?.manifestId || BUY_SELL_UI_APP_ID; - return ( - - ); -}; +const createExchangeScreen = + (screenName: ScreenName.ExchangeBuy | ScreenName.ExchangeSell) => + ( + props: StackNavigatorProps< + PtxNavigatorParamList, + ScreenName.ExchangeBuy | ScreenName.ExchangeSell + >, + ) => { + const buySellUiFlag = useFeature("buySellUi"); + const { t } = useTranslation(); + const defaultPlatform = buySellUiFlag?.params?.manifestId || BUY_SELL_UI_APP_ID; + const { + defaultAccountId, + currency, + defaultCurrencyId, + goToURL, + lastScreen, + platform, + referrer, + } = props.route.params || {}; + const resolvedCurrency = currency + ? findCryptoCurrencyByKeyword(currency)?.id + : defaultCurrencyId; + return ( + + ); + }; -const ExchangeSell = ( - _props: StackNavigatorProps, -) => { - const buySellUiFlag = useFeature("buySellUi"); - const defaultPlatform = buySellUiFlag?.params?.manifestId || BUY_SELL_UI_APP_ID; - return ( - - ); -}; +const ExchangeBuy = createExchangeScreen(ScreenName.ExchangeBuy); +const ExchangeSell = createExchangeScreen(ScreenName.ExchangeSell); -export default function ExchangeLiveAppNavigator(_props?: Record) { +export default function ExchangeLiveAppNavigator() { const { colors } = useTheme(); const stackNavigationConfig = useMemo(() => getStackNavigatorConfig(colors, true), [colors]); diff --git a/apps/ledger-live-mobile/src/components/RootNavigator/types/BaseNavigator.ts b/apps/ledger-live-mobile/src/components/RootNavigator/types/BaseNavigator.ts index 01e464ad4ecd..23d29b95bc67 100644 --- a/apps/ledger-live-mobile/src/components/RootNavigator/types/BaseNavigator.ts +++ b/apps/ledger-live-mobile/src/components/RootNavigator/types/BaseNavigator.ts @@ -33,7 +33,7 @@ import type { SwapNavigatorParamList } from "./SwapNavigator"; import type { EarnLiveAppNavigatorParamList } from "./EarnLiveAppNavigator"; import type { PlatformExchangeNavigatorParamList } from "./PlatformExchangeNavigator"; import type { ExchangeStackNavigatorParamList } from "./ExchangeStackNavigator"; -import type { ExchangeLiveAppNavigatorParamList } from "./ExchangeLiveAppNavigator"; +import type { PtxNavigatorParamList } from "./PtxNavigator"; import type { RequestAccountNavigatorParamList } from "./RequestAccountNavigator"; import type { AddAccountsNavigatorParamList } from "./AddAccountsNavigator"; import type { ClaimRewardsNavigatorParamList } from "./ClaimRewardsNavigator"; @@ -87,12 +87,10 @@ export type PathToDeviceParam = PropertyPath; export type NavigationType = "navigate" | "replace" | "push"; export type BaseNavigatorStackParamList = { - [NavigatorName.Main]: - | (NavigatorScreenParams & { - hideTabNavigation?: boolean; - }) - | undefined; - [NavigatorName.BuyDevice]: NavigatorScreenParams | undefined; + [NavigatorName.Main]?: NavigatorScreenParams & { + hideTabNavigation?: boolean; + }; + [NavigatorName.BuyDevice]?: NavigatorScreenParams; [ScreenName.NoDeviceWallScreen]: undefined; [ScreenName.PostBuyDeviceSetupNanoWallScreen]: undefined; @@ -186,7 +184,7 @@ export type BaseNavigatorStackParamList = { [ScreenName.CurrencySettings]: { currencyId: string; - headerTitle?: string | undefined; + headerTitle?: string; }; [ScreenName.EditCurrencyUnits]: { currency: CryptoCurrency; @@ -197,43 +195,38 @@ export type BaseNavigatorStackParamList = { }; [NavigatorName.Settings]: NavigatorScreenParams; - [NavigatorName.ReceiveFunds]: NavigatorScreenParams | undefined; + [NavigatorName.ReceiveFunds]?: NavigatorScreenParams; [NavigatorName.SendFunds]: NavigatorScreenParams; [NavigatorName.SignMessage]: NavigatorScreenParams & { onClose?: () => void; }; [NavigatorName.SignTransaction]: NavigatorScreenParams; - [NavigatorName.Swap]: NavigatorScreenParams | undefined; - [NavigatorName.Earn]: NavigatorScreenParams | undefined; + [NavigatorName.Swap]?: NavigatorScreenParams; + [NavigatorName.Earn]?: NavigatorScreenParams; [NavigatorName.Freeze]: NavigatorScreenParams; [NavigatorName.Unfreeze]: NavigatorScreenParams; [NavigatorName.ClaimRewards]: NavigatorScreenParams; - [NavigatorName.AddAccounts]: - | (Partial> & { - currency?: CryptoCurrency | TokenCurrency | null; - token?: TokenCurrency; - returnToSwap?: boolean; - analyticsPropertyFlow?: string; - onSuccess?: (account: AccountLike, parentAccount?: Account) => void; - onError?: (_: Error) => void; - }) - | undefined; + [NavigatorName.AddAccounts]?: Partial> & { + currency?: CryptoCurrency | TokenCurrency | null; + token?: TokenCurrency; + returnToSwap?: boolean; + analyticsPropertyFlow?: string; + onSuccess?: (account: AccountLike, parentAccount?: Account) => void; + onError?: (_: Error) => void; + }; [NavigatorName.RequestAccount]: NavigatorScreenParams & { onClose?: () => void; }; - [NavigatorName.Exchange]: NavigatorScreenParams | undefined; + [NavigatorName.Card]?: NavigatorScreenParams; + [NavigatorName.Exchange]?: NavigatorScreenParams; [NavigatorName.ExchangeStack]: NavigatorScreenParams & { mode?: "buy" | "sell"; }; [NavigatorName.PlatformExchange]: NavigatorScreenParams; [NavigatorName.AccountSettings]: NavigatorScreenParams; - [NavigatorName.ImportAccounts]: - | NavigatorScreenParams - | undefined; - [NavigatorName.PasswordAddFlow]: NavigatorScreenParams | undefined; - [NavigatorName.PasswordModifyFlow]: - | NavigatorScreenParams - | undefined; + [NavigatorName.ImportAccounts]?: NavigatorScreenParams; + [NavigatorName.PasswordAddFlow]?: NavigatorScreenParams; + [NavigatorName.PasswordModifyFlow]?: NavigatorScreenParams; [NavigatorName.NotificationCenter]: NavigatorScreenParams; [NavigatorName.NftNavigator]: NavigatorScreenParams; [NavigatorName.Accounts]: NavigatorScreenParams; @@ -261,15 +254,13 @@ export type BaseNavigatorStackParamList = { [NavigatorName.CeloLockFlow]: NavigatorScreenParams; [NavigatorName.CeloRegistrationFlow]: NavigatorScreenParams; // This is not a navigator - [NavigatorName.CeloManageAssetsNavigator]: - | { - params?: { - account?: AccountLike; - accountId?: string | null; - parentId?: string | null; - }; - } - | undefined; + [NavigatorName.CeloManageAssetsNavigator]: { + params?: { + account?: AccountLike; + accountId?: string | null; + parentId?: string | null; + }; + }; // Cosmos [NavigatorName.CosmosDelegationFlow]: NavigatorScreenParams; diff --git a/apps/ledger-live-mobile/src/components/RootNavigator/types/ExchangeLiveAppNavigator.ts b/apps/ledger-live-mobile/src/components/RootNavigator/types/ExchangeLiveAppNavigator.ts deleted file mode 100644 index 11c527a2830f..000000000000 --- a/apps/ledger-live-mobile/src/components/RootNavigator/types/ExchangeLiveAppNavigator.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { ScreenName } from "~/const"; - -export type ExchangeLiveAppNavigatorParamList = { - [ScreenName.ExchangeBuy]: - | { - account?: string; - currency?: string; // Used for the deeplink only - defaultAccountId?: string; - defaultCurrencyId?: string; - defaultTicker?: string; - goToURL?: string; - lastScreen?: string; - mode?: string; - name?: string; - parentId?: string; - platform?: string; - referrer?: string; - } - | undefined; - [ScreenName.ExchangeSell]: - | { - account?: string; - currency?: string; // Used for the deeplink only - defaultAccountId?: string; - defaultCurrencyId?: string; - defaultTicker?: string; - goToURL?: string; - lastScreen?: string; - platform?: string; - mode?: string; - name?: string; - referrer?: string; - } - | undefined; -}; diff --git a/apps/ledger-live-mobile/src/components/RootNavigator/types/ExchangeNavigator.ts b/apps/ledger-live-mobile/src/components/RootNavigator/types/ExchangeNavigator.ts deleted file mode 100644 index e634fe5fe9d9..000000000000 --- a/apps/ledger-live-mobile/src/components/RootNavigator/types/ExchangeNavigator.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { ScreenName } from "~/const"; - -export type ExchangeNavigatorParamList = { - [ScreenName.ExchangeBuy]: - | { - account?: string; - currency?: string; // Used for the deeplink only - defaultAccountId?: string; - defaultCurrencyId?: string; - defaultTicker?: string; - goToURL?: string; - lastScreen?: string; - mode?: string; - name?: string; - platform?: string; - referrer?: string; - } - | undefined; - [ScreenName.ExchangeSell]: - | { - account?: string; - currency?: string; // Used for the deeplink only - defaultAccountId?: string; - defaultCurrencyId?: string; - defaultTicker?: string; - goToURL?: string; - lastScreen?: string; - mode?: string; - name?: string; - platform?: string; - referrer?: string; - } - | undefined; -}; diff --git a/apps/ledger-live-mobile/src/components/RootNavigator/types/PtxNavigator.ts b/apps/ledger-live-mobile/src/components/RootNavigator/types/PtxNavigator.ts new file mode 100644 index 000000000000..d8d9e6e7b61d --- /dev/null +++ b/apps/ledger-live-mobile/src/components/RootNavigator/types/PtxNavigator.ts @@ -0,0 +1,25 @@ +import { ScreenName } from "~/const"; + +type CommonParams = { + goToURL?: string; + lastScreen?: string; + name?: string; + platform?: string; + referrer?: string; +}; + +type ExchangeParams = CommonParams & { + account?: string; + currency?: string; // Used for the deeplink only + defaultAccountId?: string; + defaultCurrencyId?: string; + defaultTicker?: string; +}; + +export type PtxNavigatorParamList = { + [ScreenName.ExchangeBuy]?: ExchangeParams & { + parentId?: string; + }; + [ScreenName.ExchangeSell]?: ExchangeParams; + [ScreenName.Card]?: CommonParams; +}; diff --git a/apps/ledger-live-mobile/src/components/WebPTXPlayer/index.tsx b/apps/ledger-live-mobile/src/components/WebPTXPlayer/index.tsx index f919df4a785b..1411d81e656d 100644 --- a/apps/ledger-live-mobile/src/components/WebPTXPlayer/index.tsx +++ b/apps/ledger-live-mobile/src/components/WebPTXPlayer/index.tsx @@ -37,27 +37,26 @@ type BackToInternalDomainProps = { manifest: AppManifest; webviewURL?: string; lastMatchingURL?: string | null; + config: { + screen: ScreenName.ExchangeBuy | ScreenName.ExchangeSell | ScreenName.Card; + navigator: NavigatorName.Exchange | NavigatorName.Card; + btnText: string; + }; }; function BackToInternalDomain({ manifest, webviewURL, lastMatchingURL, + config, }: BackToInternalDomainProps) { const { t } = useTranslation(); + const { screen, navigator, btnText } = config; const navigation = useNavigation>>(); - const [buttonText, setButtonText] = useState(""); const internalAppIds = useInternalAppIds() || INTERNAL_APP_IDS; - useEffect(() => { - (async () => { - const lastScreen = (await AsyncStorage.getItem("last-screen")) || ""; - setButtonText(lastScreen === "compare_providers" ? t("common.quote") : manifest.name); - })(); - }, [manifest.id, manifest.name, t]); - const handleBackClick = async () => { const manifestId = (await AsyncStorage.getItem("manifest-id")) || ""; @@ -71,8 +70,8 @@ function BackToInternalDomain({ flow: flowName, }); - navigation.navigate(NavigatorName.Exchange, { - screen: flowName === "buy" ? ScreenName.ExchangeBuy : ScreenName.ExchangeSell, + navigation.navigate(navigator, { + screen, params: { referrer: "isExternal", }, @@ -99,7 +98,7 @@ function BackToInternalDomain({ - {t("common.backTo", { to: buttonText })} + {t("common.backTo", { to: btnText })} @@ -117,9 +116,29 @@ type Props = { manifest: LiveAppManifest; inputs?: Record; disableHeader?: boolean; + config?: + | { + screen: ScreenName.ExchangeBuy | ScreenName.ExchangeSell; + navigator: NavigatorName.Exchange; + btnText: string; + } + | { + screen: ScreenName.Card; + navigator: NavigatorName.Card; + btnText: string; + }; }; -export const WebPTXPlayer = ({ manifest, inputs, disableHeader }: Props) => { +export const WebPTXPlayer = ({ + manifest, + inputs, + disableHeader, + config = { + screen: ScreenName.ExchangeSell, + btnText: manifest.name, + navigator: NavigatorName.Exchange, + }, +}: Props) => { const lastMatchingURL = useRef(null); const webviewAPIRef = useRef(null); const [webviewState, setWebviewState] = useState(initialWebviewState); @@ -153,14 +172,18 @@ export const WebPTXPlayer = ({ manifest, inputs, disableHeader }: Props) => { const manifestId = url.searchParams.get("goToManifest"); if (manifestId && goToURL) { - const flowName = url.searchParams.get("flowName") || "buy"; - - await AsyncStorage.setItem("manifest-id", manifestId); - await AsyncStorage.setItem("flow-name", flowName); - await AsyncStorage.setItem("last-screen", url.searchParams.get("lastScreen") || ""); - - navigation.navigate(NavigatorName.Exchange, { - screen: flowName === "buy" ? ScreenName.ExchangeBuy : ScreenName.ExchangeSell, + const searchParams = url.searchParams; + const flowName = searchParams.get("flowName") || ""; + const lastScreen = searchParams.get("lastScreen") || flowName; + + await AsyncStorage.multiSet([ + ["manifest-id", manifestId], + ["flow-name", flowName], + ["last-screen", lastScreen], + ]); + + navigation.navigate(config.navigator, { + screen: config.screen, params: { platform: manifestId, goToURL, @@ -176,7 +199,7 @@ export const WebPTXPlayer = ({ manifest, inputs, disableHeader }: Props) => { lastMatchingURL.current = webviewState.url; } })(); - }, [isInternalApp, navigation, webviewState.url]); + }, [config.navigator, config.screen, isInternalApp, navigation, webviewState.url]); const handleHardwareBackPress = useCallback(() => { const webview = safeGetRefValue(webviewAPIRef); @@ -231,12 +254,13 @@ export const WebPTXPlayer = ({ manifest, inputs, disableHeader }: Props) => { manifest={manifest} webviewURL={webviewState?.url} lastMatchingURL={lastMatchingURL?.current} + config={config} /> ), headerTitle: () => null, }); } - }, [manifest, navigation, webviewState, isInternalApp, disableHeader, onClose]); + }, [config, disableHeader, isInternalApp, manifest, navigation, onClose, webviewState?.url]); const customHandlers = usePTXCustomHandlers(manifest); diff --git a/apps/ledger-live-mobile/src/const/navigation.ts b/apps/ledger-live-mobile/src/const/navigation.ts index a621351af992..0238012debab 100644 --- a/apps/ledger-live-mobile/src/const/navigation.ts +++ b/apps/ledger-live-mobile/src/const/navigation.ts @@ -77,6 +77,7 @@ export enum ScreenName { DisplayResult = "DisplayResult", EditAccountName = "EditAccountName", EditDeviceName = "EditDeviceName", + Card = "Card", Exchange = "Exchange", ExchangeBuy = "ExchangeBuy", ExchangeHistory = "ExchangeHistory", @@ -541,6 +542,7 @@ export enum NavigatorName { AccountSettings = "AccountSettings", AddAccounts = "AddAccounts", Analytics = "Analytics", + Card = "CardFlow", Exchange = "Exchange", ExchangeStack = "ExchangeStack", Base = "Base", diff --git a/apps/ledger-live-mobile/src/hooks/useQuickActions.ts b/apps/ledger-live-mobile/src/hooks/useQuickActions.ts index 1a57a7e99dec..14d4e80bc091 100644 --- a/apps/ledger-live-mobile/src/hooks/useQuickActions.ts +++ b/apps/ledger-live-mobile/src/hooks/useQuickActions.ts @@ -104,7 +104,7 @@ function useQuickActions({ currency, accounts }: QuickActionProps = {}) { NavigatorName.Exchange, { screen: ScreenName.ExchangeBuy, - params: { mode: "buy", defaultCurrencyId: currency?.id }, + params: { defaultCurrencyId: currency?.id }, }, ], icon: IconsLegacy.PlusMedium, @@ -118,7 +118,7 @@ function useQuickActions({ currency, accounts }: QuickActionProps = {}) { NavigatorName.Exchange, { screen: ScreenName.ExchangeSell, - params: { mode: "sell", defaultCurrencyId: currency?.id }, + params: { defaultCurrencyId: currency?.id }, }, ], icon: IconsLegacy.MinusMedium, diff --git a/apps/ledger-live-mobile/src/locales/en/common.json b/apps/ledger-live-mobile/src/locales/en/common.json index 9bae1018da45..e0e14763c1ba 100644 --- a/apps/ledger-live-mobile/src/locales/en/common.json +++ b/apps/ledger-live-mobile/src/locales/en/common.json @@ -6261,6 +6261,9 @@ "webPlatformPlayer": { "infoPanel": { "website": "website" + }, + "back": { + "card": "all cards" } } }, diff --git a/apps/ledger-live-mobile/src/screens/PTX/BuyAndSell/index.tsx b/apps/ledger-live-mobile/src/screens/PTX/index.tsx similarity index 87% rename from apps/ledger-live-mobile/src/screens/PTX/BuyAndSell/index.tsx rename to apps/ledger-live-mobile/src/screens/PTX/index.tsx index 2765bf2dc313..248b91a742c4 100644 --- a/apps/ledger-live-mobile/src/screens/PTX/BuyAndSell/index.tsx +++ b/apps/ledger-live-mobile/src/screens/PTX/index.tsx @@ -14,9 +14,9 @@ import { Flex, InfiniteLoader } from "@ledgerhq/native-ui"; import TrackScreen from "~/analytics/TrackScreen"; import GenericErrorView from "~/components/GenericErrorView"; import { WebPTXPlayer } from "~/components/WebPTXPlayer"; -import { ExchangeNavigatorParamList } from "~/components/RootNavigator/types/ExchangeNavigator"; +import { PtxNavigatorParamList } from "~/components/RootNavigator/types/PtxNavigator"; import { StackNavigatorProps } from "~/components/RootNavigator/types/helpers"; -import { ScreenName } from "~/const"; +import { ScreenName, NavigatorName } from "~/const"; import { accountsSelector } from "~/reducers/accounts"; import { useInternalAppIds } from "@ledgerhq/live-common/hooks/useInternalAppIds"; import { INTERNAL_APP_IDS, WALLET_API_VERSION } from "@ledgerhq/live-common/wallet-api/constants"; @@ -26,13 +26,25 @@ import { counterValueCurrencySelector } from "~/reducers/settings"; import { useSettings } from "~/hooks"; export type Props = StackNavigatorProps< - ExchangeNavigatorParamList, - ScreenName.ExchangeBuy | ScreenName.ExchangeSell ->; + PtxNavigatorParamList, + ScreenName.ExchangeBuy | ScreenName.ExchangeSell | ScreenName.Card +> & { + config?: + | { + screen: ScreenName.ExchangeBuy | ScreenName.ExchangeSell; + navigator: NavigatorName.Exchange; + btnText: string; + } + | { + screen: ScreenName.Card; + navigator: NavigatorName.Card; + btnText: string; + }; +}; const appManifestNotFoundError = new Error("App not found"); // FIXME move this elsewhere. -export function BuyAndSellScreen({ route }: Props) { +export function PtxScreen({ route, config }: Props) { const accounts = useSelector(accountsSelector); const devMode = useEnv("MANAGER_DEV_MODE").toString(); const { theme } = useTheme(); @@ -55,6 +67,7 @@ export function BuyAndSellScreen({ route }: Props) { */ const customParams = useMemo(() => { if ( + "account" in params && params?.account && manifest?.apiVersion && semver.satisfies(WALLET_API_VERSION, manifest.apiVersion) @@ -107,6 +120,7 @@ export function BuyAndSellScreen({ route }: Props) { ...customParams, ...Object.fromEntries(searchParams.entries()), }} + config={config} /> ) : ( diff --git a/apps/ledger-live-mobile/src/screens/Portfolio/Header.tsx b/apps/ledger-live-mobile/src/screens/Portfolio/Header.tsx index a948ac4399de..b2663daf7612 100644 --- a/apps/ledger-live-mobile/src/screens/Portfolio/Header.tsx +++ b/apps/ledger-live-mobile/src/screens/Portfolio/Header.tsx @@ -1,6 +1,7 @@ import React, { useCallback, useMemo } from "react"; import { useNavigation } from "@react-navigation/native"; import { Flex, Text } from "@ledgerhq/native-ui"; +import { useFeature } from "@ledgerhq/live-common/featureFlags/index"; import { CardMedium, SettingsMedium, WalletConnectMedium } from "@ledgerhq/native-ui/assets/icons"; import { useTranslation } from "react-i18next"; import { useTheme } from "styled-components/native"; @@ -48,6 +49,7 @@ function PortfolioHeader({ hidePortfolio }: { hidePortfolio: boolean }) { const navigation = useNavigation(); const { t } = useTranslation(); + const ptxCardFlag = useFeature("ptxCard"); const onNavigate = useCallback( (name: string, options?: object) => { @@ -76,11 +78,17 @@ function PortfolioHeader({ hidePortfolio }: { hidePortfolio: boolean }) { }, [navigation]); const onSideImageCardButtonPress = useCallback(() => { - navigation.navigate(ScreenName.PlatformApp, { - platform: "cl-card", - name: "CL Card Powered by Ledger", - }); - }, [navigation]); + if (ptxCardFlag?.enabled) { + navigation.navigate(NavigatorName.Card, { + screen: ScreenName.Card, + }); + } else { + navigation.navigate(ScreenName.PlatformApp, { + platform: "cl-card", + name: "CL Card Powered by Ledger", + }); + } + }, [navigation, ptxCardFlag]); return (