bug fixes for redeem

This commit is contained in:
Josh Harvey 2016-05-10 15:37:07 +03:00
parent 996ebd395b
commit 694f3e5e96
3 changed files with 30 additions and 22 deletions

View file

@ -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)
}