diff --git a/lib/cash-in/cash-in-low.js b/lib/cash-in/cash-in-low.js index fc42d868..3348e62b 100644 --- a/lib/cash-in/cash-in-low.js +++ b/lib/cash-in/cash-in-low.js @@ -29,7 +29,7 @@ function toObj (row) { keys.forEach(key => { const objKey = _.camelCase(key) - if (_.includes(key, ['crypto_atoms', 'fiat', 'cash_in_fee', 'cash_in_fee_crypto'])) { + if (_.includes(key, ['crypto_atoms', 'fiat', 'cash_in_fee', 'cash_in_fee_crypto', 'commission_percentage', 'raw_ticker_price'])) { newObj[objKey] = BN(row[key]) return } diff --git a/lib/cash-out/cash-out-helper.js b/lib/cash-out/cash-out-helper.js index b9e059f2..174ecd2b 100644 --- a/lib/cash-out/cash-out-helper.js +++ b/lib/cash-out/cash-out-helper.js @@ -58,7 +58,7 @@ function toObj (row) { keys.forEach(key => { const objKey = _.camelCase(key) - if (key === 'crypto_atoms' || key === 'fiat') { + if (_.includes(key, ['crypto_atoms', 'fiat', 'commission_percentage', 'raw_ticker_price'])) { newObj[objKey] = BN(row[key]) return } diff --git a/lib/plugins.js b/lib/plugins.js index 3639238f..eddde18e 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -32,14 +32,6 @@ const PONG_TTL = '1 week' const tradesQueues = {} function plugins (settings, deviceId) { - function getRawTickerPrice (fiatCode, cryptoCode) { - return ticker.getRates(settings, fiatCode, cryptoCode) - .then(tickers => ({ - cashIn: _.get(['rates', 'ask'], tickers), - cashOut: _.get(['rates', 'bid'], tickers) - })) - } - function buildRates (tickers) { const config = configManager.machineScoped(deviceId, settings.config) const cryptoCodes = config.cryptoCurrencies @@ -198,8 +190,8 @@ function plugins (settings, deviceId) { const config = configManager.scoped(cryptoCode, deviceId, settings.config) const minimumTx = BN(config.minimumTx) const cashInFee = BN(config.cashInFee) - const cashInCommission = BN(config.cashInCommission || 0) - const cashOutCommission = BN(config.cashOutCommission || 0) + const cashInCommission = BN(config.cashInCommission) + const cashOutCommission = config.cashOutCommission ? BN(config.cashOutCommission) : null const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode) return { @@ -239,12 +231,13 @@ function plugins (settings, deviceId) { const balances = arr.slice(cryptoCodesCount + 3, 2 * cryptoCodesCount + 3) const testNets = arr.slice(2 * cryptoCodesCount + 3) const coinParams = _.zip(cryptoCodes, testNets) + const coinsWithoutRate = _.map(mapCoinSettings, coinParams) return { cassettes, rates: buildRates(tickers), balances: buildBalances(balances), - coins: _.map(mapCoinSettings, coinParams), + coins: _.zipWith(_.assign, coinsWithoutRate, tickers), configVersion } }) @@ -795,8 +788,7 @@ function plugins (settings, deviceId) { buy, sell, notificationsEnabled, - notifyOperator, - getRawTickerPrice + notifyOperator } } diff --git a/lib/tx.js b/lib/tx.js index d6b8517a..32eb3366 100644 --- a/lib/tx.js +++ b/lib/tx.js @@ -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) } diff --git a/package-lock.json b/package-lock.json index a85e1d17..bbd13c39 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2888,7 +2888,7 @@ }, "debug-log": { "version": "1.0.1", - "resolved": "http://registry.npmjs.org/debug-log/-/debug-log-1.0.1.tgz", + "resolved": "https://registry.npmjs.org/debug-log/-/debug-log-1.0.1.tgz", "integrity": "sha1-IwdjLUwEOCuN+KMvcLiVBG1SdF8=", "dev": true }, @@ -3457,7 +3457,7 @@ "dependencies": { "chalk": { "version": "1.1.3", - "resolved": "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", "dev": true, "requires": { @@ -3470,7 +3470,7 @@ }, "strip-ansi": { "version": "3.0.1", - "resolved": "http://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", "dev": true, "requires": { @@ -3670,7 +3670,7 @@ "dependencies": { "doctrine": { "version": "1.5.0", - "resolved": "http://registry.npmjs.org/doctrine/-/doctrine-1.5.0.tgz", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-1.5.0.tgz", "integrity": "sha1-N53Ocw9hZvds76TmcHoVmwLFpvo=", "dev": true, "requires": { @@ -3689,7 +3689,7 @@ }, "load-json-file": { "version": "2.0.0", - "resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz", + "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz", "integrity": "sha1-eUfkIUmvgNaWy/eXvKq8/h/inKg=", "dev": true, "requires": { @@ -3710,7 +3710,7 @@ }, "pify": { "version": "2.3.0", - "resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz", + "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", "dev": true }, @@ -9002,7 +9002,7 @@ }, "require-uncached": { "version": "1.0.3", - "resolved": "http://registry.npmjs.org/require-uncached/-/require-uncached-1.0.3.tgz", + "resolved": "https://registry.npmjs.org/require-uncached/-/require-uncached-1.0.3.tgz", "integrity": "sha1-Tg1W1slmL9MeQwEcS5WqSZVUIdM=", "dev": true, "requires": { @@ -10422,7 +10422,7 @@ }, "table": { "version": "4.0.3", - "resolved": "http://registry.npmjs.org/table/-/table-4.0.3.tgz", + "resolved": "https://registry.npmjs.org/table/-/table-4.0.3.tgz", "integrity": "sha512-S7rnFITmBH1EnyKcvxBh1LjYeQMmnZtCXSEbHcH6S0NoKit24ZuFO/T1vDcLdYsLQkM188PVVhQmzKIuThNkKg==", "dev": true, "requires": {