From 67cc76268dabee0d4374371a1c1e768183490878 Mon Sep 17 00:00:00 2001 From: Tiago Vasconcelos Date: Fri, 11 Oct 2024 15:04:57 +0100 Subject: [PATCH] fix: messages on tasks --- models.py | 2 +- tasks.py | 17 +++++++++++++---- views_api.py | 1 + 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/models.py b/models.py index 09363f8..21c9fda 100644 --- a/models.py +++ b/models.py @@ -22,7 +22,7 @@ def private_key(self) -> PrivateKey: @property def public_key(self) -> str: - return P + return self.private_key.public_key.hex() diff --git a/tasks.py b/tasks.py index 5d48245..227ba49 100644 --- a/tasks.py +++ b/tasks.py @@ -7,7 +7,12 @@ from lnbits.tasks import register_invoice_listener from lnbits.utils.exchange_rates import fiat_amount_as_satoshis -from .crud import get_appointment, get_schedule, set_appointment_paid +from .crud import ( + get_appointment, + get_or_create_calendar_settings, + get_schedule, + set_appointment_paid, +) from .helpers import normalize_public_key from .services import nostr_send_msg @@ -44,7 +49,12 @@ async def on_invoice_paid(payment: Payment) -> None: if abs(payment.amount) >= lower_bound: # allow 1% error await set_appointment_paid(payment.payment_hash) - if schedule.public_key: + settings = await get_or_create_calendar_settings() + if not settings or not settings.nostr_private_key: + return + + if schedule.public_key and appointment.nostr_pubkey: + # notify the user that the appointment has been paid pubkey = schedule.pubkey_hex assert pubkey @@ -59,8 +69,7 @@ async def on_invoice_paid(payment: Payment) -> None: """ await nostr_send_msg(pubkey, msg) - if appointment.nostr_pubkey: - #notify client that the appointment has been paid + # notify client that the appointment has been paid pubkey = normalize_public_key(appointment.nostr_pubkey) msg = f""" [DO NOT REPLY TO THIS MESSAGE] diff --git a/views_api.py b/views_api.py index e63edd1..c7f49f8 100644 --- a/views_api.py +++ b/views_api.py @@ -157,6 +157,7 @@ async def api_appointment_create(data: CreateAppointment): memo=f"{schedule.name}", extra={"tag": "lncalendar", "name": data.name, "email": data.email}, ) + await create_appointment( schedule_id=data.schedule, payment_hash=payment_hash, data=data )