Skip to content

Commit

Permalink
Feature/llm card (#7774)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sarneijim authored Sep 16, 2024
1 parent 7a0bf37 commit 4b7aa70
Show file tree
Hide file tree
Showing 13 changed files with 257 additions and 198 deletions.
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>) => {
const { t } = useTranslation();
const { goToURL, lastScreen, platform, referrer } = props.route.params || {};
return (
<PtxScreen
{...props}
config={{
screen: ScreenName.Card,
navigator: NavigatorName.Card,
btnText: t("browseWeb3.webPlatformPlayer.back.card"),
}}
route={{
...props.route,
params: {
goToURL,
lastScreen,
platform: platform || CARD_APP_ID,
referrer,
},
}}
/>
);
};

export default function CardLiveAppNavigator() {
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,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<ExchangeLiveAppNavigatorParamList>();
const Stack = createStackNavigator<PtxNavigatorParamList>();

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<
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 (
<PtxScreen
{...props}
config={{
screen: screenName,
navigator: NavigatorName.Exchange,
btnText: t("common.quote"),
}}
route={{
...props.route,
params: {
account: defaultAccountId,
currency: resolvedCurrency,
goToURL,
lastScreen,
platform: platform || defaultPlatform,
referrer: referrer,
},
}}
/>
);
};

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,
},
}}
/>
);
};
const ExchangeBuy = createExchangeScreen(ScreenName.ExchangeBuy);
const ExchangeSell = createExchangeScreen(ScreenName.ExchangeSell);

export default function ExchangeLiveAppNavigator(_props?: Record<string, unknown>) {
export default function ExchangeLiveAppNavigator() {
const { colors } = useTheme();

const stackNavigationConfig = useMemo(() => getStackNavigatorConfig(colors, true), [colors]);
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 { PtxNavigatorParamList } from "./PtxNavigator";
import type { RequestAccountNavigatorParamList } from "./RequestAccountNavigator";
import type { AddAccountsNavigatorParamList } from "./AddAccountsNavigator";
import type { ClaimRewardsNavigatorParamList } from "./ClaimRewardsNavigator";
Expand Down Expand Up @@ -87,12 +87,10 @@ export type PathToDeviceParam = PropertyPath;
export type NavigationType = "navigate" | "replace" | "push";

export type BaseNavigatorStackParamList = {
[NavigatorName.Main]:
| (NavigatorScreenParams<MainNavigatorParamList> & {
hideTabNavigation?: boolean;
})
| undefined;
[NavigatorName.BuyDevice]: NavigatorScreenParams<BuyDeviceNavigatorParamList> | undefined;
[NavigatorName.Main]?: NavigatorScreenParams<MainNavigatorParamList> & {
hideTabNavigation?: boolean;
};
[NavigatorName.BuyDevice]?: NavigatorScreenParams<BuyDeviceNavigatorParamList>;
[ScreenName.NoDeviceWallScreen]: undefined;
[ScreenName.PostBuyDeviceSetupNanoWallScreen]: undefined;

Expand Down Expand Up @@ -186,7 +184,7 @@ export type BaseNavigatorStackParamList = {

[ScreenName.CurrencySettings]: {
currencyId: string;
headerTitle?: string | undefined;
headerTitle?: string;
};
[ScreenName.EditCurrencyUnits]: {
currency: CryptoCurrency;
Expand All @@ -197,43 +195,38 @@ export type BaseNavigatorStackParamList = {
};

[NavigatorName.Settings]: NavigatorScreenParams<SettingsNavigatorStackParamList>;
[NavigatorName.ReceiveFunds]: NavigatorScreenParams<ReceiveFundsStackParamList> | undefined;
[NavigatorName.ReceiveFunds]?: NavigatorScreenParams<ReceiveFundsStackParamList>;
[NavigatorName.SendFunds]: NavigatorScreenParams<SendFundsNavigatorStackParamList>;
[NavigatorName.SignMessage]: NavigatorScreenParams<SignMessageNavigatorStackParamList> & {
onClose?: () => void;
};
[NavigatorName.SignTransaction]: NavigatorScreenParams<SignTransactionNavigatorParamList>;
[NavigatorName.Swap]: NavigatorScreenParams<SwapNavigatorParamList> | undefined;
[NavigatorName.Earn]: NavigatorScreenParams<EarnLiveAppNavigatorParamList> | undefined;
[NavigatorName.Swap]?: NavigatorScreenParams<SwapNavigatorParamList>;
[NavigatorName.Earn]?: NavigatorScreenParams<EarnLiveAppNavigatorParamList>;
[NavigatorName.Freeze]: NavigatorScreenParams<FreezeNavigatorParamList>;
[NavigatorName.Unfreeze]: NavigatorScreenParams<UnfreezeNavigatorParamList>;
[NavigatorName.ClaimRewards]: NavigatorScreenParams<ClaimRewardsNavigatorParamList>;
[NavigatorName.AddAccounts]:
| (Partial<NavigatorScreenParams<AddAccountsNavigatorParamList>> & {
currency?: CryptoCurrency | TokenCurrency | null;
token?: TokenCurrency;
returnToSwap?: boolean;
analyticsPropertyFlow?: string;
onSuccess?: (account: AccountLike, parentAccount?: Account) => void;
onError?: (_: Error) => void;
})
| undefined;
[NavigatorName.AddAccounts]?: Partial<NavigatorScreenParams<AddAccountsNavigatorParamList>> & {
currency?: CryptoCurrency | TokenCurrency | null;
token?: TokenCurrency;
returnToSwap?: boolean;
analyticsPropertyFlow?: string;
onSuccess?: (account: AccountLike, parentAccount?: Account) => void;
onError?: (_: Error) => void;
};
[NavigatorName.RequestAccount]: NavigatorScreenParams<RequestAccountNavigatorParamList> & {
onClose?: () => void;
};
[NavigatorName.Exchange]: NavigatorScreenParams<ExchangeLiveAppNavigatorParamList> | undefined;
[NavigatorName.Card]?: NavigatorScreenParams<PtxNavigatorParamList>;
[NavigatorName.Exchange]?: NavigatorScreenParams<PtxNavigatorParamList>;
[NavigatorName.ExchangeStack]: NavigatorScreenParams<ExchangeStackNavigatorParamList> & {
mode?: "buy" | "sell";
};
[NavigatorName.PlatformExchange]: NavigatorScreenParams<PlatformExchangeNavigatorParamList>;
[NavigatorName.AccountSettings]: NavigatorScreenParams<AccountSettingsNavigatorParamList>;
[NavigatorName.ImportAccounts]:
| NavigatorScreenParams<ImportAccountsNavigatorParamList>
| undefined;
[NavigatorName.PasswordAddFlow]: NavigatorScreenParams<PasswordAddFlowParamList> | undefined;
[NavigatorName.PasswordModifyFlow]:
| NavigatorScreenParams<PasswordModifyFlowParamList>
| undefined;
[NavigatorName.ImportAccounts]?: NavigatorScreenParams<ImportAccountsNavigatorParamList>;
[NavigatorName.PasswordAddFlow]?: NavigatorScreenParams<PasswordAddFlowParamList>;
[NavigatorName.PasswordModifyFlow]?: NavigatorScreenParams<PasswordModifyFlowParamList>;
[NavigatorName.NotificationCenter]: NavigatorScreenParams<NotificationCenterNavigatorParamList>;
[NavigatorName.NftNavigator]: NavigatorScreenParams<NftNavigatorParamList>;
[NavigatorName.Accounts]: NavigatorScreenParams<AccountsNavigatorParamList>;
Expand Down Expand Up @@ -261,15 +254,13 @@ export type BaseNavigatorStackParamList = {
[NavigatorName.CeloLockFlow]: NavigatorScreenParams<CeloLockFlowParamList>;
[NavigatorName.CeloRegistrationFlow]: NavigatorScreenParams<CeloRegistrationFlowParamList>;
// 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<CosmosDelegationFlowParamList>;
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 4b7aa70

Please sign in to comment.