mypy fixes.

This commit is contained in:
fiatjaf 2020-10-13 14:46:23 -03:00
parent cf0bd7ece8
commit bcdc065cc0
6 changed files with 13 additions and 16 deletions

View File

@ -1,7 +1,7 @@
import httpx import httpx
from typing import Optional, Tuple, Dict from typing import Optional, Tuple, Dict
from quart import g from quart import g
from lnurl import LnurlWithdrawResponse from lnurl import LnurlWithdrawResponse # type: ignore
try: try:
from typing import TypedDict # type: ignore from typing import TypedDict # type: ignore
@ -116,7 +116,7 @@ def pay_invoice(
else: else:
# actually pay the external invoice # actually pay the external invoice
payment: PaymentResponse = WALLET.pay_invoice(payment_request) payment: PaymentResponse = WALLET.pay_invoice(payment_request)
if payment.ok: if payment.ok and payment.checking_id:
create_payment( create_payment(
checking_id=payment.checking_id, checking_id=payment.checking_id,
fee=payment.fee_msat, 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: 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( _, payment_request = create_invoice(
wallet_id=wallet_id, wallet_id=wallet_id,
amount=res.max_sats, amount=res.max_sats,
memo=memo, memo=memo or res.default_description or "",
extra={"tag": "lnurlwallet"}, extra={"tag": "lnurlwallet"},
) )

View File

@ -347,8 +347,8 @@
{% raw %} {% raw %}
<q-form @submit="payLnurl" class="q-gutter-md"> <q-form @submit="payLnurl" class="q-gutter-md">
<p v-if="parse.lnurlpay.fixed" class="q-my-none text-h6"> <p v-if="parse.lnurlpay.fixed" class="q-my-none text-h6">
<b>{{ parse.lnurlpay.domain }}</b> is requesting <b>{{ parse.lnurlpay.domain }}</b> is requesting {{
{{ parse.lnurlpay.maxSendable | msatoshiFormat }} sat parse.lnurlpay.maxSendable | msatoshiFormat }} sat
</p> </p>
<p v-else class="q-my-none text-h6 text-center"> <p v-else class="q-my-none text-h6 text-center">
<b>{{ parse.lnurlpay.domain }}</b> is requesting <br /> <b>{{ parse.lnurlpay.domain }}</b> is requesting <br />

View File

@ -1,6 +1,6 @@
import trio # type: ignore import trio # type: ignore
import json import json
import lnurl import lnurl # type: ignore
import httpx import httpx
import traceback import traceback
from urllib.parse import urlparse, urlunparse, urlencode, parse_qs, ParseResult 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) params.update(fixed=data.min_withdrawable == data.max_withdrawable)
# callback with k1 already in it # callback with k1 already in it
url: ParseResult = urlparse(data.callback) parsed_callback: ParseResult = urlparse(data.callback)
qs: Dict = parse_qs(url.query) qs: Dict = parse_qs(parsed_callback.query)
qs["k1"] = data.k1 qs["k1"] = data.k1
url = url._replace(query=urlencode(qs, doseq=True)) parsed_callback = parsed_callback._replace(query=urlencode(qs, doseq=True))
params.update(callback=urlunparse(url)) params.update(callback=urlunparse(parsed_callback))
if type(data) is lnurl.LnurlPayResponse: if type(data) is lnurl.LnurlPayResponse:
params.update(kind="pay") params.update(kind="pay")

View File

@ -32,7 +32,7 @@ class PaymentStatus(NamedTuple):
class Wallet(ABC): class Wallet(ABC):
@abstractmethod @abstractmethod
def status() -> StatusResponse: def status(self) -> StatusResponse:
pass pass
@abstractmethod @abstractmethod

View File

@ -23,7 +23,7 @@ class LNPayWallet(Wallet):
try: try:
r = httpx.get(url, headers=self.auth) r = httpx.get(url, headers=self.auth)
except (httpx.ConnectError, httpx.RequestError): 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: if r.is_error:
return StatusResponse(r.text[:250], 0) return StatusResponse(r.text[:250], 0)

View File

@ -24,7 +24,7 @@ class OpenNodeWallet(Wallet):
try: try:
r = httpx.get(f"{self.endpoint}/v1/account/balance", headers=self.auth) r = httpx.get(f"{self.endpoint}/v1/account/balance", headers=self.auth)
except (httpx.ConnectError, httpx.RequestError): 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"] data = r.json()["message"]
if r.is_error: if r.is_error: