From 75d97ddfc1404c7b3bf79f0c3b6586ae3f182437 Mon Sep 17 00:00:00 2001 From: Eneko Illarramendi Date: Tue, 10 Mar 2020 23:12:22 +0100 Subject: [PATCH] refactor: camera ready --- lnbits/__init__.py | 6 +- lnbits/core/crud.py | 2 +- lnbits/core/static/js/index.js | 7 ++ lnbits/core/static/js/lnurl.js | 13 ---- lnbits/core/static/js/wallet.js | 43 ++++++++++-- lnbits/core/templates/core/index.html | 35 ++++++---- lnbits/core/templates/core/lnurl.html | 22 ------- lnbits/core/templates/core/wallet.html | 61 +++++++++++------- lnbits/core/views/generic.py | 2 +- lnbits/core/views/lnurl.py | 20 ++---- lnbits/static/css/base.css | 3 + lnbits/static/images/note.jpg | Bin 81049 -> 80498 bytes lnbits/static/scss/base.scss | 6 ++ .../vue-qrcode-reader.min.css | 1 + .../vue-qrcode-reader.min.js | 1 + 15 files changed, 126 insertions(+), 96 deletions(-) delete mode 100644 lnbits/core/static/js/lnurl.js delete mode 100644 lnbits/core/templates/core/lnurl.html create mode 100644 lnbits/static/vendor/vue-qrcode-reader@2.1.1/vue-qrcode-reader.min.css create mode 100644 lnbits/static/vendor/vue-qrcode-reader@2.1.1/vue-qrcode-reader.min.js diff --git a/lnbits/__init__.py b/lnbits/__init__.py index 5ac9c04..df4bd39 100644 --- a/lnbits/__init__.py +++ b/lnbits/__init__.py @@ -3,6 +3,8 @@ import importlib from flask import Flask from flask_assets import Environment, Bundle from flask_compress import Compress +from flask_limiter import Limiter +from flask_limiter.util import get_remote_address from flask_talisman import Talisman from os import getenv @@ -19,6 +21,7 @@ valid_extensions = [ext for ext in ExtensionManager().extensions if ext.is_valid # ----------------------- Compress(app) +Limiter(app, key_func=get_remote_address, default_limits=["1 per second"]) Talisman( app, force_https=getenv("LNBITS_WITH_ONION", 0) == 0, @@ -27,6 +30,7 @@ Talisman( "'self'", "'unsafe-eval'", "'unsafe-inline'", + "blob:", "cdnjs.cloudflare.com", "code.ionicframework.com", "code.jquery.com", @@ -78,5 +82,5 @@ def init(): init_databases() -if __name__ == '__main__': +if __name__ == "__main__": app.run() diff --git a/lnbits/core/crud.py b/lnbits/core/crud.py index 7620ed8..40f8b05 100644 --- a/lnbits/core/crud.py +++ b/lnbits/core/crud.py @@ -63,7 +63,7 @@ def update_user_extension(*, user_id: str, extension: str, active: int) -> None: # ------- -def create_wallet(*, user_id: str, wallet_name: Optional[str]) -> Wallet: +def create_wallet(*, user_id: str, wallet_name: Optional[str] = None) -> Wallet: with open_db() as db: wallet_id = uuid4().hex db.execute( diff --git a/lnbits/core/static/js/index.js b/lnbits/core/static/js/index.js index bc9b1bf..a348336 100644 --- a/lnbits/core/static/js/index.js +++ b/lnbits/core/static/js/index.js @@ -9,6 +9,13 @@ new Vue({ methods: { createWallet: function () { LNbits.href.createWallet(this.walletName); + }, + processing: function () { + this.$q.notify({ + timeout: 0, + message: 'Processing...', + icon: null + }); } } }); diff --git a/lnbits/core/static/js/lnurl.js b/lnbits/core/static/js/lnurl.js deleted file mode 100644 index 0670460..0000000 --- a/lnbits/core/static/js/lnurl.js +++ /dev/null @@ -1,13 +0,0 @@ -new Vue({ - el: '#vue', - mixins: [windowMixin], - methods: { - notify: function () { - this.$q.notify({ - timeout: 0, - message: 'Processing...', - icon: null - }); - } - } -}); diff --git a/lnbits/core/static/js/wallet.js b/lnbits/core/static/js/wallet.js index 0bd86bf..4419063 100644 --- a/lnbits/core/static/js/wallet.js +++ b/lnbits/core/static/js/wallet.js @@ -1,4 +1,5 @@ Vue.component(VueQrcode.name, VueQrcode); +Vue.use(VueQrcodeReader); function generateChart(canvas, payments) { @@ -119,6 +120,10 @@ new Vue({ bolt11: '' } }, + sendCamera: { + show: false, + camera: 'auto' + }, payments: [], paymentsTable: { columns: [ @@ -147,15 +152,26 @@ new Vue({ }, canPay: function () { if (!this.send.invoice) return false; - return this.send.invoice.sat < this.balance; + return this.send.invoice.sat <= this.balance; }, pendingPaymentsExist: function () { return (this.payments) ? _.where(this.payments, {pending: 1}).length > 0 : false; + }, + paymentsFiltered: function () { + return this.payments.filter(function (obj) { + return obj.isPaid; + }); } }, methods: { + closeCamera: function () { + this.sendCamera.show = false; + }, + showCamera: function () { + this.sendCamera.show = true; + }, showChart: function () { this.paymentsChart.show = true; this.$nextTick(function () { @@ -180,7 +196,8 @@ new Vue({ invoice: null, data: { bolt11: '' - } + }, + paymentChecker: null }; }, closeReceiveDialog: function () { @@ -189,6 +206,13 @@ new Vue({ clearInterval(checker); }, 10000); }, + closeSendDialog: function () { + this.sendCamera.show = false; + var checker = this.send.paymentChecker; + setTimeout(function () { + clearInterval(checker); + }, 1000); + }, createInvoice: function () { var self = this; this.receive.status = 'loading'; @@ -212,6 +236,11 @@ new Vue({ self.receive.status = 'pending'; }); }, + decodeQR: function (res) { + this.send.data.bolt11 = res; + this.decodeInvoice(); + this.sendCamera.show = false; + }, decodeInvoice: function () { try { var invoice = decode(this.send.data.bolt11); @@ -259,11 +288,11 @@ new Vue({ LNbits.utils.notifyApiError(error); }); - paymentChecker = setInterval(function () { + self.send.paymentChecker = setInterval(function () { LNbits.api.getPayment(self.w.wallet, self.send.invoice.hash).then(function (response) { if (response.data.paid) { - this.send.show = false; - clearInterval(paymentChecker); + self.send.show = false; + clearInterval(self.send.paymentChecker); dismissPaymentMsg(); self.fetchPayments(); } @@ -298,6 +327,8 @@ new Vue({ }, created: function () { this.fetchPayments(); - this.checkPendingPayments(); + setTimeout(function () { + this.checkPendingPayments(); + }, 1100); } }); diff --git a/lnbits/core/templates/core/index.html b/lnbits/core/templates/core/index.html index 5f1bc47..5908129 100644 --- a/lnbits/core/templates/core/index.html +++ b/lnbits/core/templates/core/index.html @@ -15,22 +15,29 @@
- {% block call_to_action %} - - - - + + + {% if lnurl %} Add a new wallet - - - - {% endblock %} + @click="notify" + type="a" href="{{ url_for('core.lnurlwallet', lightning=lnurl) }}"> + Press to claim bitcoin + + {% else %} + + + Add a new wallet + + {% endif %} + + diff --git a/lnbits/core/templates/core/lnurl.html b/lnbits/core/templates/core/lnurl.html deleted file mode 100644 index cad7ccb..0000000 --- a/lnbits/core/templates/core/lnurl.html +++ /dev/null @@ -1,22 +0,0 @@ -{% extends "core/index.html" %} - - -{% block scripts %} - {% assets filters='rjsmin', output='__bundle__/core/lnurl.js', - 'core/js/lnurl.js' %} - - {% endassets %} -{% endblock %} - -{% block call_to_action %} - - - - Press to claim bitcoin - - - -{% endblock %} diff --git a/lnbits/core/templates/core/wallet.html b/lnbits/core/templates/core/wallet.html index f729e3e..25fecbb 100644 --- a/lnbits/core/templates/core/wallet.html +++ b/lnbits/core/templates/core/wallet.html @@ -3,6 +3,10 @@ {% from "macros.jinja" import window_vars with context %} +{% block styles %} + +{% endblock %} + {% block scripts %} {{ window_vars(user, wallet) }} {% assets filters='rjsmin', output='__bundle__/core/chart.js', @@ -14,6 +18,7 @@ 'vendor/bolt11/utils.js', 'vendor/bolt11/decoder.js', 'vendor/vue-qrcode@1.0.2/vue-qrcode.min.js', + 'vendor/vue-qrcode-reader@2.1.1/vue-qrcode-reader.min.js', 'core/js/wallet.js' %} {% endassets %} @@ -59,7 +64,7 @@
@@ -74,7 +79,7 @@