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",