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:
parent
84456a849e
commit
26a89c58dd
2 changed files with 20 additions and 1 deletions
|
|
@ -17,9 +17,14 @@ const expensesAPI = injectService<ExpensesAPI>(SERVICE_TOKENS.EXPENSES_API)
|
|||
|
||||
const balance = ref<number | null>(null)
|
||||
const balanceCurrency = ref<string>('sats')
|
||||
const fiatBalances = ref<Record<string, number>>({})
|
||||
const pendingTransactions = ref<Transaction[]>([])
|
||||
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 budgetsEnabled = computed(() => import.meta.env.VITE_LIBRA_BUDGETS_ENABLED === 'true')
|
||||
|
||||
|
|
@ -55,6 +60,7 @@ async function loadData() {
|
|||
|
||||
balance.value = balanceData.balance
|
||||
balanceCurrency.value = balanceData.currency || 'sats'
|
||||
fiatBalances.value = balanceData.fiat_balances || {}
|
||||
|
||||
// Filter for pending transactions (flag = '!')
|
||||
pendingTransactions.value = txData.entries.filter(tx => tx.flag === '!')
|
||||
|
|
@ -112,6 +118,15 @@ function formatFiat(amount: number, currency: string): string {
|
|||
</span>
|
||||
<span class="text-lg text-muted-foreground">{{ balanceCurrency }}</span>
|
||||
</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'">
|
||||
{{ libraOwesUser ? t('libra.balance.owedToYou') : t('libra.balance.youOwe') }}
|
||||
</p>
|
||||
|
|
|
|||
|
|
@ -245,7 +245,11 @@ export class ExpensesAPI extends BaseService {
|
|||
/**
|
||||
* 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 {
|
||||
const response = await fetch(`${this.baseUrl}/libra/api/v1/balance`, {
|
||||
method: 'GET',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue