Refactor transaction display logic in WalletPage for improved status handling

- Updated the getTransactionIcon and getTransactionColor functions to accept transaction status, allowing for dynamic icon and color changes based on transaction state.
- Removed the getStatusColor function as its functionality is now integrated into the updated color logic.
- Enhanced transaction display in the WalletPage to reflect pending status with appropriate styling, improving user visibility of transaction states.

These changes enhance the clarity and responsiveness of transaction information presented in the wallet module.
This commit is contained in:
padreug 2025-09-15 00:07:47 +02:00
parent d2a5d90427
commit 3d428719be

View file

@ -62,26 +62,20 @@ async function refresh() {
await authService?.refresh() await authService?.refresh()
} }
function getTransactionIcon(type: string) { function getTransactionIcon(type: string, status: string) {
if (status === 'pending') {
return Clock
}
return type === 'received' ? ArrowDownLeft : ArrowUpRight return type === 'received' ? ArrowDownLeft : ArrowUpRight
} }
function getTransactionColor(type: string) { function getTransactionColor(type: string, status: string) {
return type === 'received' ? 'text-green-600' : 'text-orange-600' if (status === 'pending') {
return 'text-amber-500'
}
return type === 'received' ? 'text-green-600' : 'text-red-600'
} }
function getStatusColor(status: string) {
switch (status) {
case 'confirmed':
return 'default'
case 'pending':
return 'secondary'
case 'failed':
return 'destructive'
default:
return 'outline'
}
}
// Initialize on mount // Initialize on mount
onMounted(() => { onMounted(() => {
@ -191,10 +185,10 @@ onMounted(() => {
<div class="flex items-center gap-3"> <div class="flex items-center gap-3">
<div <div
class="p-1.5 rounded-full bg-background border" class="p-1.5 rounded-full bg-background border"
:class="getTransactionColor(tx.type)" :class="getTransactionColor(tx.type, tx.status)"
> >
<component <component
:is="getTransactionIcon(tx.type)" :is="getTransactionIcon(tx.type, tx.status)"
class="h-3.5 w-3.5" class="h-3.5 w-3.5"
/> />
</div> </div>
@ -222,7 +216,7 @@ onMounted(() => {
<div class="text-right"> <div class="text-right">
<p <p
class="font-semibold text-base" class="font-semibold text-base"
:class="getTransactionColor(tx.type)" :class="getTransactionColor(tx.type, tx.status)"
> >
{{ tx.type === 'received' ? '+' : '-' }}{{ tx.amount.toLocaleString() }} {{ tx.type === 'received' ? '+' : '-' }}{{ tx.amount.toLocaleString() }}
</p> </p>
@ -237,9 +231,6 @@ onMounted(() => {
<!-- Badges Row --> <!-- Badges Row -->
<div class="flex items-center gap-2 flex-wrap"> <div class="flex items-center gap-2 flex-wrap">
<Badge :variant="getStatusColor(tx.status)" class="text-xs">
{{ tx.status }}
</Badge>
<Badge v-if="tx.tag" variant="outline" class="text-xs"> <Badge v-if="tx.tag" variant="outline" class="text-xs">
{{ tx.tag }} {{ tx.tag }}
</Badge> </Badge>
@ -254,10 +245,10 @@ onMounted(() => {
<div class="flex items-center gap-4"> <div class="flex items-center gap-4">
<div <div
class="p-2 rounded-full bg-background border" class="p-2 rounded-full bg-background border"
:class="getTransactionColor(tx.type)" :class="getTransactionColor(tx.type, tx.status)"
> >
<component <component
:is="getTransactionIcon(tx.type)" :is="getTransactionIcon(tx.type, tx.status)"
class="h-4 w-4" class="h-4 w-4"
/> />
</div> </div>
@ -284,9 +275,6 @@ onMounted(() => {
} }
})() })()
}}</span> }}</span>
<Badge :variant="getStatusColor(tx.status)" class="text-xs">
{{ tx.status }}
</Badge>
<Badge v-if="tx.tag" variant="outline" class="text-xs"> <Badge v-if="tx.tag" variant="outline" class="text-xs">
{{ tx.tag }} {{ tx.tag }}
</Badge> </Badge>
@ -297,7 +285,7 @@ onMounted(() => {
<div class="text-right ml-4"> <div class="text-right ml-4">
<p <p
class="font-semibold" class="font-semibold"
:class="getTransactionColor(tx.type)" :class="getTransactionColor(tx.type, tx.status)"
> >
{{ tx.type === 'received' ? '+' : '-' }} {{ tx.type === 'received' ? '+' : '-' }}
{{ tx.amount.toLocaleString() }} sats {{ tx.amount.toLocaleString() }} sats