Merge pull request #1282 from lnbits/fix/mypy-streamalerts

fix streamalert mypy issues
This commit is contained in:
Arc 2023-01-05 07:54:51 +00:00 committed by GitHub
commit 301a784e95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 14 deletions

View File

@ -25,15 +25,20 @@ async def get_charge_details(service_id):
These might be different depending for services implemented in the future. These might be different depending for services implemented in the future.
""" """
details = {"time": 1440}
service = await get_service(service_id) service = await get_service(service_id)
assert service
wallet_id = service.wallet wallet_id = service.wallet
wallet = await get_wallet(wallet_id) wallet = await get_wallet(wallet_id)
assert wallet
user = wallet.user user = wallet.user
details["user"] = user return {
details["lnbitswallet"] = wallet_id "time": 1440,
details["onchainwallet"] = service.onchain "user": user,
return details "lnbitswallet": wallet_id,
"onchainwallet": service.onchain,
}
async def create_donation( async def create_donation(
@ -71,7 +76,7 @@ async def create_donation(
return donation return donation
async def post_donation(donation_id: str) -> tuple: async def post_donation(donation_id: str) -> dict:
"""Post donations to their respective third party APIs """Post donations to their respective third party APIs
If the donation has already been posted, it will not be posted again. If the donation has already been posted, it will not be posted again.
@ -97,7 +102,6 @@ async def post_donation(donation_id: str) -> tuple:
} }
async with httpx.AsyncClient() as client: async with httpx.AsyncClient() as client:
response = await client.post(url, data=data) response = await client.post(url, data=data)
status = [s for s in list(HTTPStatus) if s == response.status_code][0]
elif service.servicename == "StreamElements": elif service.servicename == "StreamElements":
return {"message": "StreamElements not yet supported!"} return {"message": "StreamElements not yet supported!"}
else: else:

View File

@ -1,8 +1,8 @@
from sqlite3 import Row from sqlite3 import Row
from typing import Optional from typing import Optional
from fastapi.params import Query from fastapi import Query
from pydantic.main import BaseModel from pydantic import BaseModel
class CreateService(BaseModel): class CreateService(BaseModel):

View File

@ -1,6 +1,6 @@
from http import HTTPStatus from http import HTTPStatus
from fastapi.param_functions import Depends from fastapi import Depends
from fastapi.templating import Jinja2Templates from fastapi.templating import Jinja2Templates
from starlette.exceptions import HTTPException from starlette.exceptions import HTTPException
from starlette.requests import Request from starlette.requests import Request

View File

@ -1,6 +1,6 @@
from http import HTTPStatus from http import HTTPStatus
from fastapi.params import Depends, Query from fastapi import Depends, Query
from starlette.exceptions import HTTPException from starlette.exceptions import HTTPException
from starlette.requests import Request from starlette.requests import Request
from starlette.responses import RedirectResponse from starlette.responses import RedirectResponse
@ -84,6 +84,8 @@ async def api_authenticate_service(
""" """
service = await get_service(service_id) service = await get_service(service_id)
assert service
if service.state != state: if service.state != state:
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.BAD_REQUEST, detail="State doesn't match!" status_code=HTTPStatus.BAD_REQUEST, detail="State doesn't match!"
@ -113,6 +115,7 @@ async def api_create_donation(data: CreateDonation, request: Request):
webhook_base = request.url.scheme + "://" + request.headers["Host"] webhook_base = request.url.scheme + "://" + request.headers["Host"]
service_id = data.service service_id = data.service
service = await get_service(service_id) service = await get_service(service_id)
assert service
charge_details = await get_charge_details(service.id) charge_details = await get_charge_details(service.id)
name = data.name if data.name else "Anonymous" name = data.name if data.name else "Anonymous"
@ -157,7 +160,8 @@ async def api_post_donation(request: Request, data: ValidateDonation):
@streamalerts_ext.get("/api/v1/services") @streamalerts_ext.get("/api/v1/services")
async def api_get_services(g: WalletTypeInfo = Depends(get_key_type)): async def api_get_services(g: WalletTypeInfo = Depends(get_key_type)):
"""Return list of all services assigned to wallet with given invoice key""" """Return list of all services assigned to wallet with given invoice key"""
wallet_ids = (await get_user(g.wallet.user)).wallet_ids user = await get_user(g.wallet.user)
wallet_ids = user.wallet_ids if user else []
services = [] services = []
for wallet_id in wallet_ids: for wallet_id in wallet_ids:
new_services = await get_services(wallet_id) new_services = await get_services(wallet_id)
@ -170,7 +174,8 @@ async def api_get_donations(g: WalletTypeInfo = Depends(get_key_type)):
"""Return list of all donations assigned to wallet with given invoice """Return list of all donations assigned to wallet with given invoice
key key
""" """
wallet_ids = (await get_user(g.wallet.user)).wallet_ids user = await get_user(g.wallet.user)
wallet_ids = user.wallet_ids if user else []
donations = [] donations = []
for wallet_id in wallet_ids: for wallet_id in wallet_ids:
new_donations = await get_donations(wallet_id) new_donations = await get_donations(wallet_id)

View File

@ -96,7 +96,6 @@ exclude = """(?x)(
| ^lnbits/extensions/lnaddress. | ^lnbits/extensions/lnaddress.
| ^lnbits/extensions/lnurldevice. | ^lnbits/extensions/lnurldevice.
| ^lnbits/extensions/satspay. | ^lnbits/extensions/satspay.
| ^lnbits/extensions/streamalerts.
| ^lnbits/extensions/watchonly. | ^lnbits/extensions/watchonly.
| ^lnbits/wallets/lnd_grpc_files. | ^lnbits/wallets/lnd_grpc_files.
)""" )"""