lnbits-legend/lnbits/extensions/satspay/static/js/utils.js

35 lines
976 B
JavaScript
Raw Normal View History

2022-07-07 11:37:26 +03:00
const sleep = ms => new Promise(r => setTimeout(r, ms))
const retryWithDelay = async function (fn, retryCount = 0) {
try {
await sleep(25)
// Do not return the call directly, use result.
// Otherwise the error will not be cought in this try-catch block.
const result = await fn()
return result
} catch (err) {
if (retryCount > 100) throw err
await sleep((retryCount + 1) * 1000)
return retryWithDelay(fn, retryCount + 1)
}
}
2022-07-08 15:47:48 +03:00
const mapCharge = (obj, oldObj = {}) => {
2022-07-07 11:37:26 +03:00
obj._data = _.clone(obj)
obj.theTime = obj.time * 60 - (Date.now() / 1000 - obj.timestamp)
2022-07-08 15:47:48 +03:00
obj.time = obj.time + ' min'
2022-07-07 11:37:26 +03:00
if (obj.time_elapsed) {
2022-07-08 15:47:48 +03:00
obj.date = ''
2022-07-07 11:37:26 +03:00
} else {
obj.date = Quasar.utils.date.formatDate(
new Date((obj.theTime - 3600) * 1000),
'HH:mm:ss'
)
}
2022-07-08 15:47:48 +03:00
obj.expanded = false
2022-07-07 11:37:26 +03:00
obj.displayUrl = ['/satspay/', obj.id].join('')
2022-07-08 15:47:48 +03:00
obj.expanded = oldObj.expanded
obj.pendingBalance = oldObj.pendingBalance || 0
2022-07-07 11:37:26 +03:00
return obj
}