Skip to content

Commit

Permalink
Merge pull request #4628 from LedgerHQ/feat/llm-wallet-quick-actions
Browse files Browse the repository at this point in the history
Feat/llm wallet quick actions
  • Loading branch information
KVNLS authored Sep 11, 2023
2 parents 8b09b0b + d1d0977 commit 834febb
Show file tree
Hide file tree
Showing 15 changed files with 357 additions and 152 deletions.
6 changes: 6 additions & 0 deletions .changeset/perfect-shrimps-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"live-mobile": minor
"@ledgerhq/native-ui": minor
---

[LIVE-8347] Add quick actions on the wallet
2 changes: 1 addition & 1 deletion apps/ledger-live-mobile/ios/ledgerlivemobile/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>3.16.1</string>
<string>3.29.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ export const FabAccountMainActionsComponent: React.FC<FabAccountActionsProps> =
<QuickActionList
data={quickActions}
numColumns={2}
key={"two_columns"}
keyExtractor={(_item, index) => "two_columns_" + index}
id="two_columns"
key="two_columns"
/>
) : (
<QuickActionList
data={quickActions}
numColumns={3}
key={"three_columns"}
keyExtractor={(_item, index) => "three_columns_" + index}
id="three_columns"
key="three_columns"
/>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ const FabAssetActionsComponent: React.FC<Props> = ({ currency, accounts, default
<QuickActionList
data={quickActions}
numColumns={2}
key={"asset_two_columns"}
keyExtractor={(_item, index) => "asset_two_columns_" + index}
id="asset_two_columns"
key="asset_two_columns"
/>
) : (
<QuickActionList
data={quickActions}
numColumns={3}
key={"asset_three_columns"}
keyExtractor={(_item, index) => "asset_three_columns_" + index}
id="asset_three_columns"
key="asset_three_columns"
/>
)}
</>
Expand Down
129 changes: 32 additions & 97 deletions apps/ledger-live-mobile/src/components/TabBar/TransferDrawer.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import React, { useCallback, useMemo } from "react";
import { useNavigation, useRoute } from "@react-navigation/native";
import { useNavigation } from "@react-navigation/native";
import { useTranslation } from "react-i18next";
import { useSelector } from "react-redux";
import { ScrollView } from "react-native-gesture-handler";
import { Flex, IconsLegacy, Text, Box } from "@ledgerhq/native-ui";
import { Flex, Text, Box } from "@ledgerhq/native-ui";
import { StyleProp, ViewStyle } from "react-native";
import { snakeCase } from "lodash";
import { StackNavigationProp } from "@react-navigation/stack";
import { IconType } from "@ledgerhq/native-ui/components/Icon/type";
import useFeature from "@ledgerhq/live-common/featureFlags/useFeature";
import { NavigatorName, ScreenName } from "../../const";
import { accountsCountSelector, areAccountsEmptySelector } from "../../reducers/accounts";
import { NavigatorName } from "../../const";
import { hasOrderedNanoSelector, readOnlyModeEnabledSelector } from "../../reducers/settings";
import { Props as ModalProps } from "../QueuedDrawer";
import TransferButton from "../TransferButton";
import BuyDeviceBanner, { IMAGE_PROPS_SMALL_NANO } from "../BuyDeviceBanner";
import SetupDeviceBanner from "../SetupDeviceBanner";
import { track, useAnalytics } from "../../analytics";
import { sharedSwapTracking } from "../../screens/Swap/utils";
import { useToasts } from "@ledgerhq/live-common/notifications/ToastProvider/index";
import useQuickActions from "../../hooks/useQuickActions";
import { PTX_SERVICES_TOAST_ID } from "../../constants";

type ButtonItem = {
Expand All @@ -37,19 +36,16 @@ type ButtonItem = {

export default function TransferDrawer({ onClose }: Omit<ModalProps, "isRequestingToBeOpened">) {
const navigation = useNavigation();
const route = useRoute();
const {
quickActionsList: { SEND, RECEIVE, BUY, SELL, SWAP, STAKE, WALLET_CONNECT },
} = useQuickActions();
const { t } = useTranslation();
const { pushToast, dismissToast } = useToasts();

const { page, track } = useAnalytics();
const { page } = useAnalytics();

const readOnlyModeEnabled = useSelector(readOnlyModeEnabledSelector);
const accountsCount: number = useSelector(accountsCountSelector);
const hasOrderedNano = useSelector(hasOrderedNanoSelector);
const areAccountsEmpty = useSelector(areAccountsEmptySelector);

const walletConnectEntryPoint = useFeature("walletConnectEntryPoint");
const stakePrograms = useFeature("stakePrograms");

const ptxServiceCtaExchangeDrawer = useFeature("ptxServiceCtaExchangeDrawer");

Expand All @@ -64,64 +60,11 @@ export default function TransferDrawer({ onClose }: Omit<ModalProps, "isRequesti
name,
options,
);

if (onClose) {
onClose();
}
onClose?.();
},
[navigation, onClose],
);

const onSendFunds = useCallback(
() =>
onNavigate(NavigatorName.SendFunds, {
screen: ScreenName.SendCoin,
}),
[onNavigate],
);
const onReceiveFunds = useCallback(() => onNavigate(NavigatorName.ReceiveFunds), [onNavigate]);

const onStake = useCallback(() => {
track("button_clicked", {
button: "exchange",
page,
flow: "stake",
});
onNavigate(NavigatorName.StakeFlow, {
screen: ScreenName.Stake,
params: { parentRoute: route },
});
}, [onNavigate, page, track, route]);

const onWalletConnect = useCallback(
() =>
onNavigate(NavigatorName.WalletConnect, {
screen: ScreenName.WalletConnectConnect,
}),
[onNavigate],
);

const onSwap = useCallback(() => {
track("button_clicked", {
...sharedSwapTracking,
button: "swap",
page,
});
onNavigate(NavigatorName.Swap, {
screen: ScreenName.SwapForm,
});
}, [onNavigate, page, track]);

const onBuy = useCallback(
() => onNavigate(NavigatorName.Exchange, { screen: ScreenName.ExchangeBuy }),
[onNavigate],
);

const onSell = useCallback(
() => onNavigate(NavigatorName.Exchange, { screen: ScreenName.ExchangeSell }),
[onNavigate],
);

const buttonsList: ButtonItem[] = [
{
eventProperties: {
Expand All @@ -131,9 +74,9 @@ export default function TransferDrawer({ onClose }: Omit<ModalProps, "isRequesti
},
title: t("transfer.send.title"),
description: t("transfer.send.description"),
onPress: accountsCount > 0 && !readOnlyModeEnabled && !areAccountsEmpty ? onSendFunds : null,
Icon: IconsLegacy.ArrowTopMedium,
disabled: !accountsCount || readOnlyModeEnabled || areAccountsEmpty,
onPress: () => onNavigate(...SEND.route),
Icon: SEND.icon,
disabled: SEND.disabled,
testID: "transfer-send-button",
},
{
Expand All @@ -144,9 +87,9 @@ export default function TransferDrawer({ onClose }: Omit<ModalProps, "isRequesti
},
title: t("transfer.receive.title"),
description: t("transfer.receive.description"),
onPress: onReceiveFunds,
Icon: IconsLegacy.ArrowBottomMedium,
disabled: readOnlyModeEnabled,
onPress: () => onNavigate(...RECEIVE.route),
Icon: RECEIVE.icon,
disabled: RECEIVE.disabled,
testID: "transfer-receive-button",
},
{
Expand All @@ -158,8 +101,8 @@ export default function TransferDrawer({ onClose }: Omit<ModalProps, "isRequesti
title: t("transfer.buy.title"),
description: t("transfer.buy.description"),
tag: t("common.popular"),
Icon: IconsLegacy.PlusMedium,
onPress: onBuy,
Icon: BUY.icon,
onPress: () => onNavigate(...BUY.route),
onDisabledPress: () => {
if (isPtxServiceCtaExchangeDrawerDisabled) {
onClose?.();
Expand All @@ -172,7 +115,7 @@ export default function TransferDrawer({ onClose }: Omit<ModalProps, "isRequesti
});
}
},
disabled: isPtxServiceCtaExchangeDrawerDisabled || readOnlyModeEnabled,
disabled: BUY.disabled,
testID: "transfer-receive-button",
},
{
Expand All @@ -183,8 +126,8 @@ export default function TransferDrawer({ onClose }: Omit<ModalProps, "isRequesti
},
title: t("transfer.sell.title"),
description: t("transfer.sell.description"),
Icon: IconsLegacy.MinusMedium,
onPress: accountsCount > 0 && !readOnlyModeEnabled && !areAccountsEmpty ? onSell : null,
Icon: SELL.icon,
onPress: () => onNavigate(...SELL.route),
onDisabledPress: () => {
if (isPtxServiceCtaExchangeDrawerDisabled) {
onClose?.();
Expand All @@ -197,15 +140,11 @@ export default function TransferDrawer({ onClose }: Omit<ModalProps, "isRequesti
});
}
},
disabled:
isPtxServiceCtaExchangeDrawerDisabled ||
!accountsCount ||
readOnlyModeEnabled ||
areAccountsEmpty,
disabled: SELL.disabled,
testID: "transfer-sell-button",
},

...(stakePrograms?.enabled
...(STAKE
? [
{
eventProperties: {
Expand All @@ -215,9 +154,9 @@ export default function TransferDrawer({ onClose }: Omit<ModalProps, "isRequesti
},
title: t("transfer.stake.title"),
description: t("transfer.stake.description"),
Icon: IconsLegacy.ClaimRewardsMedium,
onPress: onStake,
disabled: readOnlyModeEnabled,
Icon: STAKE.icon,
onPress: () => onNavigate(...STAKE.route),
disabled: STAKE.disabled,
testID: "transfer-stake-button",
},
]
Expand All @@ -230,8 +169,8 @@ export default function TransferDrawer({ onClose }: Omit<ModalProps, "isRequesti
},
title: t("transfer.swap.title"),
description: t("transfer.swap.description"),
Icon: IconsLegacy.BuyCryptoMedium,
onPress: accountsCount > 0 && !readOnlyModeEnabled && !areAccountsEmpty ? onSwap : null,
Icon: SWAP.icon,
onPress: () => onNavigate(...SWAP.route),
onDisabledPress: () => {
if (isPtxServiceCtaExchangeDrawerDisabled) {
onClose?.();
Expand All @@ -244,15 +183,11 @@ export default function TransferDrawer({ onClose }: Omit<ModalProps, "isRequesti
});
}
},
disabled:
isPtxServiceCtaExchangeDrawerDisabled ||
!accountsCount ||
readOnlyModeEnabled ||
areAccountsEmpty,
disabled: SWAP.disabled,
testID: "swap-transfer-button",
},

...(walletConnectEntryPoint?.enabled
...(WALLET_CONNECT
? [
{
eventProperties: {
Expand All @@ -262,9 +197,9 @@ export default function TransferDrawer({ onClose }: Omit<ModalProps, "isRequesti
},
title: t("transfer.walletConnect.title"),
description: t("transfer.walletConnect.description"),
Icon: IconsLegacy.WalletConnectMedium,
onPress: onWalletConnect,
disabled: readOnlyModeEnabled,
Icon: WALLET_CONNECT.icon,
onPress: () => onNavigate(...WALLET_CONNECT.route),
disabled: WALLET_CONNECT.disabled,
testID: "transfer-walletconnect-button",
},
]
Expand Down
Loading

1 comment on commit 834febb

@vercel
Copy link

@vercel vercel bot commented on 834febb Sep 11, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.