Skip to content
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

Feature/llm card #7774

Merged
merged 8 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -299,6 +300,12 @@ export default function BaseNavigator() {
},
})}
/>
<Stack.Screen
name={NavigatorName.Card}
component={CardLiveAppNavigator}
options={{ headerShown: false }}
{...noNanoBuyNanoWallScreenOptions}
/>
<Stack.Screen
name={NavigatorName.Exchange}
component={ExchangeLiveAppNavigator}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React, { useMemo } from "react";
import { createStackNavigator } from "@react-navigation/stack";
import { useTheme } from "styled-components/native";
import { CARD_APP_ID } from "@ledgerhq/live-common/wallet-api/constants";
import { NavigatorName, ScreenName } from "~/const";
import { getStackNavigatorConfig } from "~/navigation/navigatorConfig";

import styles from "~/navigation/styles";
import type { StackNavigatorProps } from "./types/helpers";
import { PtxScreen } from "~/screens/PTX";
import { useTranslation } from "react-i18next";
import { PtxNavigatorParamList } from "~/components/RootNavigator/types/PtxNavigator";

const Stack = createStackNavigator<PtxNavigatorParamList>();

const Card = (_props: StackNavigatorProps<PtxNavigatorParamList, ScreenName.Card>) => {
sarneijim marked this conversation as resolved.
Show resolved Hide resolved
sarneijim marked this conversation as resolved.
Show resolved Hide resolved
const { t } = useTranslation();
const defaultPlatform = CARD_APP_ID;
return (
<PtxScreen
{..._props}
sarneijim marked this conversation as resolved.
Show resolved Hide resolved
config={{
screen: ScreenName.Card,
navigator: NavigatorName.Card,
btnText: t("browseWeb3.webPlatformPlayer.back.card"),
}}
route={{
..._props.route,
params: {
goToURL: _props.route.params?.goToURL,
lastScreen: _props.route.params?.lastScreen,
platform: _props.route.params?.platform || defaultPlatform,
sarneijim marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This piece is a little unclear to me, why are we spreading the route object but then assigning onto the params values from the object we just spread?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor this part of the code, ensuring that we only fill in parameters that have not been set.

sarneijim marked this conversation as resolved.
Show resolved Hide resolved
referrer: _props.route.params?.referrer,
},
}}
/>
);
};

export default function CardAppNavigator(_props?: Record<string, unknown>) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Also please update the type to use an actual type instead of Record<string, unknown>

const { colors } = useTheme();

