fix: ui testing
This commit is contained in:
parent
5d33fcd756
commit
4ae8b21cb8
4 changed files with 43 additions and 28 deletions
|
|
@ -79,7 +79,7 @@
|
||||||
<q-item v-for="product in order.products" :key="product.id">
|
<q-item v-for="product in order.products" :key="product.id">
|
||||||
<q-item-section avatar>
|
<q-item-section avatar>
|
||||||
<q-avatar>
|
<q-avatar>
|
||||||
<img v-if="product.images[0] || product.image" :src="product.images[0] || product.image" />
|
<img v-if="product.images && product.images[0] || product.image" :src="product.images[0] || product.image" />
|
||||||
<img v-else src="/nostrmarket/static/images/placeholder.png" />
|
<img v-else src="/nostrmarket/static/images/placeholder.png" />
|
||||||
</q-avatar>
|
</q-avatar>
|
||||||
</q-item-section>
|
</q-item-section>
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ async function customerOrders(path) {
|
||||||
return {
|
return {
|
||||||
...order,
|
...order,
|
||||||
stallName: stall?.name || 'Stall',
|
stallName: stall?.name || 'Stall',
|
||||||
shippingZone: stall?.shipping?.find(s => s.id === order.shipping_id),
|
shippingZone: stall?.shipping?.find(s => s.id === order.shipping_id) || { id: order.shipping_id, name: order.shipping_id },
|
||||||
invoice: this.invoiceForOrder(order),
|
invoice: this.invoiceForOrder(order),
|
||||||
products: this.getProductsForOrder(order)
|
products: this.getProductsForOrder(order)
|
||||||
}
|
}
|
||||||
|
|
@ -62,10 +62,14 @@ async function customerOrders(path) {
|
||||||
|
|
||||||
getProductsForOrder: function (order) {
|
getProductsForOrder: function (order) {
|
||||||
if (!order?.items?.length) return []
|
if (!order?.items?.length) return []
|
||||||
const productsIds = order.items.map(i => i.product_id)
|
|
||||||
return this.products
|
return order.items.map(i => {
|
||||||
.filter(p => productsIds.indexOf(p.id) !== -1)
|
const product = this.products.find(p => p.id === i.product_id) || { id: i.product_id, name: i.product_id }
|
||||||
.map(p => ({ ...p, orderedQuantity: order.items.find(i => i.product_id === p.id).quantity }))
|
return {
|
||||||
|
...product,
|
||||||
|
orderedQuantity: i.quantity
|
||||||
|
}
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
showInvoice: function (order) {
|
showInvoice: function (order) {
|
||||||
|
|
|
||||||
|
|
@ -725,55 +725,57 @@ const market = async () => {
|
||||||
async listenForIncommingDms(from) {
|
async listenForIncommingDms(from) {
|
||||||
console.log('### from', from)
|
console.log('### from', from)
|
||||||
if (!this.account?.privkey) {
|
if (!this.account?.privkey) {
|
||||||
this.$q.notify({
|
|
||||||
message: 'Cannot listen for direct messages. You need to login first!',
|
|
||||||
icon: 'warning'
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const filters = from.map(f =>
|
const filters = [{
|
||||||
({
|
|
||||||
kinds: [4],
|
kinds: [4],
|
||||||
authors: [f.publicKey],
|
|
||||||
'#p': [this.account.pubkey],
|
'#p': [this.account.pubkey],
|
||||||
since: f.since
|
}, {
|
||||||
}))
|
kinds: [4],
|
||||||
|
authors: [this.account.pubkey],
|
||||||
|
}]
|
||||||
|
|
||||||
console.log('### filters', filters)
|
console.log('### filters', filters)
|
||||||
const subs = this.pool.sub(Array.from(this.relays), filters)
|
const subs = this.pool.sub(Array.from(this.relays), filters)
|
||||||
subs.on('event', async event => {
|
subs.on('event', async event => {
|
||||||
const receiverPubkey = event.tags.find(([k, v]) => k === 'p' && v && v !== '')[1]
|
const receiverPubkey = event.tags.find(([k, v]) => k === 'p' && v && v !== '')[1]
|
||||||
if (receiverPubkey !== this.account.pubkey) {
|
const isSentByMe = event.pubkey === this.account.pubkey
|
||||||
|
if (receiverPubkey !== this.account.pubkey && !isSentByMe) {
|
||||||
console.log('Unexpected DM. Dropped!')
|
console.log('Unexpected DM. Dropped!')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
await this.handleIncommingDm(event)
|
this.persistDMEvent(event)
|
||||||
|
const peerPubkey = isSentByMe ? receiverPubkey : event.pubkey
|
||||||
|
await this.handleIncommingDm(event, peerPubkey)
|
||||||
})
|
})
|
||||||
return subs
|
return subs
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Error: ${err}`)
|
console.error(`Error: ${err}`)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async handleIncommingDm(event) {
|
async handleIncommingDm(event, peerPubkey) {
|
||||||
this.persistDMEvent(event)
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const plainText = await NostrTools.nip04.decrypt(
|
const plainText = await NostrTools.nip04.decrypt(
|
||||||
this.account.privkey,
|
this.account.privkey,
|
||||||
event.pubkey,
|
peerPubkey,
|
||||||
event.content
|
event.content
|
||||||
)
|
)
|
||||||
console.log('### plainText', plainText)
|
console.log('### plainText', plainText)
|
||||||
if (!isJson(plainText)) return
|
if (!isJson(plainText)) return
|
||||||
|
|
||||||
const jsonData = JSON.parse(plainText)
|
const jsonData = JSON.parse(plainText)
|
||||||
|
console.log('###### type: ', jsonData.type)
|
||||||
|
if ([0, 1, 2].indexOf(jsonData.type) !== -1) {
|
||||||
|
this.persistOrderUpdate(peerPubkey, event.created_at, jsonData)
|
||||||
|
}
|
||||||
if (jsonData.type === 1) {
|
if (jsonData.type === 1) {
|
||||||
this.handlePaymentRequest(jsonData)
|
this.handlePaymentRequest(jsonData)
|
||||||
this.persistOrderUpdate(event.pubkey, event.created_at, jsonData)
|
|
||||||
} else if (jsonData.type === 2) {
|
} else if (jsonData.type === 2) {
|
||||||
this.handleOrderStatusUpdate(jsonData)
|
this.handleOrderStatusUpdate(jsonData)
|
||||||
this.persistOrderUpdate(event.pubkey, event.created_at, jsonData)
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('Unable to handle incomming DM', e)
|
console.warn('Unable to handle incomming DM', e)
|
||||||
|
|
@ -832,11 +834,17 @@ const market = async () => {
|
||||||
return dms.lastCreatedAt
|
return dms.lastCreatedAt
|
||||||
},
|
},
|
||||||
|
|
||||||
persistOrderUpdate(pubkey, createdAt, orderUpdate) {
|
persistOrderUpdate(pubkey, eventCreatedAt, orderUpdate) {
|
||||||
|
console.log(('### persistOrderUpdate', pubkey, eventCreatedAt, orderUpdate))
|
||||||
let orders = this.$q.localStorage.getItem(`nostrmarket.orders.${pubkey}`) || []
|
let orders = this.$q.localStorage.getItem(`nostrmarket.orders.${pubkey}`) || []
|
||||||
let order = orders.find(o => o.id === orderUpdate.id)
|
let order = orders.find(o => o.id === orderUpdate.id)
|
||||||
if (!order) {
|
if (!order) {
|
||||||
orders.unshift({ ...orderUpdate, createdAt, messages: orderUpdate.message ? [orderUpdate.message] : [] })
|
orders.unshift({
|
||||||
|
...orderUpdate,
|
||||||
|
eventCreatedAt,
|
||||||
|
createdAt: eventCreatedAt,
|
||||||
|
messages: orderUpdate.message ? [orderUpdate.message] : []
|
||||||
|
})
|
||||||
this.orders[pubkey] = orders
|
this.orders[pubkey] = orders
|
||||||
this.$q.localStorage.set(`nostrmarket.orders.${pubkey}`, orders)
|
this.$q.localStorage.set(`nostrmarket.orders.${pubkey}`, orders)
|
||||||
return
|
return
|
||||||
|
|
@ -846,8 +854,11 @@ const market = async () => {
|
||||||
order.messages.push(orderUpdate.message)
|
order.messages.push(orderUpdate.message)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (orderUpdate.type === 0 || orderUpdate.type === 1) {
|
if (orderUpdate.type === 0) {
|
||||||
order = { ...orderUpdate, ...order }
|
order.createdAt = eventCreatedAt
|
||||||
|
order = { ...order, ...orderUpdate }
|
||||||
|
} else if (orderUpdate.type === 1) {
|
||||||
|
order = order.eventCreatedAt < eventCreatedAt ? { ...order, ...orderUpdate } : { ...orderUpdate, ...order }
|
||||||
} else if (orderUpdate.type === 2) {
|
} else if (orderUpdate.type === 2) {
|
||||||
order.paid = orderUpdate.paid
|
order.paid = orderUpdate.paid
|
||||||
order.shipped = orderUpdate.shipped
|
order.shipped = orderUpdate.shipped
|
||||||
|
|
@ -859,7 +870,7 @@ const market = async () => {
|
||||||
this.$q.localStorage.set(`nostrmarket.orders.${pubkey}`, orders)
|
this.$q.localStorage.set(`nostrmarket.orders.${pubkey}`, orders)
|
||||||
},
|
},
|
||||||
|
|
||||||
showInvoiceQr(invoice){
|
showInvoiceQr(invoice) {
|
||||||
if (!invoice) return
|
if (!invoice) return
|
||||||
this.qrCodeDialog = {
|
this.qrCodeDialog = {
|
||||||
data: {
|
data: {
|
||||||
|
|
|
||||||
|
|
@ -914,7 +914,7 @@ async def api_reissue_order_invoice(
|
||||||
)
|
)
|
||||||
|
|
||||||
return order
|
return order
|
||||||
except AssertionError as ex:
|
except (AssertionError, ValueError) as ex:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.BAD_REQUEST,
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
detail=str(ex),
|
detail=str(ex),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue