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:
parent
5e67ce562b
commit
8b16ead5b1
1 changed files with 8 additions and 6 deletions
14
views_api.py
14
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue