fix: trade promises chain errors

This commit is contained in:
José Oliveira 2022-03-02 14:04:09 +00:00
parent 89d555de89
commit aa0d143679
2 changed files with 6 additions and 3 deletions

View file

@ -617,7 +617,10 @@ function plugins (settings, deviceId) {
const sql = pgp.helpers.insert(tradeEntry, null, 'trades') + 'RETURNING *' const sql = pgp.helpers.insert(tradeEntry, null, 'trades') + 'RETURNING *'
return db.tx(t => { return db.tx(t => {
return t.oneOrNone(sql) return t.oneOrNone(sql)
.then(newTrade => recordTradeAndTx(newTrade.id, _tradeEntry, t)) .then(newTrade => {
return recordTradeAndTx(newTrade.id, _tradeEntry, t)
.then(() => newTrade)
})
}) })
} }

View file

@ -1,4 +1,4 @@
const { toUnit } = require('@lamassu/coins') const { utils: coinUtils } = require('@lamassu/coins')
const _ = require('lodash/fp') const _ = require('lodash/fp')
const ccxt = require('ccxt') const ccxt = require('ccxt')
@ -19,7 +19,7 @@ function trade (side, account, tradeEntry, exchangeName) {
const symbol = buildMarket(fiatCode, cryptoCode, exchangeName) const symbol = buildMarket(fiatCode, cryptoCode, exchangeName)
const precision = _.defaultTo(DEFAULT_AMOUNT_PRECISION, AMOUNT_PRECISION) 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 accountOptions = _.isFunction(loadOptions) ? loadOptions(account) : {}
const withCustomKey = USER_REF ? { [USER_REF]: tradeId } : {} const withCustomKey = USER_REF ? { [USER_REF]: tradeId } : {}
const options = _.assign(accountOptions, withCustomKey) const options = _.assign(accountOptions, withCustomKey)