diff --git a/crud.py b/crud.py index ac7462f..2edf006 100644 --- a/crud.py +++ b/crud.py @@ -105,15 +105,14 @@ async def get_lnurldevice(lnurldevice_id: str, req: Request) -> Optional[Lnurlde if device.switches: url = req.url_for("lnurldevice.lnurl_v2_params", device_id=device.id) for _switch in device.switches: - if not _switch.lnurl: - _switch.lnurl = lnurl_encode( - str(url) - + f"?pin={_switch.pin}" - + f"&amount={_switch.amount}" - + f"&duration={_switch.duration}" - + f"&variable={_switch.variable}" - + f"&comment={_switch.comment}" - ) + _switch.lnurl = lnurl_encode( + str(url) + + f"?pin={_switch.pin}" + + f"&amount={_switch.amount}" + + f"&duration={_switch.duration}" + + f"&variable={_switch.variable}" + + f"&comment={_switch.comment}" + ) return device @@ -136,15 +135,14 @@ async def get_lnurldevices(wallet_ids: List[str], req: Request) -> List[Lnurldev if device.switches: url = req.url_for("lnurldevice.lnurl_v2_params", device_id=device.id) for _switch in device.switches: - if not _switch.lnurl: - _switch.lnurl = lnurl_encode( - str(url) - + f"?pin={_switch.pin}" - + f"&amount={_switch.amount}" - + f"&duration={_switch.duration}" - + f"&variable={_switch.variable}" - + f"&comment={_switch.comment}" - ) + _switch.lnurl = lnurl_encode( + str(url) + + f"?pin={_switch.pin}" + + f"&amount={_switch.amount}" + + f"&duration={_switch.duration}" + + f"&variable={_switch.variable}" + + f"&comment={_switch.comment}" + ) return devices diff --git a/lnurl.py b/lnurl.py index 068c8db..7681e52 100644 --- a/lnurl.py +++ b/lnurl.py @@ -159,7 +159,6 @@ async def lnurl_params( resp["commentAllowed"] = 1500 if variable == True: resp["maxSendable"] = price_msat * 360 - logger.debug(resp) return resp if len(p) % 4 > 0: @@ -285,6 +284,9 @@ async def lnurl_callback( return {"status": "ERROR", "reason": "Payment failed, use a different wallet."} return {"status": "OK"} if device.device == "switch": + if not amount: + return {"status": "ERROR", "reason": "No amount"} + payment_hash, payment_request = await create_invoice( wallet_id=device.wallet, amount=int(amount / 1000), @@ -293,27 +295,24 @@ async def lnurl_callback( extra={ "tag": "Switch", "pin": str(lnurldevicepayment.pin), - "amount": amount, + "amount": str(int(amount)), "comment": comment, "variable": variable, "id": paymentid, }, ) - logger.debug(bolt11.decode(payment_request)) lnurldevicepayment = await update_lnurldevicepayment( lnurldevicepayment_id=paymentid, payhash=payment_hash ) - resp = JSONResponse( - { + resp = { "pr": payment_request, "successAction": { - "tag": "text", - "description": f"{int(amount / 1000)}sats sent" + "tag": "message", + "message": f"{int(amount / 1000)}sats sent" }, "routes": [], } - ) return resp diff --git a/tasks.py b/tasks.py index 8ad3eb9..ecd6348 100644 --- a/tasks.py +++ b/tasks.py @@ -31,9 +31,10 @@ async def on_invoice_paid(payment: Payment) -> None: lnurldevicepayment_id=payment.extra["id"], payhash="used" ) comment = payment.extra["comment"] + variable = payment.extra["variable"] payload = lnurldevicepayment.payload - if payload: - payload = int(payload) * int(lnurldevicepayment.sats) + if variable: + payload = int((int(payload) / int(lnurldevicepayment.sats)) * int(payment.extra["amount"])) if comment: return await websocket_updater( @@ -42,5 +43,5 @@ async def on_invoice_paid(payment: Payment) -> None: ) return await websocket_updater( lnurldevicepayment.deviceid, - f"{lnurldevicepayment.pin}-{lnurldevicepayment.payload}", + f"{lnurldevicepayment.pin}-{payload}", )