23 lines
794 B
JavaScript
23 lines
794 B
JavaScript
import * as R from 'ramda'
|
|
|
|
import _schema from '../../../Services/schemas'
|
|
|
|
const contains = crypto => R.compose(R.includes(crypto), R.prop('cryptos'))
|
|
const sameClass = type => R.propEq(type, 'class')
|
|
const filterConfig = (crypto, type) =>
|
|
R.filter(it => sameClass(type)(it) && contains(crypto)(it))
|
|
export const getItems = (accountsConfig, accounts, type, crypto) => {
|
|
const schema = _schema()
|
|
const fConfig = filterConfig(crypto, type)(accountsConfig)
|
|
const find = code => accounts && accounts[code]
|
|
|
|
const [filled, unfilled] = R.partition(({ code }) => {
|
|
const account = find(code)
|
|
if (!schema[code]) return true
|
|
|
|
const { getValidationSchema } = schema[code]
|
|
return getValidationSchema(account).isValidSync(account)
|
|
})(fConfig)
|
|
|
|
return { filled, unfilled }
|
|
}
|