avoid endless loops

This commit is contained in:
Daniel Lugo 2020-02-28 16:49:06 -04:00
parent e5eff0c613
commit ad61133efe
2 changed files with 11 additions and 18 deletions

View file

@ -957,7 +957,6 @@ const sendPayment = async (to, amount, memo) => {
// eslint-disable-next-line init-declarations
let timeoutID
/** @type {string} */
const invoice = await Promise.race([
Utils.tryAndWait(
gun =>
@ -979,6 +978,13 @@ const sendPayment = async (to, amount, memo) => {
})
])
if (typeof invoice !== 'string') {
throw new Error(
'received invoice not an string, isntead got: ' +
JSON.stringify(invoice)
)
}
const decInvoice = await SEA.decrypt(invoice, ourSecret)
logger.info('decoded invoice: ' + decInvoice)

View file

@ -49,23 +49,10 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
)} -- addr: ${addr}`
)
let hasRetried = false
const alreadyAnswered = Utils.tryAndWait(
(_, user) =>
user
const alreadyAnswered = getUser()
.get(Key.ORDER_TO_RESPONSE)
.get(orderID)
.then(),
v => {
// only retry once, because of the timeout
if (hasRetried) {
return false
}
hasRetried = true
return typeof v === 'undefined'
}
)
.then()
if (alreadyAnswered) {
return