fix: commission overrides calculation

This commit is contained in:
Nikola Ubavic 2022-02-18 16:59:52 +01:00
parent a7ee694169
commit 824922b7ba

View file

@ -45,54 +45,46 @@ const Commissions = ({ name: SCREEN_KEY, id: deviceId }) => {
} }
const getMachineCommissions = () => { const getMachineCommissions = () => {
if (loading || !deviceId || !config) { if (loading || !deviceId || !config) return []
return []
}
const commissions = {}
// first, get general non overridden commissions const overrides = config.overrides
const makeInfo = x => ? R.concat(
(commissions[R.prop('code')(x)] = { R.filter(R.propEq('machine', 'ALL_MACHINES'), config.overrides),
code: x.code, R.filter(R.propEq('machine', deviceId), config.overrides)
name: x.display, )
: []
return R.map(
coin =>
R.reduce(
R.mergeDeepRight,
{
code: coin.code,
name: coin.display,
cashIn: config.cashIn, cashIn: config.cashIn,
cashOut: config.cashOut, cashOut: config.cashOut,
fixedFee: config.fixedFee, fixedFee: config.fixedFee,
minimumTx: config.minimumTx minimumTx: config.minimumTx
}) },
R.forEach(makeInfo)(data.cryptoCurrencies) R.project(
['cashIn', 'cashOut', 'fixedFee', 'minimumTx'],
// second, get overrides for all machines R.filter(
const isId = id => R.propEq('machine', id) o =>
const generalOverrides = config.overrides R.includes(coin.code, o.cryptoCurrencies) ||
? R.filter(isId('ALL_MACHINES'))(config.overrides) R.includes('ALL_COINS', o.cryptoCurrencies),
: [] overrides
)
const overrideInfo = o => { )
commissions[o.cryptoCurrencies[0]].cashIn = o.cashIn ),
commissions[o.cryptoCurrencies[0]].cashOut = o.cashOut data.cryptoCurrencies
commissions[o.cryptoCurrencies[0]].fixedFee = o.fixedFee )
commissions[o.cryptoCurrencies[0]].minimumTx = o.minimumTx
} }
R.forEach(overrideInfo)(generalOverrides)
// third, get overrides for this machine
const machineOverrides = config.overrides
? R.filter(isId(deviceId))(config.overrides)
: []
R.forEach(overrideInfo)(machineOverrides)
// in the end, the machine specific overrides overwrite the less general ALL_MACHINE overrides or the general overrides
return R.values(commissions)
}
const machineCommissions = getMachineCommissions()
return ( return (
<EditableTable <EditableTable
name="overrides" name="overrides"
save={saveOverrides} save={saveOverrides}
data={machineCommissions} data={getMachineCommissions()}
elements={overrides(currency)} elements={overrides(currency)}
/> />
) )