Update WalletService and WalletPage to handle timestamps more robustly

- Modified WalletService to set a default timestamp when payment time is not provided, ensuring consistent date handling.
- Enhanced WalletPage to validate timestamps before formatting, preventing potential errors and improving user experience by displaying a placeholder for invalid timestamps.

These changes improve the reliability of transaction data presentation in the wallet module.
This commit is contained in:
padreug 2025-09-14 23:23:23 +02:00
parent e5054fdb9d
commit 876eb4f20b
2 changed files with 14 additions and 5 deletions

View file

@ -271,7 +271,7 @@ export default class WalletService extends BaseService {
id: payment.payment_hash,
amount: Math.abs(payment.amount),
description: payment.memo || payment.description || 'No description',
timestamp: new Date(payment.time * 1000),
timestamp: payment.time ? new Date(payment.time * 1000) : new Date(),
type: payment.amount > 0 ? 'received' : 'sent',
status: payment.pending ? 'pending' : 'confirmed',
fee: payment.fee

View file

@ -38,15 +38,20 @@ const totalBalance = computed(() => {
// Get transactions grouped by date
const groupedTransactions = computed(() => {
const groups: Record<string, typeof transactions.value> = {}
transactions.value.forEach((tx: any) => {
const dateKey = format(tx.timestamp, 'MMMM d, yyyy')
// Ensure timestamp is valid before formatting
const timestamp = tx.timestamp instanceof Date && !isNaN(tx.timestamp.getTime())
? tx.timestamp
: new Date()
const dateKey = format(timestamp, 'MMMM d, yyyy')
if (!groups[dateKey]) {
groups[dateKey] = []
}
groups[dateKey].push(tx)
})
return groups
})
@ -189,7 +194,11 @@ onMounted(() => {
<div>
<p class="font-medium">{{ tx.description }}</p>
<div class="flex items-center gap-2 text-sm text-muted-foreground">
<span>{{ format(tx.timestamp, 'HH:mm') }}</span>
<span>{{
tx.timestamp instanceof Date && !isNaN(tx.timestamp.getTime())
? format(tx.timestamp, 'HH:mm')
: '--:--'
}}</span>
<Badge :variant="getStatusColor(tx.status)" class="text-xs">
{{ tx.status }}
</Badge>