bug fixes for redeem
This commit is contained in:
parent
996ebd395b
commit
694f3e5e96
3 changed files with 30 additions and 22 deletions
|
|
@ -806,13 +806,13 @@ exports.registerRedeem = function registerRedeem (session) {
|
|||
}
|
||||
|
||||
exports.fetchPhoneTx = function fetchPhoneTx (phone) {
|
||||
db.fetchPhoneTxs(phone, TRANSACTION_EXPIRATION)
|
||||
return db.fetchPhoneTxs(phone, TRANSACTION_EXPIRATION)
|
||||
.then(txs => {
|
||||
const authorizedTxs = txs.filter(tx => tx.authorized)
|
||||
if (authorizedTxs.length > 0) {
|
||||
const confirmedTxs = txs.filter(tx => R.contains(tx.status, ['instant', 'confirmed']))
|
||||
if (confirmedTxs.length > 0) {
|
||||
const maxTx = R.reduce((acc, val) => {
|
||||
!acc || val.cryptoAtoms.gt(acc.cryptoAtoms) ? val : acc
|
||||
}, null, authorizedTxs)
|
||||
return !acc || val.cryptoAtoms.gt(acc.cryptoAtoms) ? val : acc
|
||||
}, null, confirmedTxs)
|
||||
|
||||
return {tx: maxTx}
|
||||
}
|
||||
|
|
@ -827,5 +827,5 @@ exports.fetchTx = function fetchTx (session) {
|
|||
}
|
||||
|
||||
exports.requestDispense = function requestDispense (session, tx) {
|
||||
return db.addDispenseRequest(session.fingerprint, tx)
|
||||
return db.addDispenseRequest(session, tx)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -530,17 +530,10 @@ exports.fetchPhoneTxs = function fetchPhoneTxs (phone, dispenseTimeout) {
|
|||
'AND (EXTRACT(EPOCH FROM (COALESCE(confirmation_time, now()) - created))) * 1000 < $3 ' +
|
||||
'AND stage=$4 AND authority=$5 AND incoming=$6'
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
connect(function (cerr, client, done) {
|
||||
if (cerr) return reject(cerr)
|
||||
var values = [phone, false, dispenseTimeout, 'initial_request', 'pending', true]
|
||||
query(client, sql, values, function (err, results) {
|
||||
done()
|
||||
if (err) return reject(err)
|
||||
resolve(normalizeTxs(results.rows))
|
||||
})
|
||||
})
|
||||
})
|
||||
var values = [phone, false, dispenseTimeout, 'initial_request', 'pending', true]
|
||||
|
||||
return pquery(sql, values)
|
||||
.then(r => normalizeTxs(r.rows))
|
||||
}
|
||||
|
||||
exports.fetchTx = function fetchTx (session) {
|
||||
|
|
@ -585,8 +578,10 @@ function updateDispense (client, session, dispensed, cb) {
|
|||
'WHERE stage=$2 AND authority=$3 AND device_fingerprint=$4 AND ' +
|
||||
'session_id=$5 AND incoming=$6'
|
||||
var values = [dispensed, 'initial_request', 'pending', session.fingerprint, session.id, true]
|
||||
query(client, sql, values, function (err) {
|
||||
cb(err)
|
||||
query(client, sql, values, function (err, results) {
|
||||
if (err) return cb(err)
|
||||
if (results.rowCount === 0) return cb(new Error('No pending tx'))
|
||||
cb()
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
19
todo.txt
19
todo.txt
|
|
@ -1,6 +1,19 @@
|
|||
- change satoshis to crypto_atoms in db (ask neal about this)
|
||||
|
||||
- on upgrade, make sure we're not sending out lots of notifications
|
||||
- sending two notifications on confirmation
|
||||
- reproduce by setting db record to unconfirmed, etc
|
||||
- something is being called twice, especially notifyConfirmation
|
||||
|
||||
-----------------
|
||||
|
||||
If machine is polling when server starts:
|
||||
|
||||
TypeError: Cannot read property 'cashIn' of undefined
|
||||
at /Users/josh/projects/lamassu-server/lib/routes.js:83:22
|
||||
at /Users/josh/projects/lamassu-server/lib/plugins.js:271:12
|
||||
at /Users/josh/projects/lamassu-server/lib/postgresql_interface.js:619:7
|
||||
at null.callback (/Users/josh/projects/lamassu-server/lib/postgresql_interface.js:129:5)
|
||||
at Query.handleReadyForQuery (/Users/josh/projects/lamassu-server/node_modules/pg/lib/query.js:89:10)
|
||||
at null.<anonymous> (/Users/josh/projects/lamassu-server/node_modules/pg/lib/client.js:163:19)
|
||||
at emitOne (events.js:82:20)
|
||||
at emit (events.js:169:7)
|
||||
at Socket.<anonymous> (/Users/josh/projects/lamassu-server/node_modules/pg/lib/connection.js:109:12)
|
||||
at emitOne (events.js:77:13)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue