copilot payments not triggering animations

This commit is contained in:
benarc
2021-10-18 10:28:31 +01:00
parent 762f0ba404
commit 15cd84652e
2 changed files with 31 additions and 26 deletions

View File

@@ -33,21 +33,22 @@ async def lnurl_response(req: Request, cp_id: str = Query(None)):
status_code=HTTPStatus.NOT_FOUND, detail="Copilot not found" status_code=HTTPStatus.NOT_FOUND, detail="Copilot not found"
) )
resp = LnurlPayResponse( payResponse = {
callback=req.url_for("copilot.lnurl_callback", cp_id=cp_id, _external=True), "tag": "payRequest",
min_sendable=10000, "callback": req.url_for("copilot.lnurl_callback", cp_id=cp_id),
max_sendable=50000000, "metadata": LnurlPayMetadata(json.dumps([["text/plain", str(cp.lnurl_title)]])),
metadata=LnurlPayMetadata(json.dumps([["text/plain", str(cp.lnurl_title)]])), "maxSendable": 50000000,
) "minSendable": 10000,
}
params = resp.dict()
if cp.show_message: if cp.show_message:
params["commentAllowed"] = 300 payResponse["commentAllowed"] = 300
return json.dumps(payResponse)
return params
@copilot_ext.get("/lnurl/cb/{cp_id}", response_class=HTMLResponse) @copilot_ext.get(
"/lnurl/cb/{cp_id}", response_class=HTMLResponse, name="copilot.lnurl_callback"
)
async def lnurl_callback( async def lnurl_callback(
cp_id: str = Query(None), amount: str = Query(None), comment: str = Query(None) cp_id: str = Query(None), amount: str = Query(None), comment: str = Query(None)
): ):
@@ -56,26 +57,28 @@ async def lnurl_callback(
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="Copilot not found" status_code=HTTPStatus.NOT_FOUND, detail="Copilot not found"
) )
print(cp)
amount_received = int(amount) amount_received = int(amount)
if amount_received < 10000: if amount_received < 10000:
return LnurlErrorResponse( raise HTTPException(
reason=f"Amount {round(amount_received / 1000)} is smaller than minimum 10 sats." status_code=HTTPStatus.FORBIDDEN,
).dict() detail="Amount {round(amount_received / 1000)} is smaller than minimum 10 sats.",
)
elif amount_received / 1000 > 10000000: elif amount_received / 1000 > 10000000:
return LnurlErrorResponse( raise HTTPException(
reason=f"Amount {round(amount_received / 1000)} is greater than maximum 50000." status_code=HTTPStatus.FORBIDDEN,
).dict() detail="Amount {round(amount_received / 1000)} is greater than maximum 50000.",
)
comment = "" comment = ""
if comment: if comment:
if len(comment or "") > 300: if len(comment or "") > 300:
return LnurlErrorResponse( raise HTTPException(
reason=f"Got a comment with {len(comment)} characters, but can only accept 300" status_code=HTTPStatus.FORBIDDEN,
).dict() detail="Got a comment with {len(comment)} characters, but can only accept 300",
)
if len(comment) < 1: if len(comment) < 1:
comment = "none" comment = "none"
payment_hash, payment_request = await create_invoice( payment_hash, payment_request = await create_invoice(
wallet_id=cp.wallet, wallet_id=cp.wallet,
amount=int(amount_received / 1000), amount=int(amount_received / 1000),
@@ -87,7 +90,8 @@ async def lnurl_callback(
).digest(), ).digest(),
extra={"tag": "copilot", "copilot": cp.id, "comment": comment}, extra={"tag": "copilot", "copilot": cp.id, "comment": comment},
) )
resp = LnurlPayActionResponse( payResponse = {
pr=payment_request, success_action=None, disposable=False, routes=[] "pr": payment_request,
) "routes": [],
return resp.dict() }
return json.dumps(payResponse)

View File

@@ -26,6 +26,7 @@ async def wait_for_paid_invoices():
async def on_invoice_paid(payment: Payment) -> None: async def on_invoice_paid(payment: Payment) -> None:
webhook = None webhook = None
data = None data = None
print("cunt")
if "copilot" != payment.extra.get("tag"): if "copilot" != payment.extra.get("tag"):
# not an copilot invoice # not an copilot invoice
return return