Adds fiat currency balances to user balances
Extends user balance information to include fiat currency balances, calculated based on entry line metadata and account types. This allows for a more comprehensive view of user balances, including both satoshi and fiat currency holdings. Updates the castle index template and API to display fiat balances.
This commit is contained in:
parent
be386f60ef
commit
b0705fc24a
5 changed files with 116 additions and 4 deletions
16
views_api.py
16
views_api.py
|
|
@ -420,9 +420,23 @@ async def api_get_my_balance(
|
|||
if wallet.wallet.user == lnbits_settings.super_user:
|
||||
all_balances = await get_all_user_balances()
|
||||
total_owed = sum(b.balance for b in all_balances if b.balance > 0)
|
||||
|
||||
# Aggregate fiat balances from all users
|
||||
total_fiat_balances = {}
|
||||
for user_balance in all_balances:
|
||||
for currency, amount in user_balance.fiat_balances.items():
|
||||
if currency not in total_fiat_balances:
|
||||
total_fiat_balances[currency] = 0.0
|
||||
# Only add positive balances (what castle owes)
|
||||
if amount > 0:
|
||||
total_fiat_balances[currency] += amount
|
||||
|
||||
# Return as castle's "balance" - positive means castle owes money
|
||||
return UserBalance(
|
||||
user_id=wallet.wallet.user, balance=total_owed, accounts=[]
|
||||
user_id=wallet.wallet.user,
|
||||
balance=total_owed,
|
||||
accounts=[],
|
||||
fiat_balances=total_fiat_balances,
|
||||
)
|
||||
|
||||
# For regular users, show their individual balance
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue