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:
parent
e5054fdb9d
commit
876eb4f20b
2 changed files with 14 additions and 5 deletions
|
|
@ -271,7 +271,7 @@ export default class WalletService extends BaseService {
|
||||||
id: payment.payment_hash,
|
id: payment.payment_hash,
|
||||||
amount: Math.abs(payment.amount),
|
amount: Math.abs(payment.amount),
|
||||||
description: payment.memo || payment.description || 'No description',
|
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',
|
type: payment.amount > 0 ? 'received' : 'sent',
|
||||||
status: payment.pending ? 'pending' : 'confirmed',
|
status: payment.pending ? 'pending' : 'confirmed',
|
||||||
fee: payment.fee
|
fee: payment.fee
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,12 @@ const groupedTransactions = computed(() => {
|
||||||
const groups: Record<string, typeof transactions.value> = {}
|
const groups: Record<string, typeof transactions.value> = {}
|
||||||
|
|
||||||
transactions.value.forEach((tx: any) => {
|
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]) {
|
if (!groups[dateKey]) {
|
||||||
groups[dateKey] = []
|
groups[dateKey] = []
|
||||||
}
|
}
|
||||||
|
|
@ -189,7 +194,11 @@ onMounted(() => {
|
||||||
<div>
|
<div>
|
||||||
<p class="font-medium">{{ tx.description }}</p>
|
<p class="font-medium">{{ tx.description }}</p>
|
||||||
<div class="flex items-center gap-2 text-sm text-muted-foreground">
|
<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">
|
<Badge :variant="getStatusColor(tx.status)" class="text-xs">
|
||||||
{{ tx.status }}
|
{{ tx.status }}
|
||||||
</Badge>
|
</Badge>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue