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

🚦 [FEAT] Create the llmMarketQuickActions feature flag #7558

Merged
merged 6 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 7 additions & 0 deletions .changeset/tiny-socks-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@ledgerhq/types-live": minor
"live-mobile": minor
"@ledgerhq/live-common": minor
---

Create the llmMarketQuickActions feature flag
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { useNavigation } from "@react-navigation/native";
import { StackNavigationProp } from "@react-navigation/stack";
import React, { useMemo } from "react";
import { useTranslation } from "react-i18next";
import { QuickActionButtonProps, QuickActionList } from "@ledgerhq/native-ui";
import useQuickActions from "../../hooks/useQuickActions";

export const MarketQuickActions = () => {
const { t } = useTranslation();
const navigation = useNavigation<StackNavigationProp<Record<string, object | undefined>>>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const navigation = useNavigation<StackNavigationProp<Record<string, object | undefined>>>();
const navigation = useNavigation<StackNavigatorNavigation<BaseNavigatorStackParamList>>();

Should works :)

const { quickActionsList } = useQuickActions();

const quickActionsData: QuickActionButtonProps[] = useMemo(
() =>
QUICK_ACTIONS.flatMap(key => {
const action = quickActionsList[key];
if (!action) return [];

return {
variant: "small",
textVariant: "small",
Icon: action.icon,
children: t(QUICK_ACTION_DATA[key].name),
onPress: () => navigation.navigate(...(action.route as [string, object?])),
disabled: action.disabled,
};
}),
[quickActionsList, t, navigation],
);

return <QuickActionList data={quickActionsData} numColumns={5} id="asset_five_columns" />;
};

const QUICK_ACTIONS = ["SEND", "RECEIVE", "BUY", "SWAP", "STAKE"] as const;
const QUICK_ACTION_DATA = {
SEND: {
name: "portfolio.quickActions.send",
},
RECEIVE: {
name: "portfolio.quickActions.deposit",
},
BUY: {
name: "portfolio.quickActions.buy",
},
SWAP: {
name: "portfolio.quickActions.swap",
},
STAKE: {
name: "portfolio.quickActions.stake",
},
} as const;
Copy link
Member

Choose a reason for hiding this comment

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

Can we optimize this to only define once SEND, RECEIVE, etc...
I think that we can with something like keyof typeof.
Otherwise, maybe we can do Object.keys(QUICK_ACTION_DATA) to iterate on options.
wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I did this but it required an extra type casting because the Object keys and entries functions type def always collapse the type of the key to string.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { memo, useMemo, useState } from "react";
import { useTheme } from "styled-components/native";
import FeatureToggle from "@ledgerhq/live-common/featureFlags/FeatureToggle";
import { Flex, ScrollContainerHeader, Text } from "@ledgerhq/native-ui";
import { FlatList, Image, RefreshControl } from "react-native";
import { useTranslation } from "react-i18next";
Expand All @@ -17,6 +18,7 @@ import MarketGraph from "./components/MarketGraph";
import { ScreenName } from "~/const";
import { withDiscreetMode } from "~/context/DiscreetModeContext";
import { FabMarketActions } from "~/components/FabActions/actionsList/market";
import { MarketQuickActions } from "~/components/MarketQuickActions";
import BackButton from "./components/BackButton";
import { Item } from "~/components/Graph/types";
import {
Expand Down Expand Up @@ -138,13 +140,18 @@ function View({
</Flex>

{internalCurrency ? (
<Flex mb={6}>
<FabMarketActions
defaultAccount={defaultAccount}
currency={internalCurrency}
accounts={accounts}
/>
</Flex>
<FeatureToggle
featureId="llmMarketQuickActions"
fallback={
<Flex mb={6}>
<FabMarketActions
defaultAccount={defaultAccount}
currency={internalCurrency}
accounts={accounts}
/>
</Flex>
}
/>
) : null}
</>
}
Expand All @@ -166,6 +173,10 @@ function View({
currency={internalCurrency}
/>

<FeatureToggle featureId="llmMarketQuickActions">
<MarketQuickActions />
</FeatureToggle>

{accounts?.length > 0 ? (
<Flex mx={6} mt={8}>
<Text variant="h3">{t("accounts.title")}</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ export const DEFAULT_FEATURES: Features = {
lldnewArchOrdinals: DEFAULT_FEATURE,
enableAppsBackup: DEFAULT_FEATURE,
web3hub: DEFAULT_FEATURE,
llmMarketQuickActions: DEFAULT_FEATURE,
};

// Firebase SDK treat JSON values as strings
Expand Down
1 change: 1 addition & 0 deletions libs/ledgerjs/packages/types-live/src/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export type Features = CurrencyFeatures & {
lldnewArchOrdinals: DefaultFeature;
enableAppsBackup: Feature_EnableAppsBackup;
web3hub: Feature_web3hub;
llmMarketQuickActions: DefaultFeature;
};

/**
Expand Down
Loading