mirror of
https://github.com/lnbits/lnbits.git
synced 2025-03-26 09:42:18 +01:00
Added paylinks to table
This commit is contained in:
parent
c62678b3aa
commit
2db3325727
lnbits/extensions/watchonly
@ -136,7 +136,7 @@ async def get_payment(payment_id: str) -> Payments:
|
||||
|
||||
|
||||
async def get_payments(user: str) -> List[Payments]:
|
||||
rows = await db.fetchall("SELECT * FROM payments WHERE user IN ?", (user,))
|
||||
rows = await db.fetchall("SELECT * FROM payments WHERE user = ?", (user,))
|
||||
print(rows[0])
|
||||
return [Payments.from_row(row) for row in rows]
|
||||
|
||||
|
@ -35,6 +35,7 @@ async def m001_initial(db):
|
||||
address TEXT NOT NULL,
|
||||
time_to_pay INTEGER NOT NULL,
|
||||
amount INTEGER NOT NULL,
|
||||
amount_paid INTEGER DEFAULT 0,
|
||||
time TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now'))
|
||||
);
|
||||
"""
|
||||
|
@ -21,6 +21,7 @@ class Payments(NamedTuple):
|
||||
address: str
|
||||
time_to_pay: str
|
||||
amount: int
|
||||
amount_paid: int
|
||||
time: int
|
||||
|
||||
@classmethod
|
||||
|
@ -324,7 +324,7 @@
|
||||
dense
|
||||
v-model.trim="formDialogPayment.data.time"
|
||||
type="number"
|
||||
label="Time (mins)"
|
||||
label="Time (secs)"
|
||||
> </q-input>
|
||||
|
||||
<div class="row q-mt-lg">
|
||||
@ -512,10 +512,16 @@
|
||||
field: 'amount'
|
||||
},
|
||||
{
|
||||
name: 'time',
|
||||
name: 'time to pay',
|
||||
align: 'left',
|
||||
label: 'time',
|
||||
field: 'time'
|
||||
label: 'Time to Pay (secs)',
|
||||
field: 'time_to_pay'
|
||||
},
|
||||
{
|
||||
name: 'timeleft',
|
||||
align: 'left',
|
||||
label: 'Time left (secs)',
|
||||
field: 'timeleft'
|
||||
},
|
||||
],
|
||||
pagination: {
|
||||
@ -646,6 +652,7 @@
|
||||
)
|
||||
.then(function (response) {
|
||||
self.walletLinks = response.data.map(function (obj) {
|
||||
|
||||
return mapWalletLink(obj)
|
||||
})
|
||||
})
|
||||
@ -692,7 +699,20 @@
|
||||
this.g.user.wallets[0].inkey
|
||||
)
|
||||
.then(function (response) {
|
||||
var i
|
||||
var now = parseInt(new Date() / 1000)
|
||||
for (i = 0; i < response.data.length; i++) {
|
||||
timeleft = response.data[i].time_to_pay - (now - response.data[i].time)
|
||||
if (timeleft < 1) {
|
||||
response.data[i].timeleft = 0
|
||||
}
|
||||
else{
|
||||
response.data[i].timeleft = timeleft
|
||||
}
|
||||
}
|
||||
console.log(response.data)
|
||||
self.paymentLinks = response.data.map(function (obj) {
|
||||
console.log(mapPayment(obj))
|
||||
return mapPayment(obj)
|
||||
})
|
||||
})
|
||||
|
@ -1,6 +1,7 @@
|
||||
import hashlib
|
||||
from quart import g, jsonify, request, url_for
|
||||
from http import HTTPStatus
|
||||
import httpx
|
||||
|
||||
from lnbits.core.crud import get_user
|
||||
from lnbits.decorators import api_check_wallet_key, api_validate_post_request
|
||||
@ -113,24 +114,23 @@ async def api_get_addresses(wallet_id):
|
||||
|
||||
return jsonify([address._asdict() for address in addresses]), HTTPStatus.OK
|
||||
|
||||
|
||||
#############################PAYEMENTS##########################
|
||||
|
||||
@watchonly_ext.route("/api/v1/payment", methods=["GET"])
|
||||
@api_check_wallet_key("invoice")
|
||||
async def api_payments_retrieve():
|
||||
|
||||
try:
|
||||
payments = await get_payments(g.wallet.user)
|
||||
print(payments)
|
||||
return (
|
||||
jsonify(payments),
|
||||
HTTPStatus.OK,
|
||||
)
|
||||
except:
|
||||
payments = await get_payments(g.wallet.user)
|
||||
print(payments)
|
||||
if not payments:
|
||||
return (
|
||||
jsonify({"message": "Cant fetch."}),
|
||||
HTTPStatus.UPGRADE_REQUIRED,
|
||||
)
|
||||
else:
|
||||
return jsonify([payment._asdict() for payment in payments]), HTTPStatus.OK
|
||||
|
||||
|
||||
@watchonly_ext.route("/api/v1/payment/<payment_id>", methods=["GET"])
|
||||
@api_check_wallet_key("invoice")
|
||||
@ -196,4 +196,19 @@ async def api_get_mempool():
|
||||
mempool = await get_mempool(g.wallet.user)
|
||||
if not mempool:
|
||||
mempool = await create_mempool(user=g.wallet.user)
|
||||
return jsonify(mempool._asdict()), HTTPStatus.OK
|
||||
|
||||
@watchonly_ext.route("/api/v1/mempool/<address>", methods=["GET"])
|
||||
@api_check_wallet_key("invoice")
|
||||
async def api_get_mempool_address_balance(address):
|
||||
mempool = await get_mempool(g.wallet.user)
|
||||
async with httpx.AsyncClient() as client:
|
||||
try:
|
||||
r = await client.get(
|
||||
mempool.endpoint + "/" + address,
|
||||
timeout=40,
|
||||
)
|
||||
print(r)
|
||||
except AssertionError:
|
||||
webhook = None
|
||||
return jsonify(mempool._asdict()), HTTPStatus.OK
|
Loading…
x
Reference in New Issue
Block a user