mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-03-10 17:26:15 +01:00
fix tpos mypy issue
This commit is contained in:
parent
268d101189
commit
908369efff
4 changed files with 23 additions and 16 deletions
|
@ -20,10 +20,9 @@ async def wait_for_paid_invoices():
|
||||||
|
|
||||||
|
|
||||||
async def on_invoice_paid(payment: Payment) -> None:
|
async def on_invoice_paid(payment: Payment) -> None:
|
||||||
if payment.extra.get("tag") != "tpos":
|
if not payment.extra or payment.extra.get("tag") != "tpos":
|
||||||
return
|
return
|
||||||
|
|
||||||
tpos = await get_tpos(payment.extra.get("tposId"))
|
|
||||||
tipAmount = payment.extra.get("tipAmount")
|
tipAmount = payment.extra.get("tipAmount")
|
||||||
|
|
||||||
strippedPayment = {
|
strippedPayment = {
|
||||||
|
@ -34,14 +33,23 @@ async def on_invoice_paid(payment: Payment) -> None:
|
||||||
"bolt11": payment.bolt11,
|
"bolt11": payment.bolt11,
|
||||||
}
|
}
|
||||||
|
|
||||||
await websocketUpdater(payment.extra.get("tposId"), str(strippedPayment))
|
tpos_id = payment.extra.get("tposId")
|
||||||
|
assert tpos_id
|
||||||
|
|
||||||
if tipAmount is None:
|
tpos = await get_tpos(tpos_id)
|
||||||
|
assert tpos
|
||||||
|
|
||||||
|
await websocketUpdater(tpos_id, str(strippedPayment))
|
||||||
|
|
||||||
|
if not tipAmount:
|
||||||
# no tip amount
|
# no tip amount
|
||||||
return
|
return
|
||||||
|
|
||||||
|
wallet_id = tpos.tip_wallet
|
||||||
|
assert wallet_id
|
||||||
|
|
||||||
payment_hash, payment_request = await create_invoice(
|
payment_hash, payment_request = await create_invoice(
|
||||||
wallet_id=tpos.tip_wallet,
|
wallet_id=wallet_id,
|
||||||
amount=int(tipAmount), # sats
|
amount=int(tipAmount), # sats
|
||||||
internal=True,
|
internal=True,
|
||||||
memo=f"tpos tip",
|
memo=f"tpos tip",
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
|
|
||||||
from fastapi import Request
|
from fastapi import Depends, Request
|
||||||
from fastapi.params import Depends
|
|
||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
from starlette.exceptions import HTTPException
|
from starlette.exceptions import HTTPException
|
||||||
from starlette.responses import HTMLResponse
|
from starlette.responses import HTMLResponse
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
from fastapi import Query
|
from fastapi import Depends, Query
|
||||||
from fastapi.params import Depends
|
|
||||||
from lnurl import decode as decode_lnurl
|
from lnurl import decode as decode_lnurl
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from starlette.exceptions import HTTPException
|
from starlette.exceptions import HTTPException
|
||||||
|
@ -25,7 +24,8 @@ async def api_tposs(
|
||||||
):
|
):
|
||||||
wallet_ids = [wallet.wallet.id]
|
wallet_ids = [wallet.wallet.id]
|
||||||
if all_wallets:
|
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 []
|
||||||
|
|
||||||
return [tpos.dict() for tpos in await get_tposs(wallet_ids)]
|
return [tpos.dict() for tpos in await get_tposs(wallet_ids)]
|
||||||
|
|
||||||
|
@ -58,8 +58,9 @@ async def api_tpos_delete(
|
||||||
|
|
||||||
@tpos_ext.post("/api/v1/tposs/{tpos_id}/invoices", status_code=HTTPStatus.CREATED)
|
@tpos_ext.post("/api/v1/tposs/{tpos_id}/invoices", status_code=HTTPStatus.CREATED)
|
||||||
async def api_tpos_create_invoice(
|
async def api_tpos_create_invoice(
|
||||||
amount: int = Query(..., ge=1), tipAmount: int = None, tpos_id: str = None
|
tpos_id: str, amount: int = Query(..., ge=1), tipAmount: int = 0
|
||||||
):
|
) -> dict:
|
||||||
|
|
||||||
tpos = await get_tpos(tpos_id)
|
tpos = await get_tpos(tpos_id)
|
||||||
|
|
||||||
if not tpos:
|
if not tpos:
|
||||||
|
@ -67,7 +68,7 @@ async def api_tpos_create_invoice(
|
||||||
status_code=HTTPStatus.NOT_FOUND, detail="TPoS does not exist."
|
status_code=HTTPStatus.NOT_FOUND, detail="TPoS does not exist."
|
||||||
)
|
)
|
||||||
|
|
||||||
if tipAmount:
|
if tipAmount > 0:
|
||||||
amount += tipAmount
|
amount += tipAmount
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -84,7 +85,7 @@ async def api_tpos_create_invoice(
|
||||||
|
|
||||||
|
|
||||||
@tpos_ext.get("/api/v1/tposs/{tpos_id}/invoices")
|
@tpos_ext.get("/api/v1/tposs/{tpos_id}/invoices")
|
||||||
async def api_tpos_get_latest_invoices(tpos_id: str = None):
|
async def api_tpos_get_latest_invoices(tpos_id: str):
|
||||||
try:
|
try:
|
||||||
payments = [
|
payments = [
|
||||||
Payment.from_row(row)
|
Payment.from_row(row)
|
||||||
|
@ -111,7 +112,7 @@ async def api_tpos_get_latest_invoices(tpos_id: str = None):
|
||||||
"/api/v1/tposs/{tpos_id}/invoices/{payment_request}/pay", status_code=HTTPStatus.OK
|
"/api/v1/tposs/{tpos_id}/invoices/{payment_request}/pay", status_code=HTTPStatus.OK
|
||||||
)
|
)
|
||||||
async def api_tpos_pay_invoice(
|
async def api_tpos_pay_invoice(
|
||||||
lnurl_data: PayLnurlWData, payment_request: str = None, tpos_id: str = None
|
lnurl_data: PayLnurlWData, payment_request: str, tpos_id: str
|
||||||
):
|
):
|
||||||
tpos = await get_tpos(tpos_id)
|
tpos = await get_tpos(tpos_id)
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,6 @@ exclude = """(?x)(
|
||||||
| ^lnbits/extensions/offlineshop.
|
| ^lnbits/extensions/offlineshop.
|
||||||
| ^lnbits/extensions/satspay.
|
| ^lnbits/extensions/satspay.
|
||||||
| ^lnbits/extensions/streamalerts.
|
| ^lnbits/extensions/streamalerts.
|
||||||
| ^lnbits/extensions/tpos.
|
|
||||||
| ^lnbits/extensions/watchonly.
|
| ^lnbits/extensions/watchonly.
|
||||||
| ^lnbits/extensions/withdraw.
|
| ^lnbits/extensions/withdraw.
|
||||||
| ^lnbits/wallets/lnd_grpc_files.
|
| ^lnbits/wallets/lnd_grpc_files.
|
||||||
|
|
Loading…
Add table
Reference in a new issue