log raw ticker price within tx
This commit is contained in:
parent
5815a606f2
commit
578a39a721
8 changed files with 132 additions and 39 deletions
22
lib/tx.js
22
lib/tx.js
|
|
@ -3,8 +3,8 @@ const BN = require('./bn')
|
|||
const CashInTx = require('./cash-in/cash-in-tx')
|
||||
const CashOutTx = require('./cash-out/cash-out-tx')
|
||||
|
||||
function process (tx, pi) {
|
||||
const mtx = massage(tx, pi)
|
||||
async function process (tx, pi) {
|
||||
const mtx = await massage(tx, pi)
|
||||
if (mtx.direction === 'cashIn') return CashInTx.post(mtx, pi)
|
||||
if (mtx.direction === 'cashOut') return CashOutTx.post(mtx, pi)
|
||||
|
||||
|
|
@ -16,15 +16,22 @@ function post (tx, pi) {
|
|||
.then(_.set('dirty', false))
|
||||
}
|
||||
|
||||
function massage (tx, pi) {
|
||||
async function massage (tx, pi) {
|
||||
const direction = _.get('direction', tx)
|
||||
const cryptoCode = _.get('cryptoCode', tx)
|
||||
const fiatCode = _.get('fiatCode', tx)
|
||||
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: _.get(direction, pi.getCommissionPercentage(cryptoCode))
|
||||
commissionPercentage: _.get(direction
|
||||
, pi.getCommissionPercentage(cryptoCode))
|
||||
})
|
||||
|
||||
const tickerPrice = await pi.getRawTickerPrice(fiatCode, cryptoCode)
|
||||
const logRawTickerPrice = r => _.assign(r, {
|
||||
rawTickerPrice: _.get(direction, tickerPrice)
|
||||
})
|
||||
|
||||
const mapBN = r => {
|
||||
|
|
@ -44,7 +51,12 @@ function massage (tx, pi) {
|
|||
return _.assign(r, update)
|
||||
}
|
||||
|
||||
const mapper = _.flow(transformDates, logCommission, mapBN, _.unset('dirty'))
|
||||
const mapper = _.flow(
|
||||
transformDates,
|
||||
mapBN,
|
||||
logCommission,
|
||||
logRawTickerPrice,
|
||||
_.unset('dirty'))
|
||||
|
||||
return mapper(tx)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue