From aa0d14367901a79e51487e167e5f5149f4e622d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Wed, 2 Mar 2022 14:04:09 +0000 Subject: [PATCH] fix: trade promises chain errors --- lib/plugins.js | 5 ++++- lib/plugins/exchange/ccxt.js | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/plugins.js b/lib/plugins.js index 8a11ebfc..80bbcc9b 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -617,7 +617,10 @@ function plugins (settings, deviceId) { const sql = pgp.helpers.insert(tradeEntry, null, 'trades') + 'RETURNING *' return db.tx(t => { return t.oneOrNone(sql) - .then(newTrade => recordTradeAndTx(newTrade.id, _tradeEntry, t)) + .then(newTrade => { + return recordTradeAndTx(newTrade.id, _tradeEntry, t) + .then(() => newTrade) + }) }) } diff --git a/lib/plugins/exchange/ccxt.js b/lib/plugins/exchange/ccxt.js index 2211b9c0..bc0c73a0 100644 --- a/lib/plugins/exchange/ccxt.js +++ b/lib/plugins/exchange/ccxt.js @@ -1,4 +1,4 @@ -const { toUnit } = require('@lamassu/coins') +const { utils: coinUtils } = require('@lamassu/coins') const _ = require('lodash/fp') const ccxt = require('ccxt') @@ -19,7 +19,7 @@ function trade (side, account, tradeEntry, exchangeName) { const symbol = buildMarket(fiatCode, cryptoCode, exchangeName) const precision = _.defaultTo(DEFAULT_AMOUNT_PRECISION, AMOUNT_PRECISION) - const amount = toUnit(cryptoAtoms, cryptoCode).toFixed(precision) + const amount = coinUtils.toUnit(cryptoAtoms, cryptoCode).toFixed(precision) const accountOptions = _.isFunction(loadOptions) ? loadOptions(account) : {} const withCustomKey = USER_REF ? { [USER_REF]: tradeId } : {} const options = _.assign(accountOptions, withCustomKey)