refactor: replace custom field function with const and move update trade logic inside a function
This commit is contained in:
parent
f45c783876
commit
8567b7887c
6 changed files with 25 additions and 19 deletions
|
|
@ -517,16 +517,22 @@ function plugins (settings, deviceId) {
|
|||
const execute = tradeEntry.type === 'buy' ? exchange.buy : exchange.sell
|
||||
|
||||
return recordTrade(tradeEntry)
|
||||
.then(newEntry => {
|
||||
return execute(settings, tradeEntry.cryptoAtoms, tradeEntry.fiatCode, tradeEntry.cryptoCode, newEntry.id)
|
||||
.then(newEntry =>
|
||||
execute(settings, tradeEntry, newEntry.id)
|
||||
.catch(err => {
|
||||
const data = mergeTradeEntryAndError(tradeEntry, err)
|
||||
const sql = pgp.helpers.update(data, ['error'], 'trades') + ` WHERE id = ${newEntry.id}`
|
||||
return db.none(sql)
|
||||
.then(() => {
|
||||
throw err
|
||||
})
|
||||
updateTradeEntry(tradeEntry, newEntry, err)
|
||||
.catch(console.log)
|
||||
throw err
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
function updateTradeEntry (tradeEntry, newEntry, err) {
|
||||
const data = mergeTradeEntryAndError(tradeEntry, err)
|
||||
const sql = pgp.helpers.update(data, ['error'], 'trades') + ` WHERE id = ${newEntry.id}`
|
||||
return db.none(sql)
|
||||
.then(() => {
|
||||
throw err
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue