-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(portfolio): moved info filter to portfolio
- Loading branch information
1 parent
eb275e7
commit 80abaf8
Showing
3 changed files
with
43 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/portfolio/src/helpers/info-filter-by-name.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {tokenInfoMocks} from '../adapters/token-info.mocks' | ||
import {infoFilterByName} from './info-filter-by-name' | ||
|
||
describe('infoFilterByName', () => { | ||
it('should return a function that filters token info by name or ticker', () => { | ||
const filter = infoFilterByName('cRyP') | ||
|
||
expect(filter(tokenInfoMocks.nftCryptoKitty)).toBe(true) | ||
}) | ||
|
||
it('should return false if the token info does not match the search', () => { | ||
const filter = infoFilterByName('ADA') | ||
|
||
expect(filter(tokenInfoMocks.primaryETH)).toBe(false) | ||
}) | ||
|
||
it('should return true if the search is empty', () => { | ||
const filter = infoFilterByName('') | ||
|
||
expect(filter(tokenInfoMocks.primaryETH)).toBe(true) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {Portfolio} from '@yoroi/types' | ||
|
||
export function infoFilterByName(search: string) { | ||
if (search.length === 0) return () => true | ||
|
||
const searchSanitized = search.toLocaleLowerCase() | ||
|
||
return ({ticker, name}: Portfolio.Token.Info) => | ||
ticker.toLocaleLowerCase().includes(searchSanitized) || | ||
name.toLocaleLowerCase().includes(searchSanitized) | ||
} |