From 4f457813196c54e65d944f4e5b3cff9923444fc4 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Tue, 6 Feb 2024 05:26:50 -0300 Subject: [PATCH] alby: fix balance reporting and error handling + opennode: fix error handling (#2221) * opennode: fix error handling * alby: fix balance reporting and error handling --- lnbits/wallets/alby.py | 9 ++++++--- lnbits/wallets/opennode.py | 6 ++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lnbits/wallets/alby.py b/lnbits/wallets/alby.py index 593ad6740..7b7507739 100644 --- a/lnbits/wallets/alby.py +++ b/lnbits/wallets/alby.py @@ -44,11 +44,14 @@ class AlbyWallet(Wallet): except (httpx.ConnectError, httpx.RequestError): return StatusResponse(f"Unable to connect to '{self.endpoint}'", 0) - data = r.json()["balance"] if r.is_error: - return StatusResponse(data["error"], 0) + error_message = r.json()["message"] + return StatusResponse(error_message, 0) - return StatusResponse(None, data) + data = r.json() + assert data["unit"] == "sat" + # multiply balance by 1000 to get msats balance + return StatusResponse(None, data["balance"] * 1000) async def create_invoice( self, diff --git a/lnbits/wallets/opennode.py b/lnbits/wallets/opennode.py index ac6b510fc..7f20447b0 100644 --- a/lnbits/wallets/opennode.py +++ b/lnbits/wallets/opennode.py @@ -56,10 +56,12 @@ class OpenNodeWallet(Wallet): except (httpx.ConnectError, httpx.RequestError): return StatusResponse(f"Unable to connect to '{self.endpoint}'", 0) - data = r.json()["data"] if r.is_error: - return StatusResponse(data["message"], 0) + error_message = r.json()["message"] + return StatusResponse(error_message, 0) + data = r.json()["data"] + # multiply balance by 1000 to get msats balance return StatusResponse(None, data["balance"]["BTC"] * 1000) async def create_invoice(