refactor: Update event handling in useMarket to use stall IDs from product data
- Modify product and stall event processing to find stalls using stall IDs instead of pubkeys, improving data accuracy. - Enhance logging for better visibility into event processing and stall matching, including detailed warnings when stalls are not found.
This commit is contained in:
parent
d38978f446
commit
c91e35ac50
1 changed files with 31 additions and 5 deletions
|
|
@ -277,7 +277,8 @@ export function useMarket() {
|
||||||
console.log('Processing most recent product event:', event)
|
console.log('Processing most recent product event:', event)
|
||||||
console.log('Parsed product data:', productData)
|
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)
|
console.log('Found stall for product:', stall)
|
||||||
|
|
||||||
if (stall) {
|
if (stall) {
|
||||||
|
|
@ -299,7 +300,11 @@ export function useMarket() {
|
||||||
console.log('Created product (most recent version):', product)
|
console.log('Created product (most recent version):', product)
|
||||||
marketStore.addProduct(product)
|
marketStore.addProduct(product)
|
||||||
} else {
|
} 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) => {
|
const handleStallEvent = (event: any) => {
|
||||||
try {
|
try {
|
||||||
const stallData = JSON.parse(event.content)
|
const stallData = JSON.parse(event.content)
|
||||||
|
console.log('Processing stall event:', {
|
||||||
|
stallId: stallData.id,
|
||||||
|
stallName: stallData.name,
|
||||||
|
merchantPubkey: event.pubkey
|
||||||
|
})
|
||||||
|
|
||||||
const stall: Stall = {
|
const stall: Stall = {
|
||||||
id: event.id,
|
id: stallData.id, // Use stall ID from content, not event ID
|
||||||
pubkey: event.pubkey,
|
pubkey: event.pubkey,
|
||||||
name: stallData.name,
|
name: stallData.name,
|
||||||
description: stallData.description,
|
description: stallData.description,
|
||||||
|
|
@ -449,11 +460,20 @@ export function useMarket() {
|
||||||
const handleProductEvent = (event: any) => {
|
const handleProductEvent = (event: any) => {
|
||||||
try {
|
try {
|
||||||
const productData = JSON.parse(event.content)
|
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) {
|
if (stall) {
|
||||||
|
console.log('Found matching stall:', { stallId: stall.id, stallName: stall.name })
|
||||||
const product: Product = {
|
const product: Product = {
|
||||||
id: event.id,
|
id: productData.id, // Use product ID from content, not event ID
|
||||||
stall_id: stall.id,
|
stall_id: stall.id,
|
||||||
stallName: stall.name,
|
stallName: stall.name,
|
||||||
name: productData.name,
|
name: productData.name,
|
||||||
|
|
@ -468,6 +488,12 @@ export function useMarket() {
|
||||||
}
|
}
|
||||||
|
|
||||||
marketStore.addProduct(product)
|
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) {
|
} catch (err) {
|
||||||
console.warn('Failed to parse product event:', err)
|
console.warn('Failed to parse product event:', err)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue