Skip to content

Commit

Permalink
feat: migrate all entry screen, ctas to new add account (uncompleted …
Browse files Browse the repository at this point in the history
…v2) flow
  • Loading branch information
themooneer committed Dec 11, 2024
1 parent e764d7d commit 7edfd99
Show file tree
Hide file tree
Showing 16 changed files with 439 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -329,4 +331,7 @@ export type SwapNavigatorParamList = {
| ScreenName.SendSelectDevice
| ScreenName.SwapForm;
};
[NavigatorName.AssetSelection]?: Partial<
NavigatorScreenParams<AssetSelectionNavigatorParamsList>
>;
};
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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<AssetSelectionNavigatorParamsList, NavigatorName.AssetSelection>
>;

export default function Navigator() {
const { colors } = useTheme();
const route = useRoute();
const route = useRoute<NavigationProps["route"]>();

const { t } = useTranslation();
const hasClosedNetworkBanner = useSelector(hasClosedNetworkBannerSelector);

const { token } = route.params || {};

const onClose = useCallback(() => {
track("button_clicked", {
button: "Close",
Expand All @@ -44,6 +54,9 @@ export default function Navigator() {
...stackNavigationConfig,
gestureEnabled: Platform.OS === "ios",
}}
initialRouteName={
token ? ScreenName.AddAccountsTokenCurrencyDisclaimer : ScreenName.AddAccountsSelectCrypto
}
>
<Stack.Screen
name={ScreenName.AddAccountsSelectCrypto}
Expand All @@ -53,6 +66,9 @@ export default function Navigator() {
headerTitle: "",
headerRight: () => <NavigationHeaderCloseButtonAdvanced onClose={onClose} />,
}}
initialParams={{
...(route?.params || {}),
}}
/>

<Stack.Screen
Expand All @@ -70,6 +86,26 @@ export default function Navigator() {
</Flex>
),
}}
initialParams={{
...(route?.params || {}),
}}
/>
<Stack.Screen
name={ScreenName.AddAccountsTokenCurrencyDisclaimer}
component={TokenCurrencyDisclaimer}
initialParams={
token
? {
token,
}
: undefined
}
options={{
title: t("addAccounts.tokens.title"),
}}
initialParams={{
...(route?.params || {}),
}}
/>
</Stack.Navigator>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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, {
Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -143,7 +142,7 @@ export default function SelectCrypto({
<Text variant="h4" fontWeight="semiBold" mx={6} testID="receive-header-step1-title">
{t("transfer.receive.selectCrypto.title")}
</Text>
{list.length > 0 ? (
{list.length > 0 && loadingStatus === "success" ? (
<Flex flex={1} ml={6} mr={6} mt={3}>
<FilteredSearchBar
keys={SEARCH_KEYS}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import React, { useCallback } from "react";
import { Trans, useTranslation } from "react-i18next";
import { StyleSheet, View, SafeAreaView } from "react-native";
import { useSelector } from "react-redux";
import { findTokenAccountByCurrency } from "@ledgerhq/live-common/account/index";
import { CompositeScreenProps, useTheme } from "@react-navigation/native";
import { accountsSelector } from "~/reducers/accounts";
import CurrencyIcon from "~/components/CurrencyIcon";
import Button from "~/components/Button";
import Alert from "~/components/Alert";
import LText from "~/components/LText";
import { urls } from "~/utils/urls";
import { ScreenName, NavigatorName } from "~/const";
import { TrackScreen } from "~/analytics";
import {
StackNavigatorNavigation,
StackNavigatorProps,
} from "~/components/RootNavigator/types/helpers";
import { BaseNavigatorStackParamList } from "~/components/RootNavigator/types/BaseNavigator";
import { AssetSelectionNavigatorParamsList } from "../../types";

type Props = CompositeScreenProps<
StackNavigatorProps<
AssetSelectionNavigatorParamsList,
ScreenName.AddAccountsTokenCurrencyDisclaimer
>,
StackNavigatorProps<BaseNavigatorStackParamList>
>;

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<StackNavigatorNavigation<BaseNavigatorStackParamList>>().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 (
<SafeAreaView
style={[
styles.root,
{
backgroundColor: colors.background,
},
]}
>
<View style={styles.container}>
<TrackScreen
category="AddAccounts"
name="TokenCurrencyDisclaimer"
currencyName={tokenName}
/>
<View style={styles.wrapper}>
<CurrencyIcon size={56} radius={16} currency={token} />
</View>
<View style={[styles.wrapper, styles.spacer]}>
<LText secondary bold style={styles.tokenName}>
{tokenName}
</LText>
</View>
<View style={styles.disclaimerWrapper}>
<Alert
type="primary"
learnMoreUrl={
urls.supportLinkByTokenType[
token.tokenType as keyof typeof urls.supportLinkByTokenType
]
}
learnMoreKey={`addAccounts.tokens.generic.learnMore`}
learnMoreTransValues={{
tokenType: token.tokenType.toUpperCase(),
}}
>
<Trans
i18nKey={`addAccounts.tokens.generic.disclaimer`}
values={{
token: token.name,
ticker: token.ticker,
tokenType: token.tokenType.toUpperCase(),
currency: token.parentCurrency.name,
}}
/>
</Alert>
</View>
<View style={styles.buttonWrapper}>
<Button
event="AddAccountTokenDisclaimerClose"
title={t("common.close")}
type="secondary"
onPress={onClose}
containerStyle={[styles.buttonSpace]}
/>
<Button
event="AddAccountTokenDisclaimerBack"
title={
parentTokenAccount
? t("account.receive")
: t("addAccounts.tokens.createParentCurrencyAccount", {
parrentCurrencyName: token.parentCurrency.ticker,
})
}
type="primary"
onPress={onTokenCta}
containerStyle={styles.button}
/>
</View>
</View>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
root: {
flex: 1,
},
container: {
flex: 1,
padding: 16,
paddingTop: 32,
},
wrapper: {
justifyContent: "center",
alignItems: "center",
},
spacer: {
paddingTop: 16,
},
tokenName: {
fontSize: 18,
},
buttonWrapper: {
flexDirection: "row",
},
button: {
flex: 1,
},
buttonSpace: {
marginRight: 16,
flex: 0.5,
},
disclaimerWrapper: {
flex: 1,
paddingTop: 32,
},
});
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { CryptoCurrency, CryptoOrTokenCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
import { CryptoOrTokenCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
import { NavigatorScreenParams } from "@react-navigation/core";
import { NavigatorName, ScreenName } from "~/const";

import { DeviceSelectionNavigatorParamsList } from "../DeviceSelection/types";
import { NetworkBasedAddAccountNavigator } from "../Accounts/screens/AddAccount/types";
type CommpnParams = {
context?: "addAccounts" | "receiveFunds";
onSuccess?: () => void;
};
export type AssetSelectionNavigatorParamsList = {
[ScreenName.AddAccountsSelectCrypto]: {
[ScreenName.AddAccountsSelectCrypto]: CommpnParams & {
filterCurrencyIds?: string[];
currency?: string;
returnToSwap?: boolean;
analyticsPropertyFlow?: string;
};
[ScreenName.SelectNetwork]:
| {
Expand All @@ -15,18 +23,12 @@ export type AssetSelectionNavigatorParamsList = {
};
}
| undefined;
[NavigatorName.AddAccounts]: {
screen: ScreenName;
params: {
currency: CryptoCurrency | TokenCurrency;
createTokenAccount?: boolean;
};
};
[NavigatorName.DeviceSelection]: {
screen: ScreenName;
params: {
currency: CryptoCurrency;
createTokenAccount?: boolean;
};
[ScreenName.AddAccountsTokenCurrencyDisclaimer]: {
token: TokenCurrency;
analyticsPropertyFlow?: string;
};
[NavigatorName.DeviceSelection]?: Partial<
NavigatorScreenParams<DeviceSelectionNavigatorParamsList>
>;
[NavigatorName.AddAccounts]?: Partial<NavigatorScreenParams<NetworkBasedAddAccountNavigator>>;
};
Loading

0 comments on commit 7edfd99

Please sign in to comment.