Skip to content
This repository has been archived by the owner on Jun 16, 2022. It is now read-only.

Commit

Permalink
LL-8169 (Swap): fix add account flow issue
Browse files Browse the repository at this point in the history
  • Loading branch information
LFBarreto committed Dec 20, 2021
1 parent b9768c7 commit cc3d0d6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
13 changes: 10 additions & 3 deletions src/screens/AddAccounts/01-SelectCrypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
15 changes: 8 additions & 7 deletions src/screens/Swap2/FormSelection/SelectAccountScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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,
},
Expand All @@ -116,21 +117,21 @@ 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(() => {
navigation.navigate(NavigatorName.AddAccounts, {
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 => {
Expand Down

0 comments on commit cc3d0d6

Please sign in to comment.