Refactor OrderHistory and introduce payment status checker

- Update OrderHistory.vue to utilize a new method for determining effective order status, enhancing clarity in payment and shipping status display.
- Add a new composable, usePaymentStatusChecker, to handle payment status checks via LNbits API, improving order payment verification.
- Modify nostrmarketService to streamline order updates with consolidated status handling for paid and shipped states.
- Enhance market store initialization to include payment status and paid fields for better order management.
- Update market types to include new fields for payment and shipping status, ensuring consistency across the application.
This commit is contained in:
padreug 2025-09-05 05:16:25 +02:00
parent 4258ea87c4
commit 99bbde4d05
5 changed files with 230 additions and 34 deletions

View file

@ -403,7 +403,9 @@ export const useMarketStore = defineStore('market', () => {
...orderData,
id: orderData.id || generateOrderId(),
createdAt: Math.floor(Date.now() / 1000),
updatedAt: Math.floor(Date.now() / 1000)
updatedAt: Math.floor(Date.now() / 1000),
paid: false, // Initialize as unpaid
paymentStatus: orderData.paymentStatus || 'pending' // Default to pending if not specified
}
orders.value[order.id] = order
@ -682,7 +684,22 @@ export const useMarketStore = defineStore('market', () => {
try {
const storageKey = getUserStorageKey('market_orders')
localStorage.setItem(storageKey, JSON.stringify(orders.value))
console.log('Saved orders to localStorage with key:', storageKey)
// Debug: Check what's being saved
const orderCount = Object.keys(orders.value).length
const paidOrders = Object.values(orders.value).filter(o => o.paymentStatus === 'paid' || o.status === 'paid')
console.log('💾 Saved orders to localStorage:', {
storageKey,
totalOrders: orderCount,
paidOrders: paidOrders.length,
orderStatuses: Object.values(orders.value).map(o => ({
id: o.id?.slice(-8),
status: o.status,
paymentStatus: o.paymentStatus,
hasPaymentRequest: !!o.paymentRequest
}))
})
} catch (error) {
console.warn('Failed to save orders to localStorage:', error)
}
@ -695,7 +712,22 @@ export const useMarketStore = defineStore('market', () => {
if (stored) {
const parsedOrders = JSON.parse(stored)
orders.value = parsedOrders
console.log('Loaded orders from localStorage with key:', storageKey, 'Orders count:', Object.keys(parsedOrders).length)
// Debug: Check payment status of loaded orders
const orderCount = Object.keys(parsedOrders).length
const paidOrders = Object.values(parsedOrders).filter((o: any) => o.paymentStatus === 'paid' || o.status === 'paid')
console.log('📦 Loaded orders from localStorage:', {
storageKey,
totalOrders: orderCount,
paidOrders: paidOrders.length,
orderStatuses: Object.values(parsedOrders).map((o: any) => ({
id: o.id?.slice(-8),
status: o.status,
paymentStatus: o.paymentStatus,
hasPaymentRequest: !!o.paymentRequest
}))
})
} else {
console.log('No orders found in localStorage for key:', storageKey)
// Clear any existing orders when switching users