From 3824a108aa7563057270eee8e46a3ff57b981fa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Mon, 2 Jan 2023 11:25:01 +0100 Subject: [PATCH] fix scrub for mypy --- lnbits/extensions/scrub/tasks.py | 6 +++--- lnbits/extensions/scrub/views.py | 3 +-- lnbits/extensions/scrub/views_api.py | 11 ++++------- pyproject.toml | 1 - 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/lnbits/extensions/scrub/tasks.py b/lnbits/extensions/scrub/tasks.py index 852f3860..096cbef9 100644 --- a/lnbits/extensions/scrub/tasks.py +++ b/lnbits/extensions/scrub/tasks.py @@ -25,9 +25,9 @@ async def wait_for_paid_invoices(): await on_invoice_paid(payment) -async def on_invoice_paid(payment: Payment) -> None: +async def on_invoice_paid(payment: Payment): # (avoid loops) - if payment.extra.get("tag") == "scrubed": + if payment.extra and payment.extra.get("tag") == "scrubed": # already scrubbed return @@ -53,7 +53,7 @@ async def on_invoice_paid(payment: Payment) -> None: timeout=40, ) if r.is_error: - raise httpx.ConnectError + raise httpx.ConnectError("issue with scrub callback") except (httpx.ConnectError, httpx.RequestError): raise HTTPException( status_code=HTTPStatus.BAD_REQUEST, diff --git a/lnbits/extensions/scrub/views.py b/lnbits/extensions/scrub/views.py index 73c7ffd9..509417e0 100644 --- a/lnbits/extensions/scrub/views.py +++ b/lnbits/extensions/scrub/views.py @@ -1,5 +1,4 @@ -from fastapi import Request -from fastapi.params import Depends +from fastapi import Request, Depends from fastapi.templating import Jinja2Templates from starlette.responses import HTMLResponse diff --git a/lnbits/extensions/scrub/views_api.py b/lnbits/extensions/scrub/views_api.py index cc55c15d..289a80d2 100644 --- a/lnbits/extensions/scrub/views_api.py +++ b/lnbits/extensions/scrub/views_api.py @@ -1,9 +1,6 @@ from http import HTTPStatus -from fastapi import Request -from fastapi.param_functions import Query -from fastapi.params import Depends -from lnurl.exceptions import InvalidUrl as LnurlInvalidUrl # type: ignore +from fastapi import Query, Depends from starlette.exceptions import HTTPException from lnbits.core.crud import get_user @@ -23,14 +20,14 @@ from .models import CreateScrubLink @scrub_ext.get("/api/v1/links", status_code=HTTPStatus.OK) async def api_links( - req: Request, wallet: WalletTypeInfo = Depends(get_key_type), all_wallets: bool = Query(False), ): wallet_ids = [wallet.wallet.id] if all_wallets: - wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids + user = await get_user(wallet.wallet.user) + wallet_ids = user.wallet_ids if user else [] try: return [link.dict() for link in await get_scrub_links(wallet_ids)] @@ -44,7 +41,7 @@ async def api_links( @scrub_ext.get("/api/v1/links/{link_id}", status_code=HTTPStatus.OK) async def api_link_retrieve( - r: Request, link_id, wallet: WalletTypeInfo = Depends(get_key_type) + link_id, wallet: WalletTypeInfo = Depends(get_key_type) ): link = await get_scrub_link(link_id) diff --git a/pyproject.toml b/pyproject.toml index 96a066e5..f207ea84 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -106,7 +106,6 @@ exclude = """(?x)( | ^lnbits/extensions/offlineshop. | ^lnbits/extensions/paywall. | ^lnbits/extensions/satspay. - | ^lnbits/extensions/scrub. | ^lnbits/extensions/splitpayments. | ^lnbits/extensions/streamalerts. | ^lnbits/extensions/tipjar.