diff --git a/lnbits/extensions/satspay/crud.py b/lnbits/extensions/satspay/crud.py index c6f0d5b84..2591da9e2 100644 --- a/lnbits/extensions/satspay/crud.py +++ b/lnbits/extensions/satspay/crud.py @@ -3,8 +3,6 @@ from typing import List, Optional from loguru import logger -from loguru import logger - from lnbits.core.services import create_invoice from lnbits.core.views.api import api_payment from lnbits.helpers import urlsafe_short_hash @@ -14,7 +12,6 @@ from . import db from .helpers import fetch_onchain_balance from .models import Charges, CreateCharge, SatsPaySettings - ###############CHARGES########################## @@ -102,14 +99,12 @@ async def get_charges(user: str) -> List[Charges]: ) return [Charges.from_row(row) for row in rows] + async def get_settings(user: str) -> SatsPaySettings: row = await db.fetchone( """SELECT * FROM satspay.settings WHERE "user" = ?""", (user,), ) - logger.debug('Settings data') - logger.debug(row) - if row: return SatsPaySettings.from_row(row) else: @@ -150,10 +145,7 @@ async def save_settings(user: str, data: SatsPaySettings): """ UPDATE satspay.settings SET custom_css = ? WHERE user = ? """, - ( - data.custom_css, - user - ), + (data.custom_css, user), ) else: await db.execute( diff --git a/lnbits/extensions/satspay/models.py b/lnbits/extensions/satspay/models.py index d5f01b21c..94c0938c0 100644 --- a/lnbits/extensions/satspay/models.py +++ b/lnbits/extensions/satspay/models.py @@ -72,6 +72,7 @@ class Charges(BaseModel): def must_call_webhook(self): return self.webhook and self.paid and self.config.webhook_success == False + class SatsPaySettings(BaseModel): custom_css: str = Query(None) diff --git a/lnbits/extensions/satspay/templates/satspay/display.html b/lnbits/extensions/satspay/templates/satspay/display.html index a24ed84c7..da617a107 100644 --- a/lnbits/extensions/satspay/templates/satspay/display.html +++ b/lnbits/extensions/satspay/templates/satspay/display.html @@ -297,7 +297,12 @@
- +{% endblock %} {% block styles %} + {% endblock %} {% block scripts %} @@ -310,6 +315,7 @@ mixins: [windowMixin], data() { return { + customCss: '', charge: JSON.parse('{{charge_data | tojson}}'), mempoolEndpoint: '{{mempool_endpoint}}', network: '{{network}}', @@ -335,6 +341,27 @@ } }, methods: { + startPaymentNotifier() { + this.cancelListener() + if (!this.lnbitswallet) return + this.cancelListener = LNbits.events.onInvoicePaid( + this.wallet, + payment => { + this.checkInvoiceBalance() + } + ) + }, + getCustomCss: async function () { + try { + const {data} = await LNbits.api.request( + 'GET', + `/satspay/api/v1/settings/css/${this.charge.id}` + ) + this.customCss = data + } catch (error) { + LNbits.utils.notifyApiError(error) + } + }, checkBalances: async function () { if (!this.charge.payment_request && this.charge.hasOnchainStaleBalance) return @@ -438,6 +465,7 @@ } }, created: async function () { + await this.getCustomCss() if (this.charge.payment_request) this.payInvoice() else this.payOnchain() diff --git a/lnbits/extensions/satspay/templates/satspay/index.html b/lnbits/extensions/satspay/templates/satspay/index.html index 2c2d2ecae..ea29171b6 100644 --- a/lnbits/extensions/satspay/templates/satspay/index.html +++ b/lnbits/extensions/satspay/templates/satspay/index.html @@ -9,10 +9,12 @@ >New charge -