From 3d42960d20094f3c82c4225e42d3be64b8204433 Mon Sep 17 00:00:00 2001 From: Shroominic Date: Mon, 11 Aug 2025 14:42:22 -0300 Subject: [PATCH] fmt --- routstr/balance.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/routstr/balance.py b/routstr/balance.py index 27709269..af8620e5 100644 --- a/routstr/balance.py +++ b/routstr/balance.py @@ -77,28 +77,39 @@ async def refund_wallet_endpoint( # Perform refund operation first, before modifying balance try: if key.refund_address: - await send_to_lnurl(remaining_balance_msats, CurrencyUnit.msat, key.refund_address) + await send_to_lnurl( + remaining_balance_msats, CurrencyUnit.msat, key.refund_address + ) result = {"recipient": key.refund_address, "msats": remaining_balance_msats} else: # Convert msats to sats for cashu wallet remaining_balance_sats = remaining_balance_msats // 1000 if remaining_balance_sats == 0: raise HTTPException( - status_code=400, detail="Balance too small to refund (less than 1 sat)" + status_code=400, + detail="Balance too small to refund (less than 1 sat)", ) # TODO: choose currency and mint based on what user has configured token = await send_token(remaining_balance_sats, "sat") - result = {"msats": remaining_balance_msats, "recipient": None, "token": token} + result = { + "msats": remaining_balance_msats, + "recipient": None, + "token": token, + } except HTTPException: # Re-raise HTTP exceptions (like 400 for balance too small) raise except Exception as e: # If refund fails, don't modify the database error_msg = str(e) - if ("mint" in error_msg.lower() or "connection" in error_msg.lower() or - isinstance(e, Exception) and "ConnectError" in str(type(e))): + if ( + "mint" in error_msg.lower() + or "connection" in error_msg.lower() + or isinstance(e, Exception) + and "ConnectError" in str(type(e)) + ): raise HTTPException(status_code=503, detail="Mint service unavailable") else: raise HTTPException(status_code=500, detail="Refund failed")