From 8d383767276aa0231f6b1278db97accad78e880e Mon Sep 17 00:00:00 2001 From: jorbuedo Date: Wed, 13 Sep 2023 14:49:32 +0200 Subject: [PATCH 1/4] Add default PoolIcon --- .../src/features/Swap/common/PoolIcon/PoolIcon.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/wallet-mobile/src/features/Swap/common/PoolIcon/PoolIcon.tsx b/apps/wallet-mobile/src/features/Swap/common/PoolIcon/PoolIcon.tsx index b70b2e21a4..0222312b3a 100644 --- a/apps/wallet-mobile/src/features/Swap/common/PoolIcon/PoolIcon.tsx +++ b/apps/wallet-mobile/src/features/Swap/common/PoolIcon/PoolIcon.tsx @@ -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 } From 178da45ff81b129be605c9e27af481ecb96799eb Mon Sep 17 00:00:00 2001 From: Michal Date: Wed, 13 Sep 2023 15:37:35 +0100 Subject: [PATCH 2/4] fix(swap): Omit spaces when searching for an asset to sell --- .../src/features/Swap/common/filterBySearch.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/apps/wallet-mobile/src/features/Swap/common/filterBySearch.ts b/apps/wallet-mobile/src/features/Swap/common/filterBySearch.ts index f0db9ef219..ad10325dc5 100644 --- a/apps/wallet-mobile/src/features/Swap/common/filterBySearch.ts +++ b/apps/wallet-mobile/src/features/Swap/common/filterBySearch.ts @@ -1,21 +1,22 @@ 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 - ) + const ticker = normalizeString(tokenInfo.ticker ?? '') + const name = normalizeString(tokenInfo.name ?? '') + return ticker.includes(search) || name.includes(search) } if (tokenInfo.kind === 'nft') { - return tokenInfo.name?.toLocaleLowerCase().includes(searchTermLowerCase) ?? false + const name = normalizeString(tokenInfo.name ?? '') + return name.includes(search) } return false } } + +const normalizeString = (str: string) => str.toLocaleLowerCase().replace(/\s/g, '') From f8c33ab3aa00766e352b9d4614ca09ef8c1b2d3c Mon Sep 17 00:00:00 2001 From: Michal Date: Wed, 13 Sep 2023 16:14:06 +0100 Subject: [PATCH 3/4] Reuse search --- .../src/features/Swap/common/filterBySearch.ts | 18 +++++------------- .../SelectBuyTokenFromListScreen.tsx | 14 ++------------ 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/apps/wallet-mobile/src/features/Swap/common/filterBySearch.ts b/apps/wallet-mobile/src/features/Swap/common/filterBySearch.ts index ad10325dc5..5506b9a171 100644 --- a/apps/wallet-mobile/src/features/Swap/common/filterBySearch.ts +++ b/apps/wallet-mobile/src/features/Swap/common/filterBySearch.ts @@ -1,21 +1,13 @@ -import {Balance} from '@yoroi/types' - export const filterBySearch = (searchTerm: string) => { const search = normalizeString(searchTerm) if (search.length === 0) return () => true - return (tokenInfo: Balance.TokenInfo) => { - if (tokenInfo.kind === 'ft') { - const ticker = normalizeString(tokenInfo.ticker ?? '') - const name = normalizeString(tokenInfo.name ?? '') - return ticker.includes(search) || name.includes(search) - } + 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') { - const name = normalizeString(tokenInfo.name ?? '') - return name.includes(search) - } - return false + return ticker.includes(search) || name.includes(search) || symbol.includes(search) } } diff --git a/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/EditBuyAmount/SelectBuyTokenFromListScreen/SelectBuyTokenFromListScreen.tsx b/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/EditBuyAmount/SelectBuyTokenFromListScreen/SelectBuyTokenFromListScreen.tsx index 89115e7da4..d88df3abfd 100644 --- a/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/EditBuyAmount/SelectBuyTokenFromListScreen/SelectBuyTokenFromListScreen.tsx +++ b/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/EditBuyAmount/SelectBuyTokenFromListScreen/SelectBuyTokenFromListScreen.tsx @@ -21,6 +21,7 @@ import {NoAssetFoundImage} from '../../../../../../Send/common/NoAssetFoundImage import {useNavigateTo} from '../../../../../common/navigation' import {useStrings} from '../../../../../common/strings' import {useSwapTouched} from '../../../../../common/SwapFormProvider' +import {filterBySearch} from '../../../../../common/filterBySearch' type TransformedObject = { decimals: number | undefined @@ -205,7 +206,7 @@ const TokenList = ({showOnlyVerifiedTokens}: TokenListProps) => { ) const filteredTransformedList = React.useMemo(() => { - return transformedArray.filter(filterTokensPairBySearch(assetSearchTerm)) + return transformedArray.filter(filterBySearch(assetSearchTerm)) }, [transformedArray, assetSearchTerm]) return ( @@ -342,17 +343,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, From 148b47e63b557fc3cae4364da50624f223868826 Mon Sep 17 00:00:00 2001 From: Michal Date: Wed, 13 Sep 2023 16:22:29 +0100 Subject: [PATCH 4/4] Fix lint --- .../SelectBuyTokenFromListScreen.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/EditBuyAmount/SelectBuyTokenFromListScreen/SelectBuyTokenFromListScreen.tsx b/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/EditBuyAmount/SelectBuyTokenFromListScreen/SelectBuyTokenFromListScreen.tsx index d88df3abfd..9b94c9f7ff 100644 --- a/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/EditBuyAmount/SelectBuyTokenFromListScreen/SelectBuyTokenFromListScreen.tsx +++ b/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/EditBuyAmount/SelectBuyTokenFromListScreen/SelectBuyTokenFromListScreen.tsx @@ -18,10 +18,10 @@ 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' -import {filterBySearch} from '../../../../../common/filterBySearch' type TransformedObject = { decimals: number | undefined