diff --git a/src/composables/useMarket.ts b/src/composables/useMarket.ts index ecc7785..7bfe108 100644 --- a/src/composables/useMarket.ts +++ b/src/composables/useMarket.ts @@ -277,7 +277,8 @@ export function useMarket() { console.log('Processing most recent product event:', event) console.log('Parsed product data:', productData) - const stall = marketStore.stalls.find(s => s.pubkey === event.pubkey) + // Find stall by stall_id from product data, not by pubkey + const stall = marketStore.stalls.find(s => s.id === productData.stall_id) console.log('Found stall for product:', stall) if (stall) { @@ -299,7 +300,11 @@ export function useMarket() { console.log('Created product (most recent version):', product) marketStore.addProduct(product) } else { - console.warn('No stall found for product pubkey:', event.pubkey) + console.warn('No matching stall found for product:', { + productId: productData.id, + stallId: productData.stall_id, + availableStalls: marketStore.stalls.map(s => ({ id: s.id, name: s.name })) + }) } }) @@ -430,8 +435,14 @@ export function useMarket() { const handleStallEvent = (event: any) => { try { const stallData = JSON.parse(event.content) + console.log('Processing stall event:', { + stallId: stallData.id, + stallName: stallData.name, + merchantPubkey: event.pubkey + }) + const stall: Stall = { - id: event.id, + id: stallData.id, // Use stall ID from content, not event ID pubkey: event.pubkey, name: stallData.name, description: stallData.description, @@ -449,11 +460,20 @@ export function useMarket() { const handleProductEvent = (event: any) => { try { const productData = JSON.parse(event.content) - const stall = marketStore.stalls.find(s => s.pubkey === event.pubkey) + console.log('Processing product event:', { + productId: productData.id, + productName: productData.name, + stallId: productData.stall_id, + merchantPubkey: event.pubkey + }) + + // Find stall by stall_id from product data, not by pubkey + const stall = marketStore.stalls.find(s => s.id === productData.stall_id) if (stall) { + console.log('Found matching stall:', { stallId: stall.id, stallName: stall.name }) const product: Product = { - id: event.id, + id: productData.id, // Use product ID from content, not event ID stall_id: stall.id, stallName: stall.name, name: productData.name, @@ -468,6 +488,12 @@ export function useMarket() { } marketStore.addProduct(product) + } else { + console.warn('No matching stall found for product:', { + productId: productData.id, + stallId: productData.stall_id, + availableStalls: marketStore.stalls.map(s => ({ id: s.id, name: s.name })) + }) } } catch (err) { console.warn('Failed to parse product event:', err)