Use commission rate from machine instead of server

This commit is contained in:
Rafael Taranto 2019-02-28 20:17:00 -03:00 committed by Josh Harvey
parent 578a39a721
commit 9f3457f14d
2 changed files with 30 additions and 37 deletions

View file

@ -3,12 +3,12 @@ const BN = require('./bn')
const CashInTx = require('./cash-in/cash-in-tx')
const CashOutTx = require('./cash-out/cash-out-tx')
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)
return Promise.reject(new Error('No such tx direction: ' + mtx.direction))
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))
})
}
function post (tx, pi) {
@ -16,7 +16,7 @@ function post (tx, pi) {
.then(_.set('dirty', false))
}
async function massage (tx, pi) {
function massage (tx, pi) {
const direction = _.get('direction', tx)
const cryptoCode = _.get('cryptoCode', tx)
const fiatCode = _.get('fiatCode', tx)
@ -24,15 +24,6 @@ async function massage (tx, pi) {
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))
})
const tickerPrice = await pi.getRawTickerPrice(fiatCode, cryptoCode)
const logRawTickerPrice = r => _.assign(r, {
rawTickerPrice: _.get(direction, tickerPrice)
})
const mapBN = r => {
const update = r.direction === 'cashIn'
@ -41,11 +32,13 @@ async function massage (tx, pi) {
fiat: BN(r.fiat),
cashInFee: BN(r.cashInFee),
cashInFeeCrypto: BN(r.cashInFeeCrypto),
commissionPercentage: BN(r.commissionPercentage),
minimumTx: BN(r.minimumTx)
}
: {
cryptoAtoms: BN(r.cryptoAtoms),
fiat: BN(r.fiat)
fiat: BN(r.fiat),
commissionPercentage: BN(r.commissionPercentage)
}
return _.assign(r, update)
@ -54,9 +47,16 @@ async function massage (tx, pi) {
const mapper = _.flow(
transformDates,
mapBN,
logCommission,
logRawTickerPrice,
_.unset('dirty'))
_.unset('dirty'),
withTickerPrice)
function withTickerPrice (r) {
return pi.getRawTickerPrice(fiatCode, cryptoCode).then(tickerPrice => {
return _.assign(r, {
rawTickerPrice: _.get(direction, tickerPrice)
})
})
}
return mapper(tx)
}