UNPKG

@lifi/widget

Version:

LI.FI Widget for cross-chain bridging and swapping. It will drive your multi-chain strategy and attract new users from everywhere.

43 lines (37 loc) 1.1 kB
import type { TokenAmount } from '../../types/token.js' export const filteredTokensComparator = (searchFilter: string) => { const isExactMatch = (token: TokenAmount) => { return ( token.name?.toUpperCase() === searchFilter || token.symbol.toUpperCase() === searchFilter || token.address.toUpperCase() === searchFilter ) } return (tokenA: TokenAmount, tokenB: TokenAmount) => { const isExactMatchA = isExactMatch(tokenA) const isExactMatchB = isExactMatch(tokenB) // Exact match with logo if (isExactMatchB && tokenB.logoURI) { return 1 } if (isExactMatchA && tokenA.logoURI) { return -1 } // Any token with a logo (exact match or not) if (tokenB.logoURI && !tokenA.logoURI) { return 1 } if (tokenA.logoURI && !tokenB.logoURI) { return -1 } // Exact match without logo if (isExactMatchB && !tokenB.logoURI) { return 1 } if (isExactMatchA && !tokenA.logoURI) { return -1 } // All other tokens are considered equal in sorting priority return 0 } }