Improves pending entry amount parsing

Updates the pending entries API to correctly parse the amount and fiat values from the amount string, which can now contain both SATS and fiat information.

This change handles different formats of the amount string, including cases where the fiat amount is present within curly braces.
This commit is contained in:
padreug 2025-11-10 01:09:49 +01:00
parent 0c7356e228
commit 3cb3b23a8d

View file

@ -504,19 +504,23 @@ async def api_get_pending_entries(
postings = e.get("postings", [])
if postings:
# Get amount from first posting
first_posting = postings[0]
if isinstance(first_posting, dict):
amount_field = first_posting.get("amount")
if isinstance(amount_field, dict):
# Parse amount like {"number": "42185", "currency": "SATS"}
amount_sats = abs(int(float(amount_field.get("number", 0))))
amount_str = first_posting.get("amount", "")
# Get fiat from cost
cost = first_posting.get("cost")
if isinstance(cost, dict):
fiat_amount = float(cost.get("number", 0))
fiat_currency = cost.get("currency")
# Parse amount string format: "36791 SATS {33.33 EUR, 2025-11-09}" or "36791 SATS"
if isinstance(amount_str, str) and amount_str:
import re
# Extract SATS amount (before " SATS")
sats_match = re.match(r'^(-?\d+)\s+SATS', amount_str)
if sats_match:
amount_sats = abs(int(sats_match.group(1)))
# Extract fiat from cost syntax: {33.33 EUR, ...}
cost_match = re.search(r'\{([\d.]+)\s+([A-Z]+)', amount_str)
if cost_match:
fiat_amount = float(cost_match.group(1))
fiat_currency = cost_match.group(2)
entry_data = {
"id": entry_id or "unknown",