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.
This commit is contained in:
padreug 2025-11-01 23:24:38 +01:00
parent 5e67ce562b
commit 8b16ead5b1

View file

@ -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