Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
arcbtc committed Dec 10, 2024
1 parent da11501 commit b985691
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 30 deletions.
7 changes: 4 additions & 3 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
]
3 changes: 2 additions & 1 deletion crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
)
1 change: 1 addition & 0 deletions migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async def m001_initial(db):
"""
)


async def m002_add_npub(db):
"""
Add npubs
Expand Down
6 changes: 3 additions & 3 deletions static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
22 changes: 9 additions & 13 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down
21 changes: 11 additions & 10 deletions templates/bitcoinswitch/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,15 @@ <h5 v-html="formDialog.data.device" v-if="formDialog.data.id"></h5>
</div>
<div class="col q-ml-md">
<q-checkbox
v-if="formDialog.data.switches.length < 2"
v-model="formDialog.data.nostrfy"
color="primary"
label="Zaps"
size="xs"
dense
>
<q-tooltip>Use zaps for payments</q-tooltip>
</q-checkbox>
v-if="formDialog.data.switches.length < 2"
v-model="formDialog.data.nostrfy"
color="primary"
label="Zaps"
size="xs"
dense
>
<q-tooltip>Use zaps for payments</q-tooltip>
</q-checkbox>
</div>
</div>
<div class="row">
Expand All @@ -311,7 +311,8 @@ <h5 v-html="formDialog.data.device" v-if="formDialog.data.id"></h5>
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)"
>
</q-input>
</div>
</div>
Expand Down

0 comments on commit b985691

Please sign in to comment.