Fix ratchet errors on commission and ticker

This commit is contained in:
Rafael Taranto 2019-03-05 12:39:05 -03:00 committed by Josh Harvey
parent fe72b4fcaf
commit 3dd7503e45
5 changed files with 22 additions and 41 deletions

View file

@ -4,11 +4,10 @@ const CashInTx = require('./cash-in/cash-in-tx')
const CashOutTx = require('./cash-out/cash-out-tx')
function process (tx, pi) {
return massage(tx, pi).then(mtx => {
if (mtx.direction === 'cashIn') return CashInTx.post(mtx, pi)
if (mtx.direction === 'cashOut') return CashOutTx.post(mtx, pi)
return Promise.reject(new Error('No such tx direction: ' + mtx.direction))
})
const mtx = massage(tx, pi)
if (mtx.direction === 'cashIn') return CashInTx.post(mtx, pi)
if (mtx.direction === 'cashOut') return CashOutTx.post(mtx, pi)
return Promise.reject(new Error('No such tx direction: ' + mtx.direction))
}
function post (tx, pi) {
@ -17,9 +16,6 @@ function post (tx, pi) {
}
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})
@ -33,11 +29,13 @@ function massage (tx, pi) {
cashInFee: BN(r.cashInFee),
cashInFeeCrypto: BN(r.cashInFeeCrypto),
commissionPercentage: BN(r.commissionPercentage),
rawTickerPrice: BN(r.rawTickerPrice),
minimumTx: BN(r.minimumTx)
}
: {
cryptoAtoms: BN(r.cryptoAtoms),
fiat: BN(r.fiat),
rawTickerPrice: BN(r.rawTickerPrice),
commissionPercentage: BN(r.commissionPercentage)
}
@ -47,16 +45,7 @@ function massage (tx, pi) {
const mapper = _.flow(
transformDates,
mapBN,
_.unset('dirty'),
withTickerPrice)
function withTickerPrice (r) {
return pi.getRawTickerPrice(fiatCode, cryptoCode).then(tickerPrice => {
return _.assign(r, {
rawTickerPrice: _.get(direction, tickerPrice)
})
})
}
_.unset('dirty'))
return mapper(tx)
}