Adds websocket for incoming/outgoing payments with wallet balance (#1679)

* Websocket works for incoming/outgoing and includes wallet balance

* mypy

* mypy try

* Actual mypy (no try)

* format
This commit is contained in:
Arc 2023-05-22 12:38:26 +01:00 committed by GitHub
parent 7df131d3c7
commit c960f718f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

@ -247,6 +247,15 @@ async def pay_invoice(
new_checking_id=payment.checking_id,
conn=conn,
)
wallet = await get_wallet(wallet_id, conn=conn)
if wallet:
await websocketUpdater(
wallet_id,
{
"wallet_balance": wallet.balance or None,
"payment": payment._asdict(),
},
)
logger.debug(f"payment successful {payment.checking_id}")
elif payment.checking_id is None and payment.ok is False:
# payment failed

View File

@ -7,7 +7,7 @@ from loguru import logger
from lnbits.tasks import SseListenersDict, register_invoice_listener
from . import db
from .crud import get_balance_notify
from .crud import get_balance_notify, get_wallet
from .models import Payment
from .services import websocketUpdater
@ -38,8 +38,15 @@ async def wait_for_paid_invoices(invoice_paid_queue: asyncio.Queue):
logger.trace("received invoice paid event")
# send information to sse channel
await dispatch_api_invoice_listeners(payment)
await websocketUpdater(payment.wallet_id, payment.dict())
wallet = await get_wallet(payment.wallet_id)
if wallet:
await websocketUpdater(
payment.wallet_id,
{
"wallet_balance": wallet.balance or None,
"payment": payment._asdict(),
},
)
# dispatch webhook
if payment.webhook and not payment.webhook_status:
await dispatch_webhook(payment)