marginally improve the checkpending situation.

This commit is contained in:
fiatjaf
2021-03-21 17:10:53 -03:00
parent e4fb18a53a
commit f27c2ebc21
3 changed files with 34 additions and 30 deletions

View File

@@ -584,18 +584,16 @@ new Vue({
LNbits.href.deleteWallet(walletId, user) LNbits.href.deleteWallet(walletId, user)
}) })
}, },
fetchPayments: function (checkPending) { fetchPayments: function () {
return LNbits.api return LNbits.api.getPayments(this.g.wallet).then(response => {
.getPayments(this.g.wallet, checkPending) this.payments = response.data
.then(response => { .map(obj => {
this.payments = response.data return LNbits.map.payment(obj)
.map(obj => { })
return LNbits.map.payment(obj) .sort((a, b) => {
}) return b.time - a.time
.sort((a, b) => { })
return b.time - a.time })
})
})
}, },
fetchBalance: function () { fetchBalance: function () {
LNbits.api.getWallet(this.g.wallet).then(response => { LNbits.api.getWallet(this.g.wallet).then(response => {
@@ -612,9 +610,12 @@ new Vue({
message: 'Checking pending transactions...' message: 'Checking pending transactions...'
}) })
this.fetchPayments(true).then(() => { LNbits.api
dismissMsg() .checkPending(this.g.wallet)
}) .then(() => LNbits.api.fetchPayments)
.then(() => {
dismissMsg()
})
}, },
exportCSV: function () { exportCSV: function () {
LNbits.utils.exportCSV(this.paymentsTable.columns, this.payments) LNbits.utils.exportCSV(this.paymentsTable.columns, this.payments)
@@ -628,7 +629,7 @@ new Vue({
created: function () { created: function () {
this.fetchBalance() this.fetchBalance()
this.fetchPayments() this.fetchPayments()
setTimeout(this.checkPendingPayments(), 1200) this.checkPendingPayments()
}, },
mounted: function () { mounted: function () {
// show disclaimer // show disclaimer

View File

@@ -3,7 +3,7 @@ import json
import lnurl # type: ignore import lnurl # type: ignore
import httpx import httpx
from urllib.parse import urlparse, urlunparse, urlencode, parse_qs, ParseResult from urllib.parse import urlparse, urlunparse, urlencode, parse_qs, ParseResult
from quart import g, jsonify, request, make_response from quart import g, jsonify, make_response
from http import HTTPStatus from http import HTTPStatus
from binascii import unhexlify from binascii import unhexlify
from typing import Dict, Union from typing import Dict, Union
@@ -32,15 +32,20 @@ async def api_wallet():
) )
@core_app.route("/api/v1/checkpending", methods=["POST"])
@api_check_wallet_key("invoice")
async def api_checkpending():
g.nursery.start_soon(delete_expired_invoices)
for payment in await g.wallet.get_payments(complete=False, pending=True, exclude_uncheckable=True):
await payment.check_pending()
return "", HTTPStatus.NO_CONTENT
@core_app.route("/api/v1/payments", methods=["GET"]) @core_app.route("/api/v1/payments", methods=["GET"])
@api_check_wallet_key("invoice") @api_check_wallet_key("invoice")
async def api_payments(): async def api_payments():
if "check_pending" in request.args:
await delete_expired_invoices()
for payment in await g.wallet.get_payments(complete=False, pending=True, exclude_uncheckable=True):
await payment.check_pending()
return jsonify(await g.wallet.get_payments(pending=True)), HTTPStatus.OK return jsonify(await g.wallet.get_payments(pending=True)), HTTPStatus.OK

View File

@@ -52,13 +52,11 @@ window.LNbits = {
getWallet: function (wallet) { getWallet: function (wallet) {
return this.request('get', '/api/v1/wallet', wallet.inkey) return this.request('get', '/api/v1/wallet', wallet.inkey)
}, },
getPayments: function (wallet, checkPending) { checkPending: function (wallet) {
var query_param = checkPending ? '?check_pending' : '' return this.request('post', '/api/v1/checkpending', wallet.inkey)
return this.request( },
'get', getPayments: function (wallet) {
['/api/v1/payments', query_param].join(''), return this.request('get', '/api/v1/payments', wallet.inkey)
wallet.inkey
)
}, },
getPayment: function (wallet, paymentHash) { getPayment: function (wallet, paymentHash) {
return this.request( return this.request(