const stackNavigationConfig = useMemo(() => getStackNavigatorConfig(colors, true), [colors]);
return (
<Stack.Navigator {...stackNavigationConfig}>
<Stack.Screen
name={ScreenName.Card}
options={{
headerStyle: styles.headerNoShadow,
title: "",
}}
>
{props => <Card {...props} />}
</Stack.Screen>
</Stack.Navigator>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,55 @@ 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 { PtxLiveAppNavigatorParamList } from "./types/PtxLiveAppNavigator";
import type { StackNavigatorProps } from "./types/helpers";
import { BuyAndSellScreen } from "~/screens/PTX/BuyAndSell";
import { PtxScreen } from "~/screens/PTX";

const Stack = createStackNavigator<ExchangeLiveAppNavigatorParamList>();
const Stack = createStackNavigator<PtxLiveAppNavigatorParamList>();

const ExchangeBuy = (
_props: StackNavigatorProps<ExchangeLiveAppNavigatorParamList, ScreenName.ExchangeBuy>,
) => {
const buySellUiFlag = useFeature("buySellUi");
const defaultPlatform = buySellUiFlag?.params?.manifestId || BUY_SELL_UI_APP_ID;
return (
<BuyAndSellScreen
{..._props}
route={{
..._props.route,
params: {
account: _props.route.params?.defaultAccountId,
currency: _props.route.params?.currency
? findCryptoCurrencyByKeyword(_props.route.params?.currency)?.id
: _props.route.params?.defaultCurrencyId,
goToURL: _props.route.params?.goToURL,
lastScreen: _props.route.params?.lastScreen,
mode: "buy",
platform: _props.route.params?.platform || defaultPlatform,
referrer: _props.route.params?.referrer,
},
}}
/>
);
};
const createExchangeScreen =
(screenName: ScreenName.ExchangeBuy | ScreenName.ExchangeSell) =>
(
_props: StackNavigatorProps<
sarneijim marked this conversation as resolved.
Show resolved Hide resolved
PtxLiveAppNavigatorParamList,
ScreenName.ExchangeBuy | ScreenName.ExchangeSell
>,
) => {
const buySellUiFlag = useFeature("buySellUi");
const { t } = useTranslation();
const defaultPlatform = buySellUiFlag?.params?.manifestId || BUY_SELL_UI_APP_ID;

const ExchangeSell = (
_props: StackNavigatorProps<ExchangeLiveAppNavigatorParamList, ScreenName.ExchangeSell>,
) => {
const buySellUiFlag = useFeature("buySellUi");
const defaultPlatform = buySellUiFlag?.params?.manifestId || BUY_SELL_UI_APP_ID;
return (
<BuyAndSellScreen
{..._props}
route={{
..._props.route,
params: {
account: _props.route.params?.defaultAccountId,
currency: _props.route.params?.currency
? findCryptoCurrencyByKeyword(_props.route.params?.currency)?.id
: _props.route.params?.defaultCurrencyId,
goToURL: _props.route.params?.goToURL,
lastScreen: _props.route.params?.lastScreen,
mode: "sell",
platform: _props.route.params?.platform || defaultPlatform,
referrer: _props.route.params?.referrer,
},
}}
/>
);
};
return (
<PtxScreen
{..._props}
config={{
screen: screenName,
navigator: NavigatorName.Exchange,
btnText: t("common.quote"),
}}
route={{
..._props.route,
params: {
account: _props.route.params?.defaultAccountId,
currency: _props.route.params?.currency
? findCryptoCurrencyByKeyword(_props.route.params?.currency)?.id
: _props.route.params?.defaultCurrencyId,
goToURL: _props.route.params?.goToURL,
lastScreen: _props.route.params?.lastScreen,
platform: _props.route.params?.platform || defaultPlatform,
sarneijim marked this conversation as resolved.
Show resolved Hide resolved
referrer: _props.route.params?.referrer,
},
}}
/>
);
};

const ExchangeBuy = createExchangeScreen(ScreenName.ExchangeBuy);
const ExchangeSell = createExchangeScreen(ScreenName.ExchangeSell);

export default function ExchangeLiveAppNavigator(_props?: Record<string, unknown>) {
const { colors } = useTheme();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 { PtxLiveAppNavigatorParamList } from "./PtxLiveAppNavigator";
import type { RequestAccountNavigatorParamList } from "./RequestAccountNavigator";
import type { AddAccountsNavigatorParamList } from "./AddAccountsNavigator";
import type { ClaimRewardsNavigatorParamList } from "./ClaimRewardsNavigator";
Expand Down Expand Up @@ -221,7 +221,8 @@ export type BaseNavigatorStackParamList = {
[NavigatorName.RequestAccount]: NavigatorScreenParams<RequestAccountNavigatorParamList> & {
onClose?: () => void;
};
[NavigatorName.Exchange]: NavigatorScreenParams<ExchangeLiveAppNavigatorParamList> | undefined;
[NavigatorName.Card]: NavigatorScreenParams<PtxLiveAppNavigatorParamList> | undefined;
[NavigatorName.Exchange]: NavigatorScreenParams<PtxLiveAppNavigatorParamList> | undefined;
sarneijim marked this conversation as resolved.
Show resolved Hide resolved
[NavigatorName.ExchangeStack]: NavigatorScreenParams<ExchangeStackNavigatorParamList> & {
mode?: "buy" | "sell";
};
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
};
sarneijim marked this conversation as resolved.
Show resolved Hide resolved

export type PtxLiveAppNavigatorParamList = {
[ScreenName.ExchangeBuy]?: ExchangeParams & {
parentId?: string;
};
[ScreenName.ExchangeSell]?: ExchangeParams;
[ScreenName.Card]?: CommonParams;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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;
};
sarneijim marked this conversation as resolved.
Show resolved Hide resolved

export type PtxNavigatorParamList = {
[ScreenName.ExchangeBuy]?: ExchangeParams;
[ScreenName.ExchangeSell]?: ExchangeParams;
[ScreenName.Card]?: CommonParams;
};
Loading
Loading