mirror of
https://github.com/lnbits/lnbits.git
synced 2025-06-14 02:41:06 +02:00
refactor: use named params
This commit is contained in:
parent
ac14594677
commit
b0aafe18f7
@ -276,28 +276,26 @@ class StrikeWallet(Wallet):
|
|||||||
json=payload,
|
json=payload,
|
||||||
headers={**self.client.headers, "idempotency-key": idem},
|
headers={**self.client.headers, "idempotency-key": idem},
|
||||||
)
|
)
|
||||||
resp = r.json() # Parse JSON response.
|
resp = r.json()
|
||||||
invoice_id = resp.get("receiveRequestId") # Get the receive request ID.
|
invoice_id = resp.get("receiveRequestId")
|
||||||
bolt11 = resp.get("bolt11", {}).get("invoice") # Get the bolt11 invoice.
|
bolt11 = resp.get("bolt11", {}).get("invoice")
|
||||||
if (
|
if not invoice_id or not bolt11:
|
||||||
not invoice_id or not bolt11
|
|
||||||
): # Check if both invoice ID and bolt11 are present.
|
|
||||||
return InvoiceResponse(False, None, None, "Invalid invoice response")
|
|
||||||
|
|
||||||
self.pending_invoices.append(
|
|
||||||
invoice_id
|
|
||||||
) # Add invoice ID to pending invoices.
|
|
||||||
return InvoiceResponse(
|
return InvoiceResponse(
|
||||||
True, invoice_id, bolt11, None
|
ok=False, error_message="Invalid invoice response"
|
||||||
) # Return successful invoice response.
|
)
|
||||||
|
|
||||||
|
self.pending_invoices.append(invoice_id)
|
||||||
|
return InvoiceResponse(
|
||||||
|
ok=True, checking_id=invoice_id, payment_request=bolt11
|
||||||
|
)
|
||||||
except httpx.HTTPStatusError as e:
|
except httpx.HTTPStatusError as e:
|
||||||
msg = e.response.json().get(
|
msg = e.response.json().get(
|
||||||
"message", e.response.text
|
"message", e.response.text
|
||||||
) # Get error message from response.
|
) # Get error message from response.
|
||||||
return InvoiceResponse(False, None, None, f"Strike API error: {msg}")
|
return InvoiceResponse(ok=False, error_message=f"Strike API error: {msg}")
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.exception("Error in create_invoice()")
|
logger.exception("Error in create_invoice()")
|
||||||
return InvoiceResponse(False, None, None, "Connection error")
|
return InvoiceResponse(ok=False, error_message="Connection error")
|
||||||
|
|
||||||
async def pay_invoice(self, bolt11: str, fee_limit_msat: int) -> PaymentResponse:
|
async def pay_invoice(self, bolt11: str, fee_limit_msat: int) -> PaymentResponse:
|
||||||
try:
|
try:
|
||||||
@ -529,23 +527,3 @@ class StrikeWallet(Wallet):
|
|||||||
except Exception:
|
except Exception:
|
||||||
logger.exception("Error in get_invoices()")
|
logger.exception("Error in get_invoices()")
|
||||||
return {"error": "unable to fetch invoices"}
|
return {"error": "unable to fetch invoices"}
|
||||||
|
|
||||||
async def cancel_invoice(self, invoice_id: str) -> Dict[str, Any]:
|
|
||||||
try:
|
|
||||||
r = await self._patch(
|
|
||||||
f"/invoices/{invoice_id}/cancel"
|
|
||||||
) # Cancel invoice on Strike.
|
|
||||||
return r.json()
|
|
||||||
except Exception:
|
|
||||||
logger.exception("Error in cancel_invoice()")
|
|
||||||
return {"error": "unable to cancel invoice"}
|
|
||||||
|
|
||||||
async def get_account_profile_by_handle(self, handle: str) -> Dict[str, Any]:
|
|
||||||
try:
|
|
||||||
r = await self._get(
|
|
||||||
f"/accounts/handle/{handle}"
|
|
||||||
) # Get account profile by handle from Strike API.
|
|
||||||
return r.json()
|
|
||||||
except Exception:
|
|
||||||
logger.exception("Error in get_account_profile_by_handle()")
|
|
||||||
return {"error": "unable to fetch profile"}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user