websocket internal payment notifications (#1831)

* add send_payment_notification service
payment notifications are sent from multiple places with inconsistent and incomplete data
* adopt new send_payment_notification service
* add tests
This commit is contained in:
jackstar12
2023-07-26 12:08:22 +02:00
committed by GitHub
parent cf0a87582c
commit dda6c1b3c1
4 changed files with 65 additions and 28 deletions
+2 -11
View File
@@ -1,5 +1,4 @@
import asyncio
import json
from typing import Dict, Optional
import httpx
@@ -11,7 +10,7 @@ from lnbits.tasks import SseListenersDict, register_invoice_listener
from . import db
from .crud import get_balance_notify, get_wallet
from .models import Payment
from .services import get_balance_delta, switch_to_voidwallet, websocketUpdater
from .services import get_balance_delta, send_payment_notification, switch_to_voidwallet
api_invoice_listeners: Dict[str, asyncio.Queue] = SseListenersDict(
"api_invoice_listeners"
@@ -123,15 +122,7 @@ async def wait_for_paid_invoices(invoice_paid_queue: asyncio.Queue):
await dispatch_api_invoice_listeners(payment)
wallet = await get_wallet(payment.wallet_id)
if wallet:
await websocketUpdater(
payment.wallet_id,
json.dumps(
{
"wallet_balance": wallet.balance or None,
"payment": payment.dict(),
}
),
)
await send_payment_notification(wallet, payment)
# dispatch webhook
if payment.webhook and not payment.webhook_status:
await dispatch_webhook(payment)