Fix balance sign interpretation on Castle balance page

Castle API returns positive = user owes castle, negative = castle owes
user. The display was inverted, showing "you owe" after submitting an
expense when it should show "owed to you".

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Padreug 2026-04-25 17:07:26 +02:00
commit bac9fd091e

View file

@ -42,7 +42,8 @@ const pendingFiatCurrency = computed(() => {
return tx?.fiat_currency ?? null return tx?.fiat_currency ?? null
}) })
const balanceIsPositive = computed(() => (balance.value ?? 0) >= 0) // Castle API: positive = user owes castle, negative = castle owes user
const castleOwesUser = computed(() => (balance.value ?? 0) <= 0)
async function loadData() { async function loadData() {
if (!walletKey.value) return if (!walletKey.value) return
@ -120,17 +121,17 @@ function formatFiat(amount: number, currency: string): string {
<div v-if="balance !== null" class="space-y-1"> <div v-if="balance !== null" class="space-y-1">
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<component <component
:is="balanceIsPositive ? ArrowDown : ArrowUp" :is="castleOwesUser ? ArrowDown : ArrowUp"
class="w-5 h-5" class="w-5 h-5"
:class="balanceIsPositive ? 'text-green-500' : 'text-red-500'" :class="castleOwesUser ? 'text-green-500' : 'text-red-500'"
/> />
<span class="text-3xl font-bold text-foreground"> <span class="text-3xl font-bold text-foreground">
{{ formatAmount(balance) }} {{ formatAmount(balance) }}
</span> </span>
<span class="text-lg text-muted-foreground">{{ balanceCurrency }}</span> <span class="text-lg text-muted-foreground">{{ balanceCurrency }}</span>
</div> </div>
<p class="text-sm" :class="balanceIsPositive ? 'text-green-600 dark:text-green-400' : 'text-red-600 dark:text-red-400'"> <p class="text-sm" :class="castleOwesUser ? 'text-green-600 dark:text-green-400' : 'text-red-600 dark:text-red-400'">
{{ balanceIsPositive ? t('castle.balance.owedToYou') : t('castle.balance.youOwe') }} {{ castleOwesUser ? t('castle.balance.owedToYou') : t('castle.balance.youOwe') }}
</p> </p>
</div> </div>