From 7ba506923ee9ac709023e6deffe708d5b18d8304 Mon Sep 17 00:00:00 2001 From: benarc Date: Mon, 14 Sep 2020 20:20:12 +0100 Subject: [PATCH] Admin top up complete --- lnbits/core/services.py | 14 +++++++++++ lnbits/core/static/js/wallet.js | 28 +++++++++++++++++++++ lnbits/core/templates/core/wallet.html | 34 ++++++++++++++++++++++++-- lnbits/core/views/api.py | 18 +++++++++++--- lnbits/static/js/base.js | 5 ++++ 5 files changed, 94 insertions(+), 5 deletions(-) diff --git a/lnbits/core/services.py b/lnbits/core/services.py index fd42aa6..94011f2 100644 --- a/lnbits/core/services.py +++ b/lnbits/core/services.py @@ -125,3 +125,17 @@ def check_invoice_status(wallet_id: str, payment_hash: str) -> PaymentStatus: return PaymentStatus(None) return WALLET.get_invoice_status(payment.checking_id) + +def update_wallet_balance(wallet_id: str, amount: int) -> str: + temp_id = f"temp_{urlsafe_short_hash()}" + internal_id = f"internal_{urlsafe_short_hash()}" + create_payment( + wallet_id=wallet_id, + checking_id=internal_id, + payment_request="admin_internal", + payment_hash="admin_internal", + amount=amount*1000, + memo="admin_internal", + pending=False, + ) + return "admin_internal" diff --git a/lnbits/core/static/js/wallet.js b/lnbits/core/static/js/wallet.js index 140ca47..65580c1 100644 --- a/lnbits/core/static/js/wallet.js +++ b/lnbits/core/static/js/wallet.js @@ -127,6 +127,12 @@ new Vue({ memo: '' } }, + update: { + show: false, + data: { + amount: null + } + }, send: { show: false, invoice: null, @@ -241,6 +247,14 @@ new Vue({ paymentChecker: null } }, + showUpdateDialog: function () { + this.update = { + show: true, + data: { + amount: null + } + } + }, closeReceiveDialog: function () { var checker = this.receive.paymentChecker setTimeout(function () { @@ -284,6 +298,20 @@ new Vue({ self.receive.status = 'pending' }) }, + updateBalance: function () { + var self = this + self.receive.status = 'loading' + LNbits.api + .updateBalance(self.g.wallet, self.update.data.amount) + .then(function (response) { + self.fetchPayments() + self.update.show = false + }) + .catch(function (error) { + LNbits.utils.notifyApiError(error) + self.receive.status = 'pending' + }) + }, decodeQR: function (res) { this.send.data.bolt11 = res this.decodeInvoice() diff --git a/lnbits/core/templates/core/wallet.html b/lnbits/core/templates/core/wallet.html index daf9420..573f45d 100644 --- a/lnbits/core/templates/core/wallet.html +++ b/lnbits/core/templates/core/wallet.html @@ -25,8 +25,14 @@

{% raw %}{{ fbalance }}{% endraw %} sat {% if admin %} - - Update balance + + Admin top up {% endif %}

@@ -251,6 +257,30 @@ + + + + +
+ Top up + Cancel +
+
+
+
+