From 3cb3b23a8d9f2183b8e35b0b21ac6be9035682be Mon Sep 17 00:00:00 2001 From: padreug Date: Mon, 10 Nov 2025 01:09:49 +0100 Subject: [PATCH] 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. --- views_api.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/views_api.py b/views_api.py index b5332a1..cb79ed1 100644 --- a/views_api.py +++ b/views_api.py @@ -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",