Cleaning up watchonly

This commit is contained in:
benarc
2021-02-23 14:31:05 +00:00
parent 6e4f8431b7
commit be6ee64b4e
4 changed files with 14 additions and 247 deletions

View File

@@ -2,18 +2,7 @@ async def m001_initial(db):
"""
Initial wallet table.
"""
await db.execute(
"""
CREATE TABLE IF NOT EXISTS wallets (
id TEXT NOT NULL PRIMARY KEY,
user TEXT,
masterpub TEXT NOT NULL,
title TEXT NOT NULL,
address_no INTEGER NOT NULL DEFAULT 0,
balance INTEGER NOT NULL
);
"""
)
await db.execute(
"""
@@ -29,12 +18,4 @@ async def m001_initial(db):
time TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now'))
);
"""
)
await db.execute(
"""
CREATE TABLE IF NOT EXISTS mempool (
user TEXT NOT NULL,
endpoint TEXT NOT NULL
);
"""
)

View File

@@ -170,6 +170,14 @@
label="Time (secs)"
> </q-input>
<q-input
filled
dense
v-model.trim="formDialogCharge.data.webhook"
type="url"
label="Webhook"
> </q-input>
<div class="row">
<div class="col">
<div v-if="walletLinks.length > 0">
@@ -375,7 +383,7 @@
.then(function (response) {
for (i = 0; i < response.data.length; i++) {
self.walletLinks.push(response.data[i].title + " " + response.data[i].id)
self.walletLinks.push(response.data[i].id)
}
console.log(self.walletLinks)

View File

@@ -81,7 +81,7 @@
<template v-slot:body="props">
<q-tr :props="props">
<q-td auto-width>
<q-td auto-width>
<q-btn
unelevated
@@ -195,62 +195,6 @@
</q-card>
</q-dialog>
<q-dialog v-model="formDialogCharge.show" position="top" @hide="closeFormDialog">
<q-card class="q-pa-lg q-pt-xl lnbits__dialog-card">
<q-form @submit="sendFormDataCharge" class="q-gutter-md">
<q-input
filled
dense
v-model.trim="formDialogCharge.data.title"
type="text"
label="Title"
></q-input>
<q-input
filled
dense
v-model.trim="formDialogCharge.data.amount"
type="number"
label="Amount (sats)"
></q-input>
<q-input
filled
dense
v-model.trim="formDialogCharge.data.time"
type="number"
label="Time (secs)"
> </q-input>
<div class="row q-mt-lg">
<q-btn
v-if="formDialogCharge.data.id"
unelevated
color="deep-purple"
type="submit"
>Update Paylink</q-btn
>
<q-btn
v-else
unelevated
color="deep-purple"
:disable="
formDialogCharge.data.time == null ||
formDialogCharge.data.amount == null"
type="submit"
>Create Paylink</q-btn
>
<q-btn v-close-popup flat color="grey" class="q-ml-auto"
>Cancel</q-btn
>
</div>
</q-form>
</q-card>
</q-dialog>
<q-dialog v-model="Addresses.show" position="top">
<q-card v-if="Addresses.data" class="q-pa-lg lnbits__dialog-card">
{% raw %}
@@ -378,6 +322,7 @@
label: 'Title',
field: 'title'
},
{
name: 'amount',
align: 'left',
@@ -443,10 +388,7 @@
show: false,
data: {}
},
formDialogCharge: {
show: false,
data: {}
},
qrCodeDialog: {
show: false,
data: null
@@ -494,9 +436,7 @@
},
chargeRedirect: function (address){
window.location.href = this.mempool.endpoint + "/address/" + address;
},
getMempool: function () {
var self = this
@@ -580,105 +520,6 @@
}
},
getCharges: function () {
var self = this
var getAddressBalance = this.getAddressBalance
LNbits.api
.request(
'GET',
'/watchonly/api/v1/ChargeLinks',
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
}
}
self.ChargeLinks = response.data.map(function (obj) {
return mapCharge(obj)
})
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
},
sendFormDataCharge: function () {
var self = this
var wallet = self.g.user.wallets[0]
var data = self.formDialogCharge.data
data.amount = parseInt(data.amount)
data.time = parseInt(data.time)
if (data.id) {
this.updateCharge(wallet, data)
} else {
this.createCharge(wallet, data)
}
},
updateCharge: function (wallet, data) {
var self = this
LNbits.api
.request(
'PUT',
'/watchonly/api/v1/Charge/' + data.id,
wallet.inkey, data)
.then(function (response) {
self.Charge = _.reject(self.Charge, function (obj) {
return obj.id === data.id
})
self.Charge.push(mapCharge(response.data))
self.formDialogPayLink.show = false
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
},
createCharge: function (wallet, data) {
var self = this
LNbits.api
.request('POST', '/watchonly/api/v1/Charge', wallet.inkey, data)
.then(function (response) {
self.ChargeLinks.push(mapCharge(response.data))
self.formDialogCharge.show = false
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
},
deleteCharge: function (linkId) {
var self = this
var link = _.findWhere(this.Charge, {id: linkId})
console.log(self.g.user.wallets[0].adminkey)
LNbits.utils
.confirmDialog('Are you sure you want to delete this pay link?')
.onOk(function () {
LNbits.api
.request(
'DELETE',
'/watchonly/api/v1/Charge/' + linkId,
self.g.user.wallets[0].inkey
)
.then(function (response) {
self.Charge = _.reject(self.Charge, function (obj) {
return obj.id === linkId
})})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
})
},
updateWalletLink: function (wallet, data) {
var self = this
@@ -743,8 +584,6 @@
if (this.g.user.wallets.length) {
var getWalletLinks = this.getWalletLinks
getWalletLinks()
var getCharges = this.getCharges
getCharges()
var getMempool = this.getMempool
getMempool()

View File

@@ -82,67 +82,6 @@ async def api_wallet_delete(wallet_id):
return jsonify({"deleted": "true"}), HTTPStatus.NO_CONTENT
#############################CHARGES##########################
@watchonly_ext.route("/api/v1/charges", methods=["GET"])
@api_check_wallet_key("invoice")
async def api_charges_retrieve():
charges = await get_charges(g.wallet.user)
if not charges:
return (
jsonify(""),
HTTPStatus.OK
)
else:
return jsonify([charge._asdict() for charge in charges]), HTTPStatus.OK
@watchonly_ext.route("/api/v1/charge/<charge_id>", methods=["GET"])
@api_check_wallet_key("invoice")
async def api_charge_retrieve(charge_id):
charge = get_charge(charge_id)
if not charge:
return jsonify({"message": "charge does not exist"}), HTTPStatus.NOT_FOUND
return jsonify({charge}), HTTPStatus.OK
@watchonly_ext.route("/api/v1/charge", methods=["POST"])
@watchonly_ext.route("/api/v1/charge/<charge_id>", methods=["PUT"])
@api_check_wallet_key("invoice")
@api_validate_post_request(
schema={
"walletid": {"type": "string", "empty": False, "required": True},
"title": {"type": "string", "empty": False, "required": True},
"time": {"type": "integer", "min": 1, "required": True},
"amount": {"type": "integer", "min": 1, "required": True},
}
)
async def api_charge_create_or_update(charge_id=None):
if not charge_id:
charge = await create_charge(user = g.wallet.user, **g.data)
return jsonify(charge), HTTPStatus.CREATED
else:
charge = await update_charge(user = g.wallet.user, **g.data)
return jsonify(charge), HTTPStatus.OK
@watchonly_ext.route("/api/v1/charge/<charge_id>", methods=["DELETE"])
@api_check_wallet_key("invoice")
async def api_charge_delete(charge_id):
charge = await get_watch_wallet(charge_id)
if not charge:
return jsonify({"message": "Wallet link does not exist."}), HTTPStatus.NOT_FOUND
await delete_watch_wallet(charge_id)
return "", HTTPStatus.NO_CONTENT
#############################MEMPOOL##########################
@watchonly_ext.route("/api/v1/mempool", methods=["PUT"])