Skip to content

Commit

Permalink
fix: filter currencies by name (#7493)
Browse files Browse the repository at this point in the history
  • Loading branch information
farrah-deriv committed Mar 21, 2023
1 parent 636b0fe commit ccbc68e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/components/src/components/autocomplete/autocomplete.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,17 @@ const Autocomplete = React.memo(props => {

React.useEffect(() => {
if (has_updating_list) {
const new_filtered_items = is_list_visible ? getFilteredItems(value.toLowerCase(), list_items) : list_items;
let new_filtered_items = [];

if (is_list_visible) {
if (typeof props.onSearch === 'function') {
new_filtered_items = props.onSearch(value.toLowerCase(), list_items);
} else {
new_filtered_items = getFilteredItems(value.toLowerCase(), list_items);
}
} else {
new_filtered_items = list_items;
}

setFilteredItems(new_filtered_items);
if (historyValue) {
Expand Down Expand Up @@ -263,7 +273,13 @@ const Autocomplete = React.memo(props => {

const filterList = e => {
const val = e.target.value.toLowerCase();
const new_filtered_items = getFilteredItems(val, props.list_items, should_filter_by_char);
let new_filtered_items = [];

if (typeof props.onSearch === 'function') {
new_filtered_items = props.onSearch(val, props.list_items);
} else {
new_filtered_items = getFilteredItems(val, props.list_items, should_filter_by_char);
}

if (!new_filtered_items.length) {
setInputValue('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ const CurrencySelector = ({ className, default_value, list, onSelect }) => {
onItemSelection={({ value }) => {
if (value) onSelect?.(value);
}}
onSearch={(value, list_items) => {
return list_items.filter(
item =>
item.display_name.toLowerCase().includes(value) ||
item.text.toLowerCase().includes(value)
);
}}
placeholder={localize('Search')}
trailing_icon={
field.value ? (
Expand Down
1 change: 1 addition & 0 deletions packages/p2p/src/stores/buy-sell-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ export default class BuySellStore extends BaseStore {
</Text>
</div>
),
display_name,
has_adverts,
is_default,
text: symbol,
Expand Down

0 comments on commit ccbc68e

Please sign in to comment.