Skip to content

Commit

Permalink
fix: fix the sort instead of reversing it
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmahidalgo committed Nov 28, 2023
1 parent f659b3f commit 021a0c2
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,19 @@ const ChainAndTokenSelector = (props: Props) => {
}, [currentChain, wallet.address])

const filteredTokens = useMemo(() => {
const filtered = tokens
?.filter(
token =>
token.symbol.toLowerCase().includes(search.toLowerCase()) &&
token.chainId === currentChain.toString()
)
.reverse()
const filtered = tokens?.filter(
token =>
token.symbol.toLowerCase().includes(search.toLowerCase()) &&
token.chainId === currentChain.toString()
)
// this sortes the tokens by USD balance
const sortedByBalance = filtered?.sort((a, b) => {
filtered?.sort((a, b) => {
const aQuote = balances[a.address.toLowerCase()]?.quote ?? '0'
const bQuote = balances[b.address.toLowerCase()]?.quote ?? '0'
if (aQuote === bQuote) return 0
return aQuote < bQuote ? 1 : -1
})
return sortedByBalance
return filtered
}, [tokens, search, currentChain, balances])

return (
Expand Down

0 comments on commit 021a0c2

Please sign in to comment.