From b9856914506c73df4f22d1a63f4c3a6cb6f5288a Mon Sep 17 00:00:00 2001 From: Arc Date: Tue, 10 Dec 2024 18:43:03 +0000 Subject: [PATCH] format --- __init__.py | 7 ++++--- crud.py | 3 ++- migrations.py | 1 + static/js/index.js | 6 +++--- tasks.py | 22 +++++++++------------- templates/bitcoinswitch/index.html | 21 +++++++++++---------- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/__init__.py b/__init__.py index 10efe5c..300c2a7 100644 --- a/__init__.py +++ b/__init__.py @@ -4,7 +4,7 @@ from loguru import logger from .crud import db -from .tasks import wait_for_paid_invoices, get_nostr_events +from .tasks import get_nostr_events, wait_for_paid_invoices from .views import bitcoinswitch_generic_router from .views_api import bitcoinswitch_api_router from .views_lnurl import bitcoinswitch_lnurl_router @@ -35,15 +35,16 @@ def bitcoinswitch_stop(): def bitcoinswitch_start(): from lnbits.tasks import create_permanent_unique_task + task1 = create_permanent_unique_task("ext_bitcoinswitch", wait_for_paid_invoices) task2 = create_permanent_unique_task("ext_bitcoinswitch", get_nostr_events) scheduled_tasks.extend([task1, task2]) __all__ = [ - "db", "bitcoinswitch_ext", - "bitcoinswitch_static_files", "bitcoinswitch_start", + "bitcoinswitch_static_files", "bitcoinswitch_stop", + "db", ] diff --git a/crud.py b/crud.py index 22a3679..7a290cb 100644 --- a/crud.py +++ b/crud.py @@ -160,9 +160,10 @@ async def get_public_keys(): npubs = [record.npub for record in records if record.npub] return npubs + async def get_switch_from_npub(npub: str) -> Bitcoinswitch: return await db.fetchone( "SELECT * FROM bitcoinswitch.switch WHERE npub = :npub", {"npub": npub}, Bitcoinswitch, - ) \ No newline at end of file + ) diff --git a/migrations.py b/migrations.py index b2a8eec..567f4a0 100644 --- a/migrations.py +++ b/migrations.py @@ -36,6 +36,7 @@ async def m001_initial(db): """ ) + async def m002_add_npub(db): """ Add npubs diff --git a/static/js/index.js b/static/js/index.js index da342af..ab08b52 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -72,9 +72,9 @@ window.app = Vue.createApp({ 'formDialog.data.npub': { immediate: true, handler(newValue) { - this.formDialog.data.nostrfy = newValue !== ""; - }, - }, + this.formDialog.data.nostrfy = newValue !== '' + } + } }, computed: { wsMessage() { diff --git a/tasks.py b/tasks.py index 3920bac..65bbde7 100644 --- a/tasks.py +++ b/tasks.py @@ -1,26 +1,21 @@ import asyncio from bech32 import bech32_decode, convertbits - -from nostr.filter import Filter, Filters -from nostr.key import PublicKey -from nostr.message_type import ClientMessageType -from nostr.relay_manager import RelayManager -from nostr.subscription import Subscription -from nostr.event import Event - from lnbits.core.models import Payment from lnbits.core.services import websocket_updater -from lnbits.tasks import register_invoice_listener from lnbits.settings import settings +from lnbits.tasks import register_invoice_listener +from nostr.filter import Filter, Filters +from nostr.relay_manager import RelayManager from .crud import ( get_bitcoinswitch_payment, - update_bitcoinswitch_payment, get_public_keys, - get_switch_from_npub + get_switch_from_npub, + update_bitcoinswitch_payment, ) + async def wait_for_paid_invoices(): invoice_queue = asyncio.Queue() register_invoice_listener(invoice_queue, "ext_bitcoinswitch") @@ -60,11 +55,11 @@ async def on_invoice_paid(payment: Payment) -> None: payload, ) + async def get_nostr_events(): pub_keys = await get_public_keys() target_keys_hex = [ - decode_npub_to_hex(pk) if pk.startswith("npub") else pk - for pk in pub_keys + decode_npub_to_hex(pk) if pk.startswith("npub") else pk for pk in pub_keys ] relay_url = f"wss://localhost:{settings.port}/nostrclient/api/v1/relay" @@ -102,6 +97,7 @@ async def get_nostr_events(): finally: relay_manager.close_connections() + def decode_npub_to_hex(npub): hrp, data = bech32_decode(npub) if hrp != "npub" or data is None: diff --git a/templates/bitcoinswitch/index.html b/templates/bitcoinswitch/index.html index 1e05263..f5e57eb 100644 --- a/templates/bitcoinswitch/index.html +++ b/templates/bitcoinswitch/index.html @@ -292,15 +292,15 @@
- Use zaps for payments - + v-if="formDialog.data.switches.length < 2" + v-model="formDialog.data.nostrfy" + color="primary" + label="Zaps" + size="xs" + dense + > + Use zaps for payments +
@@ -311,7 +311,8 @@
dense v-model.trim="formDialog.data.npub" type="text" - label="Add your npub (limits to only one switch)"> + label="Add your npub (limits to only one switch)" + >