tx.commission_percentage added

This commit is contained in:
Fabio Cigliano 2018-11-23 16:00:51 +13:00 committed by Josh Harvey
parent 038a22aba7
commit 03279c8d2c
7 changed files with 140 additions and 42 deletions

View file

@ -4,7 +4,7 @@ const CashInTx = require('./cash-in/cash-in-tx')
const CashOutTx = require('./cash-out/cash-out-tx')
function process (tx, pi) {
const mtx = massage(tx)
const mtx = massage(tx, pi)
if (mtx.direction === 'cashIn') return CashInTx.post(mtx, pi)
if (mtx.direction === 'cashOut') return CashOutTx.post(mtx, pi)
@ -16,11 +16,12 @@ function post (tx, pi) {
.then(_.set('dirty', false))
}
function massage (tx) {
function massage (tx, pi) {
const isDateField = r => r === 'created' || _.endsWith('_time', r)
const transformDate = (v, k) => isDateField(k) ? new Date(v) : v
const mapValuesWithKey = _.mapValues.convert({'cap': false})
const transformDates = r => mapValuesWithKey(transformDate, r)
const logCommission = r => _.assign(r, {commissionPercentage: pi.getCommissionForTx(tx)})
const mapBN = r => {
const update = r.direction === 'cashIn'
@ -39,7 +40,7 @@ function massage (tx) {
return _.assign(r, update)
}
const mapper = _.flow(transformDates, mapBN, _.unset('dirty'))
const mapper = _.flow(transformDates, logCommission, mapBN, _.unset('dirty'))
return mapper(tx)
}