From 8b16ead5b172d8f6e5bfb93a0e292de52f537939 Mon Sep 17 00:00:00 2001 From: padreug Date: Sat, 1 Nov 2025 23:24:38 +0100 Subject: [PATCH] Formats fiat amounts and rates in API calls Ensures consistent formatting of fiat currency, amount, and exchange rates in the `api_settle_receivable` and `api_pay_user` API endpoints. Specifically, it: - Converts fiat currency to uppercase. - Formats fiat amount to three decimal places. - Calculates and includes fiat and BTC rates. --- views_api.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/views_api.py b/views_api.py index cfc950a..2be05b1 100644 --- a/views_api.py +++ b/views_api.py @@ -842,9 +842,10 @@ async def api_settle_receivable( ) amount_in_sats = data.amount_sats line_metadata = { - "fiat_currency": data.currency, - "fiat_amount": str(data.amount), - "exchange_rate": data.amount_sats / float(data.amount) + "fiat_currency": data.currency.upper(), + "fiat_amount": str(data.amount.quantize(Decimal("0.001"))), + "fiat_rate": float(data.amount_sats) / float(data.amount) if data.amount > 0 else 0, + "btc_rate": float(data.amount) / float(data.amount_sats) * 100_000_000 if data.amount_sats > 0 else 0, } else: # Satoshi payment @@ -988,9 +989,10 @@ async def api_pay_user( ) amount_in_sats = data.amount_sats line_metadata = { - "fiat_currency": data.currency, - "fiat_amount": str(data.amount), - "exchange_rate": data.amount_sats / float(data.amount) + "fiat_currency": data.currency.upper(), + "fiat_amount": str(data.amount.quantize(Decimal("0.001"))), + "fiat_rate": float(data.amount_sats) / float(data.amount) if data.amount > 0 else 0, + "btc_rate": float(data.amount) / float(data.amount_sats) * 100_000_000 if data.amount_sats > 0 else 0, } else: # Satoshi payment