From 5815a606f2d2c317703467175bba69b950389a8e Mon Sep 17 00:00:00 2001 From: Fabio Cigliano Date: Mon, 26 Nov 2018 11:31:08 +1300 Subject: [PATCH] rewoking getCommissionPercentage function --- lib/cash-out/cash-out-helper.js | 6 +++++- lib/plugins.js | 12 ++++++------ lib/tx.js | 6 +++++- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/cash-out/cash-out-helper.js b/lib/cash-out/cash-out-helper.js index f4e7ccf9..1241ebd3 100644 --- a/lib/cash-out/cash-out-helper.js +++ b/lib/cash-out/cash-out-helper.js @@ -11,7 +11,11 @@ module.exports = {redeemableTxs, toObj, toDb} const mapValuesWithKey = _.mapValues.convert({cap: false}) function convertBigNumFields (obj) { - const convert = (value, key) => _.includes(key, ['cryptoAtoms', 'fiat', 'commissionPercentage']) + const convert = (value, key) => _.includes(key, [ + 'cryptoAtoms', + 'fiat', + 'commissionPercentage' + ]) ? value.toString() : value diff --git a/lib/plugins.js b/lib/plugins.js index dca6d3a1..0a1ec5f3 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -32,13 +32,13 @@ const PONG_TTL = '1 week' const tradesQueues = {} function plugins (settings, deviceId) { - function getCommissionForTx (tx) { - const direction = _.get('direction', tx) - const cryptoCode = _.get('cryptoCode', tx) + function getCommissionPercentage (cryptoCode) { const cryptoConfig = configManager.scoped(cryptoCode, deviceId, settings.config) - if (direction === 'cashIn') return /* cashInCommission */ BN(cryptoConfig.cashInCommission).div(100) - if (direction === 'cashOut') return /* cashOutCommission */ BN(cryptoConfig.cashOutCommission).div(100) + return { + cashIn: BN(cryptoConfig.cashInCommission).div(100), + cashOut: BN(cryptoConfig.cashOutCommission).div(100) + } } function buildRates (tickers) { @@ -793,7 +793,7 @@ function plugins (settings, deviceId) { sell, notificationsEnabled, notifyOperator, - getCommissionForTx + getCommissionPercentage } } diff --git a/lib/tx.js b/lib/tx.js index 63d454f5..71c84f19 100644 --- a/lib/tx.js +++ b/lib/tx.js @@ -17,11 +17,15 @@ function post (tx, pi) { } function massage (tx, pi) { + const direction = _.get('direction', tx) + const cryptoCode = _.get('cryptoCode', 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: pi.getCommissionForTx(tx)}) + const logCommission = r => _.assign(r, { + commissionPercentage: _.get(direction, pi.getCommissionPercentage(cryptoCode)) + }) const mapBN = r => { const update = r.direction === 'cashIn'