From cbeb888761fd67c54b89380a0c4ce987caff7fe0 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sat, 17 Apr 2021 23:44:26 -0300 Subject: [PATCH] fix lnurlwallet flow. --- lnbits/core/services.py | 31 +++++++++++++++++++++---------- lnbits/core/views/generic.py | 4 ++-- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/lnbits/core/services.py b/lnbits/core/services.py index 8ccf1a425..97435f72f 100644 --- a/lnbits/core/services.py +++ b/lnbits/core/services.py @@ -1,3 +1,4 @@ +import trio # type: ignore import json import httpx from io import BytesIO @@ -182,6 +183,7 @@ async def redeem_lnurl_withdraw( lnurl_request: str, memo: Optional[str] = None, extra: Optional[Dict] = None, + wait_seconds: int = 0, conn: Optional[Connection] = None, ) -> None: res = {} @@ -199,19 +201,28 @@ async def redeem_lnurl_withdraw( conn=conn, ) + if wait_seconds: + await trio.sleep(wait_seconds) + + params = { + "k1": res["k1"], + "pr": payment_request, + } + + try: + params["balanceNotify"] = url_for( + "core.lnurl_balance_notify", + service=urlparse(lnurl_request).netloc, + wal=wallet_id, + _external=True, + ) + except Exception: + pass + async with httpx.AsyncClient() as client: await client.get( res["callback"], - params={ - "k1": res["k1"], - "pr": payment_request, - "balanceNotify": url_for( - "core.lnurl_balance_notify", - service=urlparse(lnurl_request).netloc, - wal=wallet_id, - _external=True, - ), - }, + params=params, ) diff --git a/lnbits/core/views/generic.py b/lnbits/core/views/generic.py index 384511897..e17d71b31 100644 --- a/lnbits/core/views/generic.py +++ b/lnbits/core/views/generic.py @@ -1,4 +1,3 @@ -import trio # type: ignore from os import path from http import HTTPStatus from quart import ( @@ -203,8 +202,9 @@ async def lnurlwallet(): wallet.id, request.args.get("lightning"), "LNbits initial funding: voucher redeem.", + {"tag": "lnurlwallet"}, + 5, # wait 5 seconds before sending the invoice to the service ) - await trio.sleep(3) return redirect(url_for("core.wallet", usr=user.id, wal=wallet.id))