mirror of
https://github.com/lnbits/lnbits.git
synced 2025-10-04 18:33:10 +02:00
Added countedown
This commit is contained in:
@@ -9,7 +9,9 @@ from lnbits.helpers import urlsafe_short_hash
|
||||
from quart import jsonify
|
||||
import httpx
|
||||
from lnbits.core.services import create_invoice, check_invoice_status
|
||||
from ..watchonly.crud import get_watch_wallet, get_derive_address
|
||||
from ..watchonly.crud import get_watch_wallet, get_derive_address, get_mempool
|
||||
|
||||
import time
|
||||
|
||||
###############CHARGES##########################
|
||||
|
||||
@@ -66,10 +68,7 @@ async def get_charge(charge_id: str) -> Charges:
|
||||
|
||||
async def get_charges(user: str) -> List[Charges]:
|
||||
rows = await db.fetchall("SELECT * FROM charges WHERE user = ?", (user,))
|
||||
for row in rows:
|
||||
await check_address_balance(row.id)
|
||||
rows = await db.fetchall("SELECT * FROM charges WHERE user = ?", (user,))
|
||||
return [charges.from_row(row) for row in rows]
|
||||
return [Charges.from_row(row) for row in rows]
|
||||
|
||||
|
||||
async def delete_charge(charge_id: str) -> None:
|
||||
|
@@ -13,7 +13,6 @@ async def m001_initial(db):
|
||||
onchainwallet TEXT,
|
||||
onchainaddress TEXT,
|
||||
lnbitswallet TEXT,
|
||||
lnbitskey TEXT,
|
||||
payment_request TEXT,
|
||||
payment_hash TEXT,
|
||||
webhook TEXT,
|
||||
|
@@ -36,12 +36,10 @@
|
||||
:filter="filter"
|
||||
>
|
||||
|
||||
|
||||
<template v-slot:header="props">
|
||||
<q-tr :props="props">
|
||||
<q-th auto-width></q-th>
|
||||
|
||||
|
||||
<q-th auto-width></q-th>
|
||||
|
||||
<q-th v-for="col in props.cols" :key="col.name" :props="props" auto-width>
|
||||
<div v-if="col.name == 'id'"></div>
|
||||
@@ -52,8 +50,10 @@
|
||||
<q-th auto-width></q-th>
|
||||
</q-tr>
|
||||
</template>
|
||||
|
||||
<template v-slot:body="props">
|
||||
<q-tr :props="props">
|
||||
|
||||
<q-td auto-width>
|
||||
<q-btn
|
||||
unelevated
|
||||
@@ -76,7 +76,7 @@
|
||||
:color="($q.dark.isActive) ? 'red' : 'red'"
|
||||
></q-icon>
|
||||
|
||||
<q-icon v-else-if="props.row.amount_paid > props.row.amount"
|
||||
<q-icon v-else-if="props.row.balance > props.row.amount"
|
||||
#unelevated
|
||||
dense
|
||||
size="xs"
|
||||
@@ -91,9 +91,6 @@
|
||||
name="cached"
|
||||
:color="($q.dark.isActive) ? 'blue' : 'blue'"
|
||||
></q-icon>
|
||||
|
||||
|
||||
|
||||
<q-btn
|
||||
flat
|
||||
dense
|
||||
@@ -286,10 +283,19 @@
|
||||
}
|
||||
var mapCharge = function (obj) {
|
||||
obj._data = _.clone(obj)
|
||||
obj.theDate = ( obj.time + obj.timestamp - ((Date.now()/1000)))
|
||||
console.log(obj.theDate)
|
||||
if(obj.theDate < 0){
|
||||
obj.date = "Time elapsed"
|
||||
}
|
||||
else{
|
||||
obj.date = Quasar.utils.date.formatDate(
|
||||
new Date(obj.time * 1000),
|
||||
'YYYY-MM-DD HH:mm'
|
||||
|
||||
new Date(obj.theDate * 1000),
|
||||
'HH:mm:ss'
|
||||
)
|
||||
}
|
||||
|
||||
obj.displayUrl = ['/satspay/', obj.id].join('')
|
||||
return obj
|
||||
}
|
||||
@@ -318,12 +324,11 @@
|
||||
|
||||
ChargesTable: {
|
||||
columns: [
|
||||
{name: 'id', align: 'left', label: 'ID', field: 'id'},
|
||||
{
|
||||
name: 'title',
|
||||
name: 'description',
|
||||
align: 'left',
|
||||
label: 'Title',
|
||||
field: 'title'
|
||||
field: 'description'
|
||||
},
|
||||
{
|
||||
name: 'amount',
|
||||
@@ -335,7 +340,7 @@
|
||||
name: 'balance',
|
||||
align: 'left',
|
||||
label: 'Balance',
|
||||
field: 'amount_paid'
|
||||
field: 'balance'
|
||||
},
|
||||
{
|
||||
name: 'onchain address',
|
||||
@@ -347,19 +352,19 @@
|
||||
name: 'LNbits wallet',
|
||||
align: 'left',
|
||||
label: 'LNbits wallet',
|
||||
field: 'lnbits-wallet'
|
||||
field: 'lnbitswallet'
|
||||
},
|
||||
{
|
||||
name: 'time to pay',
|
||||
align: 'left',
|
||||
label: 'Time to Pay',
|
||||
field: 'time_to_pay'
|
||||
field: 'time'
|
||||
},
|
||||
{
|
||||
name: 'timeleft',
|
||||
align: 'left',
|
||||
label: 'Time left',
|
||||
field: 'timeleft'
|
||||
field: 'date'
|
||||
},
|
||||
],
|
||||
pagination: {
|
||||
@@ -459,7 +464,10 @@
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
self.ChargeLinks = response.data.map(function (obj) {
|
||||
console.log(obj.timestamp)
|
||||
console.log(Date.now()/1000)
|
||||
return mapCharge(obj)
|
||||
})
|
||||
})
|
||||
@@ -499,6 +507,21 @@
|
||||
LNbits.utils.notifyApiError(error)
|
||||
})
|
||||
},
|
||||
getBalance: function (walletId) {
|
||||
var self = this
|
||||
LNbits.api
|
||||
.request(
|
||||
'GET',
|
||||
'/satspay/api/v1/charges/balance/' + walletId,
|
||||
this.g.user.wallets[0].inkey
|
||||
)
|
||||
.then(function (response) {
|
||||
console.log(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
LNbits.utils.notifyApiError(error)
|
||||
})
|
||||
},
|
||||
createCharge: function (wallet, data) {
|
||||
var self = this
|
||||
|
||||
@@ -598,26 +621,16 @@
|
||||
|
||||
},
|
||||
created: function () {
|
||||
var getWalletLinks = this.getWalletLinks
|
||||
getWalletLinks()
|
||||
var self = this
|
||||
var getCharges = this.getCharges
|
||||
getCharges()
|
||||
|
||||
if (this.g.user.wallets.length) {
|
||||
for (i = 0; i < this.g.extensions.length; i++) {
|
||||
if(this.g.extensions[i].code == "watchonly"){
|
||||
console.log(this.walletLinks)
|
||||
if(this.walletLinks.length > 0 ){
|
||||
this.watchonlyactive = true
|
||||
var getBalance = this.getBalance
|
||||
setTimeout(function(){
|
||||
for (i = 0; i < self.ChargeLinks.length; i++) {
|
||||
getBalance(self.ChargeLinks[i].id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}, 5000);
|
||||
getCharges()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
@@ -13,75 +13,28 @@ from .crud import (
|
||||
get_charge,
|
||||
get_charges,
|
||||
delete_charge,
|
||||
check_address_balance,
|
||||
)
|
||||
|
||||
###################WALLETS#############################
|
||||
|
||||
@satspay_ext.route("/api/v1/wallet", methods=["GET"])
|
||||
@api_check_wallet_key("invoice")
|
||||
async def api_wallets_retrieve():
|
||||
|
||||
try:
|
||||
return (
|
||||
jsonify([wallet._asdict() for wallet in await get_watch_wallets(g.wallet.user)]), HTTPStatus.OK
|
||||
)
|
||||
except:
|
||||
return ""
|
||||
|
||||
@satspay_ext.route("/api/v1/wallet/<wallet_id>", methods=["GET"])
|
||||
@api_check_wallet_key("invoice")
|
||||
async def api_wallet_retrieve(wallet_id):
|
||||
wallet = await get_watch_wallet(wallet_id)
|
||||
|
||||
if not wallet:
|
||||
return jsonify({"message": "wallet does not exist"}), HTTPStatus.NOT_FOUND
|
||||
|
||||
return jsonify({wallet}), HTTPStatus.OK
|
||||
|
||||
|
||||
@satspay_ext.route("/api/v1/wallet", methods=["POST"])
|
||||
@satspay_ext.route("/api/v1/wallet/<wallet_id>", methods=["PUT"])
|
||||
@api_check_wallet_key("invoice")
|
||||
@api_validate_post_request(
|
||||
schema={
|
||||
"masterpub": {"type": "string", "empty": False, "required": True},
|
||||
"title": {"type": "string", "empty": False, "required": True},
|
||||
}
|
||||
)
|
||||
async def api_wallet_create_or_update(wallet_id=None):
|
||||
print("g.data")
|
||||
if not wallet_id:
|
||||
wallet = await create_watch_wallet(user=g.wallet.user, masterpub=g.data["masterpub"], title=g.data["title"])
|
||||
mempool = await get_mempool(g.wallet.user)
|
||||
if not mempool:
|
||||
create_mempool(user=g.wallet.user)
|
||||
return jsonify(wallet._asdict()), HTTPStatus.CREATED
|
||||
else:
|
||||
wallet = await update_watch_wallet(wallet_id=wallet_id, **g.data)
|
||||
return jsonify(wallet._asdict()), HTTPStatus.OK
|
||||
|
||||
|
||||
@satspay_ext.route("/api/v1/wallet/<wallet_id>", methods=["DELETE"])
|
||||
@api_check_wallet_key("invoice")
|
||||
async def api_wallet_delete(wallet_id):
|
||||
wallet = await get_watch_wallet(wallet_id)
|
||||
|
||||
if not wallet:
|
||||
return jsonify({"message": "Wallet link does not exist."}), HTTPStatus.NOT_FOUND
|
||||
|
||||
await delete_watch_wallet(wallet_id)
|
||||
|
||||
return jsonify({"deleted": "true"}), HTTPStatus.NO_CONTENT
|
||||
|
||||
|
||||
#############################CHARGES##########################
|
||||
@satspay_ext.route("/api/v1/charges/balance/<charge_id>", methods=["GET"])
|
||||
@api_check_wallet_key("invoice")
|
||||
async def api_charges_balance(charge_id):
|
||||
|
||||
charge = await check_address_balance(charge_id)
|
||||
if not charge:
|
||||
return (
|
||||
jsonify(""),
|
||||
HTTPStatus.OK
|
||||
)
|
||||
else:
|
||||
return jsonify(charge._asdict()), HTTPStatus.OK
|
||||
|
||||
@satspay_ext.route("/api/v1/charges", methods=["GET"])
|
||||
@api_check_wallet_key("invoice")
|
||||
async def api_charges_retrieve():
|
||||
|
||||
charges = await get_charges(g.wallet.user)
|
||||
print(charges)
|
||||
if not charges:
|
||||
return (
|
||||
jsonify(""),
|
||||
@@ -107,8 +60,8 @@ async def api_charge_retrieve(charge_id):
|
||||
@api_check_wallet_key("invoice")
|
||||
@api_validate_post_request(
|
||||
schema={
|
||||
"onchainwallet": {"type": "string", "empty": False, "required": True},
|
||||
"lnbitswallet": {"type": "string", "empty": False, "required": True},
|
||||
"onchainwallet": {"type": "string"},
|
||||
"lnbitswallet": {"type": "string"},
|
||||
"description": {"type": "string", "empty": False, "required": True},
|
||||
"webhook": {"type": "string", "empty": False, "required": True},
|
||||
"time": {"type": "integer", "min": 1, "required": True},
|
||||
|
Reference in New Issue
Block a user