-
Notifications
You must be signed in to change notification settings - Fork 504
/
selectors.js
32 lines (29 loc) · 1.26 KB
/
selectors.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { createSelector } from 'reselect'
import { selectors } from 'data'
import { all, curry, isEmpty, propSatisfies, toUpper, prop, allPass, anyPass, compose, contains, map, filter } from 'ramda'
const filterTransactions = curry((status, criteria, transactions) => {
const isOfType = curry((filter, tx) => propSatisfies(x => filter === '' || toUpper(x) === toUpper(filter), 'type', tx))
const search = curry((text, property, tx) => compose(contains(toUpper(text || '')), toUpper, String, prop(property))(tx))
const searchPredicate = anyPass(map(search(criteria), ['description', 'from', 'to']))
const fullPredicate = allPass([isOfType(status), searchPredicate])
return filter(fullPredicate, transactions)
})
export const getData = createSelector(
[
selectors.form.getFormValues('bchTransactions'),
selectors.core.common.bch.getWalletTransactions
],
(formValues, pages) => {
const empty = (page) => isEmpty(page.data)
const search = prop('search', formValues) || ''
const status = prop('status', formValues) || ''
const filteredPages = !isEmpty(pages)
? pages.map(map(filterTransactions(status, search)))
: []
return {
pages: filteredPages,
search: search.length > 0,
empty: all(empty)(filteredPages)
}
}
)