Supports new amount format and metadata tracking

Updates the amount parsing logic to support a new format where fiat amounts (EUR/USD) are specified directly.

Adds support for tracking SATS equivalents from metadata when the new format is used.

Also tracks fiat amounts specified in metadata as a fallback for backward compatibility.
Reverses the calculation of net balance to correctly reflect receivables and liabilities.
This commit is contained in:
padreug 2025-11-10 03:42:30 +01:00
parent ca2ce1dfcc
commit 476e9dec4b
2 changed files with 48 additions and 29 deletions

View file

@ -1104,12 +1104,13 @@ async def api_get_my_balance(
all_balances = await fava.get_all_user_balances()
# Calculate total:
# Positive balances = Castle owes users (liabilities)
# Negative balances = Users owe Castle (receivables)
# Net: positive means castle owes, negative means castle is owed
total_liabilities = sum(b["balance"] for b in all_balances if b["balance"] > 0)
total_receivables = sum(abs(b["balance"]) for b in all_balances if b["balance"] < 0)
net_balance = total_liabilities - total_receivables
# From get_user_balance(): positive = user owes castle, negative = castle owes user
# Positive balances = Users owe Castle (receivables for Castle)
# Negative balances = Castle owes users (liabilities for Castle)
# Net: positive means castle is owed money, negative means castle owes money
total_receivables = sum(b["balance"] for b in all_balances if b["balance"] > 0)
total_liabilities = sum(abs(b["balance"]) for b in all_balances if b["balance"] < 0)
net_balance = total_receivables - total_liabilities
# Aggregate fiat balances from all users
total_fiat_balances = {}