Skip to content

Commit

Permalink
Merge branch 'develop' into yomo-759
Browse files Browse the repository at this point in the history
  • Loading branch information
jorbuedo authored Sep 14, 2023
2 parents b5af097 + 0a15ace commit a2d0982
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, {FunctionComponent} from 'react'
import {Icon} from '../../../../components'

export const PoolIcon = ({providerId, size}: {providerId: Pool['provider']; size: number}) => {
const IconVariant = icons[providerId]
const IconVariant = icons[providerId] ?? Icon.Swap
return <IconVariant size={size} />
}

Expand Down
25 changes: 9 additions & 16 deletions apps/wallet-mobile/src/features/Swap/common/filterBySearch.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
import {Balance} from '@yoroi/types'

export const filterBySearch = (searchTerm: string) => {
const searchTermLowerCase = searchTerm.toLocaleLowerCase()
if (searchTermLowerCase.length === 0) return () => true
const search = normalizeString(searchTerm)
if (search.length === 0) return () => true

return (tokenInfo: Balance.TokenInfo) => {
if (tokenInfo.kind === 'ft') {
return (
(tokenInfo.ticker?.toLocaleLowerCase()?.includes(searchTermLowerCase) ||
tokenInfo.name?.toLocaleLowerCase()?.includes(searchTermLowerCase)) ??
false
)
}
return (asset: {ticker?: string; name?: string; symbol?: string}) => {
const name = normalizeString(asset.name ?? '')
const ticker = normalizeString(asset.ticker ?? '')
const symbol = normalizeString(asset.symbol ?? '')

if (tokenInfo.kind === 'nft') {
return tokenInfo.name?.toLocaleLowerCase().includes(searchTermLowerCase) ?? false
}
return false
return ticker.includes(search) || name.includes(search) || symbol.includes(search)
}
}

const normalizeString = (str: string) => str.toLocaleLowerCase().replace(/\s/g, '')
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {useAllTokenInfos, useBalance} from '../../../../../../../yoroi-wallets/h
import {Quantities} from '../../../../../../../yoroi-wallets/utils'
import {filterByFungibility} from '../../../../../../Send/common/filterByFungibility'
import {NoAssetFoundImage} from '../../../../../../Send/common/NoAssetFoundImage'
import {filterBySearch} from '../../../../../common/filterBySearch'
import {useNavigateTo} from '../../../../../common/navigation'
import {useStrings} from '../../../../../common/strings'
import {useSwapTouched} from '../../../../../common/SwapFormProvider'
Expand Down Expand Up @@ -131,7 +132,7 @@ const TokenList = () => {
)

const filteredTransformedList = React.useMemo(() => {
return transformedArray.filter(filterTokensPairBySearch(assetSearchTerm))
return transformedArray.filter(filterBySearch(assetSearchTerm))
}, [transformedArray, assetSearchTerm])

return (
Expand Down Expand Up @@ -268,17 +269,6 @@ const EmptySearchResult = ({assetSearchTerm}: {assetSearchTerm: string}) => {
)
}

export const filterTokensPairBySearch = (searchTerm: string) => {
const searchTermLowerCase = searchTerm.toLocaleLowerCase()
if (searchTermLowerCase.length === 0) return () => true

return (tokenInfo: TransformedObject) => {
return (
tokenInfo.name?.toLocaleLowerCase().replace(/\s/g, '').includes(searchTermLowerCase.replace(/\s/g, '')) ?? false
)
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
Expand Down

0 comments on commit a2d0982

Please sign in to comment.