chore: select refactor
This commit is contained in:
parent
772be35d06
commit
013955075a
5 changed files with 118 additions and 111 deletions
|
|
@ -20,17 +20,6 @@ const ALL_COINS = {
|
|||
code: 'ALL_COINS'
|
||||
}
|
||||
|
||||
const SHOW_ALL = 'Show all'
|
||||
|
||||
const ORDER_OPTIONS = [
|
||||
'Machine name',
|
||||
'Cryptocurrency',
|
||||
'Cash-in',
|
||||
'Cash-out',
|
||||
'Fixed Fee',
|
||||
'Minimum Tx'
|
||||
]
|
||||
|
||||
const cashInAndOutHeaderStyle = { marginLeft: 6 }
|
||||
|
||||
const cashInHeader = (
|
||||
|
|
@ -405,19 +394,6 @@ const getCommissions = (cryptoCode, deviceId, config) => {
|
|||
return createCommissions(cryptoCode, deviceId, true, config)
|
||||
}
|
||||
|
||||
const getMachineCoins = (deviceId, localeConfig) => {
|
||||
const machineCoins = R.prop('cryptoCurrencies', localeConfig)
|
||||
|
||||
const overrides = R.prop('overrides', localeConfig)
|
||||
|
||||
if (overrides && !R.isEmpty(overrides)) {
|
||||
const override = R.find(it => it.machine === deviceId)(overrides)
|
||||
|
||||
if (override !== undefined) return R.prop('cryptoCurrencies', override)
|
||||
}
|
||||
return machineCoins
|
||||
}
|
||||
|
||||
const getListCommissionsSchema = () => {
|
||||
return Yup.object().shape({
|
||||
machine: Yup.string()
|
||||
|
|
@ -539,43 +515,6 @@ const getListCommissionsFields = (getData, currency, defaults) => {
|
|||
]
|
||||
}
|
||||
|
||||
const filterCommissions = (coinFilter, machineFilter, machines) =>
|
||||
R.compose(
|
||||
R.filter(byMachine(machineFilter, machines)),
|
||||
R.filter(byCoin(coinFilter))
|
||||
)
|
||||
|
||||
const byMachine = (filter, machines) => it =>
|
||||
(filter === SHOW_ALL) |
|
||||
(filter === getView(machines, 'name', 'deviceId')(it.machine))
|
||||
|
||||
const byCoin = filter => it =>
|
||||
(filter === SHOW_ALL) | (filter === it.cryptoCurrencies[0])
|
||||
|
||||
const sortCommissionsBy = (prop, machines) => {
|
||||
switch (prop) {
|
||||
case ORDER_OPTIONS[1]:
|
||||
return R.sortBy(R.path(['cryptoCurrencies', 0]))
|
||||
case ORDER_OPTIONS[2]:
|
||||
return R.sortBy(R.prop('cashIn'))
|
||||
case ORDER_OPTIONS[3]:
|
||||
return R.sortBy(R.prop('cashOut'))
|
||||
case ORDER_OPTIONS[4]:
|
||||
return R.sortBy(R.prop('fixedFee'))
|
||||
case ORDER_OPTIONS[5]:
|
||||
return R.sortBy(R.prop('minimumTx'))
|
||||
default:
|
||||
return R.sortBy(
|
||||
R.compose(getView(machines, 'name', 'deviceId'), R.prop('machine'))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const removeCoinFromOverride = crypto => override =>
|
||||
R.mergeRight(override, {
|
||||
cryptoCurrencies: R.without([crypto], override.cryptoCurrencies)
|
||||
})
|
||||
|
||||
export {
|
||||
mainFields,
|
||||
overrides,
|
||||
|
|
@ -585,15 +524,6 @@ export {
|
|||
overridesDefaults,
|
||||
getOrder,
|
||||
getCommissions,
|
||||
getMachineCoins,
|
||||
getListCommissionsSchema,
|
||||
commissionsList,
|
||||
getView,
|
||||
byMachine,
|
||||
byCoin,
|
||||
sortCommissionsBy,
|
||||
filterCommissions,
|
||||
removeCoinFromOverride,
|
||||
SHOW_ALL,
|
||||
ORDER_OPTIONS
|
||||
commissionsList
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue