refactor: inline one step

This commit is contained in:
siiky 2023-10-23 10:35:28 +01:00
parent 347844610c
commit d47101215f

View file

@ -161,20 +161,18 @@ function plugins (settings, deviceId) {
return _.map(([acc, bill]) => acc + bill.provisioned, _.zip(sum, bills))
}
const counts = _.flow(
recyclers = _.flow(
// Sum "used" bills per recycler
_.reduce(sumTxs, _.map(_.constant(0), recyclers)),
_.zip(_.map('count', recyclers)),
_.map(([count, provisioned]) => count - provisioned),
_.zip(recyclers),
// Remove used bills from recycler counts
_.map(([recycler, provisioned]) => _.set('count', recycler.count - provisioned, recycler)),
)(redeemableTxs)
if (_.some(_.lt(_, 0), counts)) {
if (_.some(({ count }) => count < 0, recyclers))
throw new Error('Negative note count: %j', counts)
}
return _.map(
recycler => _.set('count', counts[recycler.number], recycler),
recyclers
)
return recyclers
}
function buildAvailableCassettes (excludeTxId) {