From aef24c75ff31e3a3cb05d7977d6d894b4cfb4ab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Fri, 30 Aug 2024 17:35:14 +0200 Subject: [PATCH 1/2] fix: create_charge is broken on latest satspay - improved error handling --- views_api.py | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/views_api.py b/views_api.py index 4cdcd05..36f7bee 100644 --- a/views_api.py +++ b/views_api.py @@ -58,21 +58,27 @@ async def api_create_tip(data: CreateTips): ) name = data.name or "Anonymous" - charge_id = await create_charge( - data={ - "amount": sats, - "webhook": tipjar.webhook or "", - "name": name, - "description": message, - "onchainwallet": tipjar.onchain or "", - "lnbitswallet": tipjar.wallet, - "completelink": "/tipjar/" + str(tipjar_id), - "completelinktext": "Thanks for the tip!", - "time": 1440, - "custom_css": "", - }, - api_key=wallet.inkey, - ) + try: + charge_id = await create_charge( + data={ + "amount": sats, + "webhook": tipjar.webhook or None, + "name": name, + "description": message, + "onchainwallet": tipjar.onchain or None, + "lnbitswallet": tipjar.wallet, + "completelink": f"/tipjar/{tipjar_id}", + "completelinktext": "Thanks for the tip!", + "time": 1440, + "custom_css": "", + }, + api_key=wallet.inkey, + ) + except Exception as exc: + msg = f"Failed to create charge: {exc!s}" + raise HTTPException( + status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=msg + ) from exc await create_tip( tip_id=charge_id, @@ -184,7 +190,13 @@ async def api_delete_tip( detail="Not authorized to delete this tip!", ) await delete_tip(tip_id) - await delete_charge(tip_id, key_type.wallet.inkey) + try: + await delete_charge(tip_id, key_type.wallet.inkey) + except Exception as exc: + raise HTTPException( + status_code=HTTPStatus.INTERNAL_SERVER_ERROR, + detail=f"Failed to delete charge: {exc!s}", + ) from exc return "", HTTPStatus.NO_CONTENT From d212471e83bffbbda17cd1dd7af9e58bb46413d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Fri, 30 Aug 2024 17:45:17 +0200 Subject: [PATCH 2/2] fix html --- templates/tipjar/display.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/tipjar/display.html b/templates/tipjar/display.html index ff735e1..1fb6c34 100644 --- a/templates/tipjar/display.html +++ b/templates/tipjar/display.html @@ -69,13 +69,13 @@
Tip {{ donatee }} some sats!
} }, methods: { - invoice: function () { + invoice() { axios .post('/tipjar/api/v1/tips', { tipjar: '{{ tipjar_id }}', - name: self.tipDialog.data.name, - sats: self.tipDialog.data.sats, - message: self.tipDialog.data.message + name: this.tipDialog.data.name, + sats: this.tipDialog.data.sats, + message: this.tipDialog.data.message }) .then(response => { this.redirect_url = response.data.redirect_url