feat(libra/balance): show fiat balances alongside sats

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Padreug 2026-05-17 15:44:23 +02:00
commit 26a89c58dd
2 changed files with 20 additions and 1 deletions

View file

@ -17,9 +17,14 @@ const expensesAPI = injectService<ExpensesAPI>(SERVICE_TOKENS.EXPENSES_API)
const balance = ref<number | null>(null) const balance = ref<number | null>(null)
const balanceCurrency = ref<string>('sats') const balanceCurrency = ref<string>('sats')
const fiatBalances = ref<Record<string, number>>({})
const pendingTransactions = ref<Transaction[]>([]) const pendingTransactions = ref<Transaction[]>([])
const isLoading = ref(true) const isLoading = ref(true)
const fiatBalanceEntries = computed(() =>
Object.entries(fiatBalances.value).filter(([, amount]) => Math.abs(amount) > 0.005)
)
const walletKey = computed(() => user.value?.wallets?.[0]?.inkey) const walletKey = computed(() => user.value?.wallets?.[0]?.inkey)
const budgetsEnabled = computed(() => import.meta.env.VITE_LIBRA_BUDGETS_ENABLED === 'true') const budgetsEnabled = computed(() => import.meta.env.VITE_LIBRA_BUDGETS_ENABLED === 'true')
@ -55,6 +60,7 @@ async function loadData() {
balance.value = balanceData.balance balance.value = balanceData.balance
balanceCurrency.value = balanceData.currency || 'sats' balanceCurrency.value = balanceData.currency || 'sats'
fiatBalances.value = balanceData.fiat_balances || {}
// Filter for pending transactions (flag = '!') // Filter for pending transactions (flag = '!')
pendingTransactions.value = txData.entries.filter(tx => tx.flag === '!') pendingTransactions.value = txData.entries.filter(tx => tx.flag === '!')
@ -112,6 +118,15 @@ function formatFiat(amount: number, currency: string): string {
</span> </span>
<span class="text-lg text-muted-foreground">{{ balanceCurrency }}</span> <span class="text-lg text-muted-foreground">{{ balanceCurrency }}</span>
</div> </div>
<div v-if="fiatBalanceEntries.length > 0" class="flex flex-wrap items-center gap-x-3 gap-y-1 pl-7">
<span
v-for="[currency, amount] in fiatBalanceEntries"
:key="currency"
class="text-base text-muted-foreground"
>
{{ formatFiat(Math.abs(amount), currency) }}
</span>
</div>
<p class="text-sm" :class="libraOwesUser ? 'text-green-600 dark:text-green-400' : 'text-red-600 dark:text-red-400'"> <p class="text-sm" :class="libraOwesUser ? 'text-green-600 dark:text-green-400' : 'text-red-600 dark:text-red-400'">
{{ libraOwesUser ? t('libra.balance.owedToYou') : t('libra.balance.youOwe') }} {{ libraOwesUser ? t('libra.balance.owedToYou') : t('libra.balance.youOwe') }}
</p> </p>

View file

@ -245,7 +245,11 @@ export class ExpensesAPI extends BaseService {
/** /**
* Get user's balance with libra * Get user's balance with libra
*/ */
async getUserBalance(walletKey: string): Promise<{ balance: number; currency: string }> { async getUserBalance(walletKey: string): Promise<{
balance: number
currency: string
fiat_balances?: Record<string, number>
}> {
try { try {
const response = await fetch(`${this.baseUrl}/libra/api/v1/balance`, { const response = await fetch(`${this.baseUrl}/libra/api/v1/balance`, {
method: 'GET', method: 'GET',