From bcdc065cc055b2d88e8297e102541c6af6b29a8a Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Tue, 13 Oct 2020 14:46:23 -0300 Subject: [PATCH] mypy fixes. --- lnbits/core/services.py | 9 +++------ lnbits/core/templates/core/wallet.html | 4 ++-- lnbits/core/views/api.py | 10 +++++----- lnbits/wallets/base.py | 2 +- lnbits/wallets/lnpay.py | 2 +- lnbits/wallets/opennode.py | 2 +- 6 files changed, 13 insertions(+), 16 deletions(-) diff --git a/lnbits/core/services.py b/lnbits/core/services.py index d4d4d8c0..a0b329a6 100644 --- a/lnbits/core/services.py +++ b/lnbits/core/services.py @@ -1,7 +1,7 @@ import httpx from typing import Optional, Tuple, Dict from quart import g -from lnurl import LnurlWithdrawResponse +from lnurl import LnurlWithdrawResponse # type: ignore try: from typing import TypedDict # type: ignore @@ -116,7 +116,7 @@ def pay_invoice( else: # actually pay the external invoice payment: PaymentResponse = WALLET.pay_invoice(payment_request) - if payment.ok: + if payment.ok and payment.checking_id: create_payment( checking_id=payment.checking_id, fee=payment.fee_msat, @@ -132,13 +132,10 @@ def pay_invoice( async def redeem_lnurl_withdraw(wallet_id: str, res: LnurlWithdrawResponse, memo: Optional[str] = None) -> None: - if not memo: - memo = res.default_description - _, payment_request = create_invoice( wallet_id=wallet_id, amount=res.max_sats, - memo=memo, + memo=memo or res.default_description or "", extra={"tag": "lnurlwallet"}, ) diff --git a/lnbits/core/templates/core/wallet.html b/lnbits/core/templates/core/wallet.html index 4edf134d..a9169c3b 100644 --- a/lnbits/core/templates/core/wallet.html +++ b/lnbits/core/templates/core/wallet.html @@ -347,8 +347,8 @@ {% raw %}

- {{ parse.lnurlpay.domain }} is requesting - {{ parse.lnurlpay.maxSendable | msatoshiFormat }} sat + {{ parse.lnurlpay.domain }} is requesting {{ + parse.lnurlpay.maxSendable | msatoshiFormat }} sat

{{ parse.lnurlpay.domain }} is requesting
diff --git a/lnbits/core/views/api.py b/lnbits/core/views/api.py index 90526d74..fce82ae1 100644 --- a/lnbits/core/views/api.py +++ b/lnbits/core/views/api.py @@ -1,6 +1,6 @@ import trio # type: ignore import json -import lnurl +import lnurl # type: ignore import httpx import traceback from urllib.parse import urlparse, urlunparse, urlencode, parse_qs, ParseResult @@ -306,11 +306,11 @@ async def api_lnurlscan(code: str): params.update(fixed=data.min_withdrawable == data.max_withdrawable) # callback with k1 already in it - url: ParseResult = urlparse(data.callback) - qs: Dict = parse_qs(url.query) + parsed_callback: ParseResult = urlparse(data.callback) + qs: Dict = parse_qs(parsed_callback.query) qs["k1"] = data.k1 - url = url._replace(query=urlencode(qs, doseq=True)) - params.update(callback=urlunparse(url)) + parsed_callback = parsed_callback._replace(query=urlencode(qs, doseq=True)) + params.update(callback=urlunparse(parsed_callback)) if type(data) is lnurl.LnurlPayResponse: params.update(kind="pay") diff --git a/lnbits/wallets/base.py b/lnbits/wallets/base.py index 98f91378..d2486c73 100644 --- a/lnbits/wallets/base.py +++ b/lnbits/wallets/base.py @@ -32,7 +32,7 @@ class PaymentStatus(NamedTuple): class Wallet(ABC): @abstractmethod - def status() -> StatusResponse: + def status(self) -> StatusResponse: pass @abstractmethod diff --git a/lnbits/wallets/lnpay.py b/lnbits/wallets/lnpay.py index 65629f75..e1b6d446 100644 --- a/lnbits/wallets/lnpay.py +++ b/lnbits/wallets/lnpay.py @@ -23,7 +23,7 @@ class LNPayWallet(Wallet): try: r = httpx.get(url, headers=self.auth) except (httpx.ConnectError, httpx.RequestError): - return StatusResponse(f"Unable to connect to '{url}'") + return StatusResponse(f"Unable to connect to '{url}'", 0) if r.is_error: return StatusResponse(r.text[:250], 0) diff --git a/lnbits/wallets/opennode.py b/lnbits/wallets/opennode.py index 8b772e7e..4510e0d3 100644 --- a/lnbits/wallets/opennode.py +++ b/lnbits/wallets/opennode.py @@ -24,7 +24,7 @@ class OpenNodeWallet(Wallet): try: r = httpx.get(f"{self.endpoint}/v1/account/balance", headers=self.auth) except (httpx.ConnectError, httpx.RequestError): - return StatusResponse(f"Unable to connect to '{self.endpoint}'") + return StatusResponse(f"Unable to connect to '{self.endpoint}'", 0) data = r.json()["message"] if r.is_error: