From 7edfd995a87dbeaee2f21b9b75e5246493be38f5 Mon Sep 17 00:00:00 2001 From: Mounir Hamzaoui Date: Wed, 11 Dec 2024 18:15:03 +0100 Subject: [PATCH] feat: migrate all entry screen, ctas to new add account (uncompleted v2) flow --- .../FabActions/hooks/useAssetActions.tsx | 8 +- .../RootNavigator/types/SwapNavigator.ts | 7 +- .../features/AssetSelection/Navigator.tsx | 44 ++++- .../screens/SelectCrypto/index.tsx | 11 +- .../screens/TokenCurrencyDisclamer/index.tsx | 172 ++++++++++++++++++ .../newArch/features/AssetSelection/types.ts | 34 ++-- .../features/DeviceSelection/Navigator.tsx | 1 + .../Modals/InstalledAppModal.tsx | 14 +- .../screens/ReceiveFunds/02-SelectAccount.tsx | 35 ++-- .../RequestAccount/02-SelectAccount.tsx | 22 ++- .../src/screens/Swap/Form/Summary/index.tsx | 53 ++++-- .../screens/Swap/SubScreens/SelectAccount.tsx | 42 +++-- .../src/screens/WalletCentricAsset/index.tsx | 33 ++-- .../src/deposit/deposit.integration.test.ts | 32 +++- libs/ledger-live-common/src/deposit/type.ts | 5 + .../useGroupedCurrenciesByProvider.hook.ts | 26 ++- 16 files changed, 439 insertions(+), 100 deletions(-) create mode 100644 apps/ledger-live-mobile/src/newArch/features/AssetSelection/screens/TokenCurrencyDisclamer/index.tsx diff --git a/apps/ledger-live-mobile/src/components/FabActions/hooks/useAssetActions.tsx b/apps/ledger-live-mobile/src/components/FabActions/hooks/useAssetActions.tsx index 278b741daeb4..665c66e18cc1 100644 --- a/apps/ledger-live-mobile/src/components/FabActions/hooks/useAssetActions.tsx +++ b/apps/ledger-live-mobile/src/components/FabActions/hooks/useAssetActions.tsx @@ -38,6 +38,7 @@ export default function useAssetActions({ currency, accounts }: useAssetActionsP const { data: currenciesAll } = useFetchCurrencyAll(); const ptxServiceCtaScreens = useFeature("ptxServiceCtaScreens"); + const llmNetworkBasedAddAccountFlow = useFeature("llmNetworkBasedAddAccountFlow"); const { t } = useTranslation(); const stakeLabel = getStakeLabelLocaleBased(); @@ -226,11 +227,16 @@ export default function useAssetActions({ currency, accounts }: useAssetActionsP label: t("addAccountsModal.ctaAdd"), Icon: iconAddAccount, navigationParams: [ - NavigatorName.AddAccounts, + llmNetworkBasedAddAccountFlow?.enabled + ? NavigatorName.AssetSelection + : NavigatorName.AddAccounts, { screen: ScreenName.AddAccountsSelectCrypto, params: { filterCurrencyIds: currency ? [currency.id] : undefined, + ...(llmNetworkBasedAddAccountFlow?.enabled && { + context: "addAccounts", + }), }, }, ] as const, diff --git a/apps/ledger-live-mobile/src/components/RootNavigator/types/SwapNavigator.ts b/apps/ledger-live-mobile/src/components/RootNavigator/types/SwapNavigator.ts index fabdb2249ade..bb8e2fc187f1 100644 --- a/apps/ledger-live-mobile/src/components/RootNavigator/types/SwapNavigator.ts +++ b/apps/ledger-live-mobile/src/components/RootNavigator/types/SwapNavigator.ts @@ -44,7 +44,9 @@ import type { Transaction as CasperTransaction } from "@ledgerhq/live-common/fam import type { Transaction as TonTransaction } from "@ledgerhq/live-common/families/ton/types"; import BigNumber from "bignumber.js"; import { Account, Operation } from "@ledgerhq/types-live"; -import { ScreenName } from "~/const"; +import { NavigatorName, ScreenName } from "~/const"; +import { NavigatorScreenParams } from "@react-navigation/core"; +import { AssetSelectionNavigatorParamsList } from "~/newArch/features/AssetSelection/types"; type Target = "from" | "to"; @@ -329,4 +331,7 @@ export type SwapNavigatorParamList = { | ScreenName.SendSelectDevice | ScreenName.SwapForm; }; + [NavigatorName.AssetSelection]?: Partial< + NavigatorScreenParams + >; }; diff --git a/apps/ledger-live-mobile/src/newArch/features/AssetSelection/Navigator.tsx b/apps/ledger-live-mobile/src/newArch/features/AssetSelection/Navigator.tsx index 1a6cd42457fc..8f672d7b5b82 100644 --- a/apps/ledger-live-mobile/src/newArch/features/AssetSelection/Navigator.tsx +++ b/apps/ledger-live-mobile/src/newArch/features/AssetSelection/Navigator.tsx @@ -1,9 +1,9 @@ -import React, { useCallback, useMemo } from "react"; +import React, { useCallback, useEffect, useMemo } from "react"; import { Platform } from "react-native"; import { createStackNavigator } from "@react-navigation/stack"; import { useTheme } from "styled-components/native"; -import { useRoute } from "@react-navigation/native"; -import { ScreenName } from "~/const"; +import { useNavigation, useRoute } from "@react-navigation/native"; +import { NavigatorName, ScreenName } from "~/const"; import { getStackNavigatorConfig } from "~/navigation/navigatorConfig"; import { track } from "~/analytics"; import { Flex } from "@ledgerhq/native-ui"; @@ -16,13 +16,23 @@ import SelectNetwork from "LLM/features/AssetSelection/screens/SelectNetwork"; import { NavigationHeaderCloseButtonAdvanced } from "~/components/NavigationHeaderCloseButton"; import { NavigationHeaderBackButton } from "~/components/NavigationHeaderBackButton"; import { AssetSelectionNavigatorParamsList } from "./types"; +import { BaseComposite, StackNavigatorProps } from "~/components/RootNavigator/types/helpers"; +import TokenCurrencyDisclaimer from "./screens/TokenCurrencyDisclamer"; +import { useTranslation } from "react-i18next"; + +type NavigationProps = BaseComposite< + StackNavigatorProps +>; export default function Navigator() { const { colors } = useTheme(); - const route = useRoute(); + const route = useRoute(); + const { t } = useTranslation(); const hasClosedNetworkBanner = useSelector(hasClosedNetworkBannerSelector); + const { token } = route.params || {}; + const onClose = useCallback(() => { track("button_clicked", { button: "Close", @@ -44,6 +54,9 @@ export default function Navigator() { ...stackNavigationConfig, gestureEnabled: Platform.OS === "ios", }} + initialRouteName={ + token ? ScreenName.AddAccountsTokenCurrencyDisclaimer : ScreenName.AddAccountsSelectCrypto + } > , }} + initialParams={{ + ...(route?.params || {}), + }} /> ), }} + initialParams={{ + ...(route?.params || {}), + }} + /> + ); diff --git a/apps/ledger-live-mobile/src/newArch/features/AssetSelection/screens/SelectCrypto/index.tsx b/apps/ledger-live-mobile/src/newArch/features/AssetSelection/screens/SelectCrypto/index.tsx index 9e5bd36b0b15..2edd67f50994 100644 --- a/apps/ledger-live-mobile/src/newArch/features/AssetSelection/screens/SelectCrypto/index.tsx +++ b/apps/ledger-live-mobile/src/newArch/features/AssetSelection/screens/SelectCrypto/index.tsx @@ -50,7 +50,8 @@ export default function SelectCrypto({ const { t } = useTranslation(); const accounts = useSelector(flattenAccountsSelector); - const { currenciesByProvider, sortedCryptoCurrencies } = useGroupedCurrenciesByProvider(); + const { result, loadingStatus } = useGroupedCurrenciesByProvider(true); + const { currenciesByProvider, sortedCryptoCurrencies } = result; const onPressItem = useCallback( (curr: CryptoCurrency | TokenCurrency) => { @@ -64,7 +65,6 @@ export default function SelectCrypto({ currencyByNetwork => (currencyByNetwork as CryptoCurrency | TokenCurrency).id === curr.id, ), ); - // If the selected currency exists on multiple networks we redirect to the SelectNetwork screen if (provider && provider?.currenciesByNetwork.length > 1) { navigation.navigate(ScreenName.SelectNetwork, { @@ -103,12 +103,11 @@ export default function SelectCrypto({ useEffect(() => { if (paramsCurrency) { const selectedCurrency = findCryptoCurrencyByKeyword(paramsCurrency.toUpperCase()); - - if (selectedCurrency) { + if (selectedCurrency && loadingStatus === "success") { onPressItem(selectedCurrency); } } - }, [onPressItem, paramsCurrency]); + }, [onPressItem, paramsCurrency, loadingStatus]); const debounceTrackOnSearchChange = debounce((newQuery: string) => { track("asset_searched", { page: "Choose a crypto to secure", asset: newQuery }); @@ -143,7 +142,7 @@ export default function SelectCrypto({ {t("transfer.receive.selectCrypto.title")} - {list.length > 0 ? ( + {list.length > 0 && loadingStatus === "success" ? ( , + StackNavigatorProps +>; + +export default function TokenCurrencyDisclaimer({ navigation, route }: Props) { + const { colors } = useTheme(); + const { t } = useTranslation(); + const accounts = useSelector(accountsSelector); + const token = route.params.token; + const tokenName = `${token.name} (${token.ticker})`; + const parentCurrency = token.parentCurrency; + const accountData = findTokenAccountByCurrency(token, accounts); + const parentTokenAccount = accountData ? accountData.parentAccount : null; + const onClose = useCallback(() => { + navigation.getParent>().pop(); + }, [navigation]); + // specific cta in case of token accounts + const onTokenCta = useCallback(() => { + if (parentTokenAccount && parentTokenAccount.type === "Account") { + onClose(); + navigation.navigate(NavigatorName.ReceiveFunds, { + screen: ScreenName.ReceiveConfirmation, + params: { + // prefilter with token curency + accountId: parentTokenAccount.id, + currency: token, + createTokenAccount: true, + }, + }); + } else { + // set parentCurrency in already opened add account flow and continue + navigation.navigate(NavigatorName.DeviceSelection, { + screen: ScreenName.SelectDevice, + params: { + ...route.params, + currency: parentCurrency, + }, + }); + } + }, [parentTokenAccount, onClose, navigation, token, route.params, parentCurrency]); + return ( + + + + + + + + + {tokenName} + + + + + + + + +