From e818f34888386859264f54f3836c111f832660a6 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Mon, 28 Nov 2022 15:52:39 +0200 Subject: [PATCH] fix: rebase clean-up --- lnbits/extensions/satspay/crud.py | 7 +---- lnbits/extensions/satspay/migrations.py | 1 + .../satspay/templates/satspay/display.html | 13 --------- .../satspay/templates/satspay/index.html | 1 - lnbits/extensions/satspay/views.py | 7 ++--- lnbits/extensions/satspay/views_api.py | 28 +++++-------------- 6 files changed, 11 insertions(+), 46 deletions(-) diff --git a/lnbits/extensions/satspay/crud.py b/lnbits/extensions/satspay/crud.py index c1b0948cc..13e114e35 100644 --- a/lnbits/extensions/satspay/crud.py +++ b/lnbits/extensions/satspay/crud.py @@ -7,8 +7,8 @@ from lnbits.core.services import create_invoice from lnbits.core.views.api import api_payment from lnbits.helpers import urlsafe_short_hash -from . import db from ..watchonly.crud import get_config, get_fresh_address +from . import db from .helpers import fetch_onchain_balance from .models import Charges, CreateCharge, SatsPayThemes @@ -26,9 +26,6 @@ async def create_charge(user: str, data: CreateCharge) -> Charges: onchainaddress = onchain.address else: onchainaddress = None - data.extra = json.dumps( - {"mempool_endpoint": "https://mempool.space", "network": "Mainnet"} - ) if data.lnbitswallet: payment_hash, payment_request = await create_invoice( wallet_id=data.lnbitswallet, @@ -81,7 +78,6 @@ async def create_charge(user: str, data: CreateCharge) -> Charges: data.extra, ), ) - logger.debug(await get_charge(charge_id)) return await get_charge(charge_id) @@ -96,7 +92,6 @@ async def update_charge(charge_id: str, **kwargs) -> Optional[Charges]: async def get_charge(charge_id: str) -> Charges: row = await db.fetchone("SELECT * FROM satspay.charges WHERE id = ?", (charge_id,)) - return Charges.from_row(row) if row else None diff --git a/lnbits/extensions/satspay/migrations.py b/lnbits/extensions/satspay/migrations.py index a1c6d30b5..ff6b44be8 100644 --- a/lnbits/extensions/satspay/migrations.py +++ b/lnbits/extensions/satspay/migrations.py @@ -38,6 +38,7 @@ async def m002_add_charge_extra_data(db): """ ) + async def m003_add_themes_table(db): """ Themes table diff --git a/lnbits/extensions/satspay/templates/satspay/display.html b/lnbits/extensions/satspay/templates/satspay/display.html index b91e6fe41..8fc240c71 100644 --- a/lnbits/extensions/satspay/templates/satspay/display.html +++ b/lnbits/extensions/satspay/templates/satspay/display.html @@ -320,11 +320,9 @@ mixins: [windowMixin], data() { return { - customCss: '', charge: JSON.parse('{{charge_data | tojson}}'), mempoolEndpoint: '{{mempool_endpoint}}', network: '{{network}}', - css_id: '{{ charge_data.css_id }}', pendingFunds: 0, ws: null, newProgress: 0.4, @@ -347,16 +345,6 @@ } }, methods: { - startPaymentNotifier() { - this.cancelListener() - if (!this.lnbitswallet) return - this.cancelListener = LNbits.events.onInvoicePaid( - this.wallet, - payment => { - this.checkInvoiceBalance() - } - ) - }, checkBalances: async function () { if (!this.charge.payment_request && this.charge.hasOnchainStaleBalance) return @@ -463,7 +451,6 @@ await this.getCustomCss() if (this.charge.payment_request) this.payInvoice() // Remove a user defined theme - console.log(this.charge.custom_css) if (this.charge.custom_css) { document.body.setAttribute('data-theme', '') } diff --git a/lnbits/extensions/satspay/templates/satspay/index.html b/lnbits/extensions/satspay/templates/satspay/index.html index a77b444d2..fd8cf1ec0 100644 --- a/lnbits/extensions/satspay/templates/satspay/index.html +++ b/lnbits/extensions/satspay/templates/satspay/index.html @@ -952,7 +952,6 @@ } }, created: async function () { - console.log(this.admin) if (this.admin == 'True') { await this.getThemes() } diff --git a/lnbits/extensions/satspay/views.py b/lnbits/extensions/satspay/views.py index 8bffc2b92..a8ccbd39b 100644 --- a/lnbits/extensions/satspay/views.py +++ b/lnbits/extensions/satspay/views.py @@ -17,8 +17,6 @@ from lnbits.settings import LNBITS_ADMIN_USERS from . import satspay_ext, satspay_renderer from .crud import get_charge, get_theme -from loguru import logger - templates = Jinja2Templates(directory="templates") @@ -39,15 +37,14 @@ async def display(request: Request, charge_id: str): raise HTTPException( status_code=HTTPStatus.NOT_FOUND, detail="Charge link does not exist." ) - extra = json.loads(charge.extra) return satspay_renderer().TemplateResponse( "satspay/display.html", { "request": request, "charge_data": public_charge(charge), - "mempool_endpoint": extra["mempool_endpoint"], - "network": extra["network"], + "mempool_endpoint": charge.config.mempool_endpoint, + "network": charge.config.network, }, ) diff --git a/lnbits/extensions/satspay/views_api.py b/lnbits/extensions/satspay/views_api.py index b0c298fa8..09884040e 100644 --- a/lnbits/extensions/satspay/views_api.py +++ b/lnbits/extensions/satspay/views_api.py @@ -7,30 +7,27 @@ from loguru import logger from starlette.exceptions import HTTPException from lnbits.core.crud import get_wallet -from lnbits.decorators import (WalletTypeInfo, get_key_type, require_admin_key, - require_invoice_key) +from lnbits.decorators import ( + WalletTypeInfo, + get_key_type, + require_admin_key, + require_invoice_key, +) from lnbits.extensions.satspay import satspay_ext from lnbits.settings import LNBITS_ADMIN_EXTENSIONS, LNBITS_ADMIN_USERS -from lnbits.settings import ( - LNBITS_ADMIN_EXTENSIONS, - LNBITS_ADMIN_USERS, -) - from .crud import ( check_address_balance, create_charge, delete_charge, + delete_theme, get_charge, get_charges, get_theme, get_themes, - delete_theme, save_theme, update_charge, ) - -from .models import CreateCharge, SatsPayThemes from .helpers import call_webhook, public_charge from .models import CreateCharge, SatsPayThemes @@ -136,17 +133,6 @@ async def api_charge_balance(charge_id): extra = {**charge.config.dict(), **resp} await update_charge(charge_id=charge.id, extra=json.dumps(extra)) - if charge.paid and charge.webhook: - async with httpx.AsyncClient() as client: - try: - r = await client.post( - charge.webhook, - json=public_charge(charge), - timeout=40, - ) - except AssertionError: - charge.webhook = None - return {**public_charge(charge)}