Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a longer list of tokens #2331

Merged
merged 1 commit into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions app/components/UI/Swaps/components/TokenSelectModal.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback, useMemo, useRef, useState } from 'react';
import PropTypes from 'prop-types';
import { StyleSheet, TextInput, SafeAreaView, TouchableOpacity, View } from 'react-native';
import { StyleSheet, TextInput, SafeAreaView, TouchableOpacity, View, TouchableWithoutFeedback } from 'react-native';
import { FlatList } from 'react-native-gesture-handler';
import Modal from 'react-native-modal';
import Icon from 'react-native-vector-icons/Ionicons';
Expand Down Expand Up @@ -65,6 +65,8 @@ const styles = StyleSheet.create({
}
});

const MAX_TOKENS_RESULTS = 20;

function TokenSelectModal({
isVisible,
dismiss,
Expand All @@ -81,6 +83,7 @@ function TokenSelectModal({
balances
}) {
const searchInput = useRef(null);
const list = useRef();
const [searchString, setSearchString] = useState('');

const filteredTokens = useMemo(() => tokens?.filter(token => !excludeAddresses.includes(token.address)), [
Expand Down Expand Up @@ -108,7 +111,10 @@ function TokenSelectModal({
[filteredTokens]
);
const tokenSearchResults = useMemo(
() => (searchString.length > 0 ? tokenFuse.search(searchString)?.slice(0, 5) : filteredInitialTokens),
() =>
searchString.length > 0
? tokenFuse.search(searchString)?.slice(0, MAX_TOKENS_RESULTS)
: filteredInitialTokens,
[searchString, tokenFuse, filteredInitialTokens]
);

Expand Down Expand Up @@ -160,6 +166,11 @@ function TokenSelectModal({
[searchString]
);

const handleSearchTextChange = useCallback(text => {
setSearchString(text);
if (list.current) list.current.scrollToOffset({ animated: false, y: 0 });
}, []);

return (
<Modal
isVisible={isVisible}
Expand All @@ -177,18 +188,21 @@ function TokenSelectModal({
<Text bold centered primary style={styles.modalTitle}>
{title}
</Text>
<View style={styles.inputWrapper}>
<Icon name="ios-search" size={20} style={styles.searchIcon} onPress={handleSearchPress} />
<TextInput
ref={searchInput}
style={styles.input}
placeholder={strings('swaps.search_token')}
placeholderTextColor={colors.grey500}
value={searchString}
onChangeText={setSearchString}
/>
</View>
<TouchableWithoutFeedback onPress={handleSearchPress}>
<View style={styles.inputWrapper}>
<Icon name="ios-search" size={20} style={styles.searchIcon} />
<TextInput
ref={searchInput}
style={styles.input}
placeholder={strings('swaps.search_token')}
placeholderTextColor={colors.grey500}
value={searchString}
onChangeText={handleSearchTextChange}
/>
</View>
</TouchableWithoutFeedback>
<FlatList
ref={list}
style={styles.resultsView}
keyboardDismissMode="none"
keyboardShouldPersistTaps="always"
Expand Down
6 changes: 4 additions & 2 deletions app/components/UI/Swaps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ const styles = StyleSheet.create({

const SWAPS_ETH_ADDRESS = swapsUtils.ETH_SWAPS_TOKEN_ADDRESS;
const TOKEN_MINIMUM_SOURCES = 1;
const MAX_TOP_ASSETS = 20;

function SwapsAmountView({
swapsTokens,
accounts,
Expand Down Expand Up @@ -468,13 +470,13 @@ function SwapsAmountView({
dismiss={toggleDestinationModal}
title={strings('swaps.convert_to')}
tokens={swapsTokens}
initialTokens={[swapsUtils.ETH_SWAPS_TOKEN_OBJECT, ...tokensTopAssets.slice(0, 5)]}
initialTokens={[swapsUtils.ETH_SWAPS_TOKEN_OBJECT, ...tokensTopAssets.slice(0, MAX_TOP_ASSETS)]}
onItemPress={handleDestinationTokenPress}
excludeAddresses={[sourceToken?.address]}
/>
</View>
<View>
{Boolean(destinationToken) && destinationToken.symbol !== 'ETH' ? (
{Boolean(destinationToken) && destinationToken?.address !== SWAPS_ETH_ADDRESS ? (
destinationTokenHasEnoughOcurrances ? (
<TouchableOpacity onPress={handleVerifyPress} style={styles.verifyToken}>
<Text small centered>
Expand Down