mirror of
https://github.com/lnbits/lnbits.git
synced 2025-10-09 12:02:39 +02:00
Added paylinks to table
This commit is contained in:
@@ -136,7 +136,7 @@ async def get_payment(payment_id: str) -> Payments:
|
|||||||
|
|
||||||
|
|
||||||
async def get_payments(user: str) -> List[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])
|
print(rows[0])
|
||||||
return [Payments.from_row(row) for row in rows]
|
return [Payments.from_row(row) for row in rows]
|
||||||
|
|
||||||
|
@@ -35,6 +35,7 @@ async def m001_initial(db):
|
|||||||
address TEXT NOT NULL,
|
address TEXT NOT NULL,
|
||||||
time_to_pay INTEGER NOT NULL,
|
time_to_pay INTEGER NOT NULL,
|
||||||
amount INTEGER NOT NULL,
|
amount INTEGER NOT NULL,
|
||||||
|
amount_paid INTEGER DEFAULT 0,
|
||||||
time TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now'))
|
time TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now'))
|
||||||
);
|
);
|
||||||
"""
|
"""
|
||||||
|
@@ -21,6 +21,7 @@ class Payments(NamedTuple):
|
|||||||
address: str
|
address: str
|
||||||
time_to_pay: str
|
time_to_pay: str
|
||||||
amount: int
|
amount: int
|
||||||
|
amount_paid: int
|
||||||
time: int
|
time: int
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@@ -324,7 +324,7 @@
|
|||||||
dense
|
dense
|
||||||
v-model.trim="formDialogPayment.data.time"
|
v-model.trim="formDialogPayment.data.time"
|
||||||
type="number"
|
type="number"
|
||||||
label="Time (mins)"
|
label="Time (secs)"
|
||||||
> </q-input>
|
> </q-input>
|
||||||
|
|
||||||
<div class="row q-mt-lg">
|
<div class="row q-mt-lg">
|
||||||
@@ -512,10 +512,16 @@
|
|||||||
field: 'amount'
|
field: 'amount'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'time',
|
name: 'time to pay',
|
||||||
align: 'left',
|
align: 'left',
|
||||||
label: 'time',
|
label: 'Time to Pay (secs)',
|
||||||
field: 'time'
|
field: 'time_to_pay'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'timeleft',
|
||||||
|
align: 'left',
|
||||||
|
label: 'Time left (secs)',
|
||||||
|
field: 'timeleft'
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
pagination: {
|
pagination: {
|
||||||
@@ -646,6 +652,7 @@
|
|||||||
)
|
)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
self.walletLinks = response.data.map(function (obj) {
|
self.walletLinks = response.data.map(function (obj) {
|
||||||
|
|
||||||
return mapWalletLink(obj)
|
return mapWalletLink(obj)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -692,7 +699,20 @@
|
|||||||
this.g.user.wallets[0].inkey
|
this.g.user.wallets[0].inkey
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.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) {
|
self.paymentLinks = response.data.map(function (obj) {
|
||||||
|
console.log(mapPayment(obj))
|
||||||
return mapPayment(obj)
|
return mapPayment(obj)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import hashlib
|
import hashlib
|
||||||
from quart import g, jsonify, request, url_for
|
from quart import g, jsonify, request, url_for
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
|
import httpx
|
||||||
|
|
||||||
from lnbits.core.crud import get_user
|
from lnbits.core.crud import get_user
|
||||||
from lnbits.decorators import api_check_wallet_key, api_validate_post_request
|
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
|
return jsonify([address._asdict() for address in addresses]), HTTPStatus.OK
|
||||||
|
|
||||||
|
|
||||||
#############################PAYEMENTS##########################
|
#############################PAYEMENTS##########################
|
||||||
|
|
||||||
@watchonly_ext.route("/api/v1/payment", methods=["GET"])
|
@watchonly_ext.route("/api/v1/payment", methods=["GET"])
|
||||||
@api_check_wallet_key("invoice")
|
@api_check_wallet_key("invoice")
|
||||||
async def api_payments_retrieve():
|
async def api_payments_retrieve():
|
||||||
|
|
||||||
try:
|
payments = await get_payments(g.wallet.user)
|
||||||
payments = await get_payments(g.wallet.user)
|
print(payments)
|
||||||
print(payments)
|
if not payments:
|
||||||
return (
|
|
||||||
jsonify(payments),
|
|
||||||
HTTPStatus.OK,
|
|
||||||
)
|
|
||||||
except:
|
|
||||||
return (
|
return (
|
||||||
jsonify({"message": "Cant fetch."}),
|
jsonify({"message": "Cant fetch."}),
|
||||||
HTTPStatus.UPGRADE_REQUIRED,
|
HTTPStatus.UPGRADE_REQUIRED,
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
return jsonify([payment._asdict() for payment in payments]), HTTPStatus.OK
|
||||||
|
|
||||||
|
|
||||||
@watchonly_ext.route("/api/v1/payment/<payment_id>", methods=["GET"])
|
@watchonly_ext.route("/api/v1/payment/<payment_id>", methods=["GET"])
|
||||||
@api_check_wallet_key("invoice")
|
@api_check_wallet_key("invoice")
|
||||||
@@ -197,3 +197,18 @@ async def api_get_mempool():
|
|||||||
if not mempool:
|
if not mempool:
|
||||||
mempool = await create_mempool(user=g.wallet.user)
|
mempool = await create_mempool(user=g.wallet.user)
|
||||||
return jsonify(mempool._asdict()), HTTPStatus.OK
|
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
|
Reference in New Issue
Block a user