From cc3d0d634a8e7fb6c2e785cdaad2b4105d449587 Mon Sep 17 00:00:00 2001 From: LFBarreto Date: Mon, 20 Dec 2021 16:44:21 +0100 Subject: [PATCH] LL-8169 (Swap): fix add account flow issue --- src/screens/AddAccounts/01-SelectCrypto.js | 13 ++++++++++--- .../Swap2/FormSelection/SelectAccountScreen.js | 15 ++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/screens/AddAccounts/01-SelectCrypto.js b/src/screens/AddAccounts/01-SelectCrypto.js index 3bdcb85e97..9299323221 100644 --- a/src/screens/AddAccounts/01-SelectCrypto.js +++ b/src/screens/AddAccounts/01-SelectCrypto.js @@ -26,7 +26,7 @@ const SEARCH_KEYS = ["name", "ticker"]; type Props = { devMode: boolean, navigation: any, - route: { params: * }, + route: { params: { filterCurrencyIds?: string[] } }, }; const keyExtractor = currency => currency.id; @@ -44,9 +44,16 @@ const listSupportedTokens = () => export default function AddAccountsSelectCrypto({ navigation, route }: Props) { const { colors } = useTheme(); + const { filterCurrencyIds = [] } = route.params; const cryptoCurrencies = useMemo( - () => listSupportedCurrencies().concat(listSupportedTokens()), - [], + () => + listSupportedCurrencies() + .concat(listSupportedTokens()) + .filter( + ({ id }) => + filterCurrencyIds.length <= 0 || filterCurrencyIds.includes(id), + ), + [filterCurrencyIds], ); const sortedCryptoCurrencies = useCurrenciesByMarketcap(cryptoCurrencies); diff --git a/src/screens/Swap2/FormSelection/SelectAccountScreen.js b/src/screens/Swap2/FormSelection/SelectAccountScreen.js index 70fd28f3ef..6411d92536 100644 --- a/src/screens/Swap2/FormSelection/SelectAccountScreen.js +++ b/src/screens/Swap2/FormSelection/SelectAccountScreen.js @@ -42,6 +42,7 @@ type Props = { export default function SelectAccount({ navigation, route }: Props) { const { colors } = useTheme(); const { swap, target, selectedCurrency, setAccount, provider } = route.params; + const unfilteredAccounts = useSelector(accountsSelector); const selectableCurrencies = useSelector(swapSelectableCurrenciesSelector); @@ -101,7 +102,7 @@ export default function SelectAccount({ navigation, route }: Props) { swap: { ...route.params.swap, from: { - ...route.params.swap.from, + ...(route.params.swap?.from || {}), account, parentAccount: null, }, @@ -116,7 +117,7 @@ export default function SelectAccount({ navigation, route }: Props) { ); const elligibleAccountsForSelectedCurrency = allAccounts.filter(account => - isFrom ? account.balance.gt(0) : swap.from.account?.id !== account.id, + isFrom ? account.balance.gt(0) : swap.from?.account?.id !== account.id, ); const onAddAccount = useCallback(() => { @@ -124,13 +125,13 @@ export default function SelectAccount({ navigation, route }: Props) { screen: ScreenName.AddAccountsSelectCrypto, params: { returnToSwap: true, - onSuccess: () => - navigation.navigate(ScreenName.SwapV2FormSelectAccount, { - params: route.params, - }), + filterCurrencyIds: selectableCurrencies, + onSuccess: () => { + navigation.navigate(ScreenName.SwapV2FormSelectAccount, route.params); + }, }, }); - }, [navigation, route.params]); + }, [navigation, route.params, selectableCurrencies]); const renderList = useCallback( items => {