commit
f91c0ec38c
1 changed files with 52 additions and 63 deletions
|
|
@ -193,69 +193,58 @@ async function customerStall(path) {
|
||||||
},
|
},
|
||||||
async placeOrder() {
|
async placeOrder() {
|
||||||
this.loading = true
|
this.loading = true
|
||||||
LNbits.utils
|
let orderData = this.checkoutDialog.data
|
||||||
.confirmDialog(
|
let orderObj = {
|
||||||
`Send the order to the merchant? You should receive a message with the payment details.`
|
name: orderData?.username,
|
||||||
)
|
address: orderData.address,
|
||||||
.onOk(async () => {
|
message: orderData?.message,
|
||||||
let orderData = this.checkoutDialog.data
|
contact: {
|
||||||
let orderObj = {
|
nostr: this.customerPubkey,
|
||||||
name: orderData?.username,
|
phone: null,
|
||||||
address: orderData.address,
|
email: orderData?.email
|
||||||
message: orderData?.message,
|
},
|
||||||
contact: {
|
items: Array.from(this.cart.products, p => {
|
||||||
nostr: this.customerPubkey,
|
return {product_id: p[0], quantity: p[1].quantity}
|
||||||
phone: null,
|
|
||||||
email: orderData?.email
|
|
||||||
},
|
|
||||||
items: Array.from(this.cart.products, p => {
|
|
||||||
return {product_id: p[0], quantity: p[1].quantity}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
let created_at = Math.floor(Date.now() / 1000)
|
|
||||||
orderObj.id = await hash(
|
|
||||||
[this.customerPubkey, created_at, JSON.stringify(orderObj)].join(
|
|
||||||
':'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
this.activeOrder = orderObj.id
|
|
||||||
let event = {
|
|
||||||
...(await NostrTools.getBlankEvent()),
|
|
||||||
kind: 4,
|
|
||||||
created_at,
|
|
||||||
tags: [['p', this.stall.pubkey]],
|
|
||||||
pubkey: this.customerPubkey
|
|
||||||
}
|
|
||||||
if (this.customerPrivkey) {
|
|
||||||
event.content = await NostrTools.nip04.encrypt(
|
|
||||||
this.customerPrivkey,
|
|
||||||
this.stall.pubkey,
|
|
||||||
JSON.stringify(orderObj)
|
|
||||||
)
|
|
||||||
} else if (this.customerUseExtension && this.hasNip07) {
|
|
||||||
event.content = await window.nostr.nip04.encrypt(
|
|
||||||
this.stall.pubkey,
|
|
||||||
JSON.stringify(orderObj)
|
|
||||||
)
|
|
||||||
let userRelays = Object.keys(
|
|
||||||
(await window.nostr?.getRelays?.()) || []
|
|
||||||
)
|
|
||||||
if (userRelays.length != 0) {
|
|
||||||
userRelays.map(r => this.relays.add(r))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
event.id = NostrTools.getEventHash(event)
|
|
||||||
if (this.customerPrivkey) {
|
|
||||||
event.sig = await NostrTools.signEvent(
|
|
||||||
event,
|
|
||||||
this.customerPrivkey
|
|
||||||
)
|
|
||||||
} else if (this.customerUseExtension && this.hasNip07) {
|
|
||||||
event = await window.nostr.signEvent(event)
|
|
||||||
}
|
|
||||||
this.resetCheckout()
|
|
||||||
await this.sendOrder(event)
|
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
let created_at = Math.floor(Date.now() / 1000)
|
||||||
|
orderObj.id = await hash(
|
||||||
|
[this.customerPubkey, created_at, JSON.stringify(orderObj)].join(':')
|
||||||
|
)
|
||||||
|
this.activeOrder = orderObj.id
|
||||||
|
let event = {
|
||||||
|
...(await NostrTools.getBlankEvent()),
|
||||||
|
kind: 4,
|
||||||
|
created_at,
|
||||||
|
tags: [['p', this.stall.pubkey]],
|
||||||
|
pubkey: this.customerPubkey
|
||||||
|
}
|
||||||
|
if (this.customerPrivkey) {
|
||||||
|
event.content = await NostrTools.nip04.encrypt(
|
||||||
|
this.customerPrivkey,
|
||||||
|
this.stall.pubkey,
|
||||||
|
JSON.stringify(orderObj)
|
||||||
|
)
|
||||||
|
} else if (this.customerUseExtension && this.hasNip07) {
|
||||||
|
event.content = await window.nostr.nip04.encrypt(
|
||||||
|
this.stall.pubkey,
|
||||||
|
JSON.stringify(orderObj)
|
||||||
|
)
|
||||||
|
let userRelays = Object.keys(
|
||||||
|
(await window.nostr?.getRelays?.()) || []
|
||||||
|
)
|
||||||
|
if (userRelays.length != 0) {
|
||||||
|
userRelays.map(r => this.relays.add(r))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event.id = NostrTools.getEventHash(event)
|
||||||
|
if (this.customerPrivkey) {
|
||||||
|
event.sig = await NostrTools.signEvent(event, this.customerPrivkey)
|
||||||
|
} else if (this.customerUseExtension && this.hasNip07) {
|
||||||
|
event = await window.nostr.signEvent(event)
|
||||||
|
}
|
||||||
|
this.resetCheckout()
|
||||||
|
await this.sendOrder(event)
|
||||||
},
|
},
|
||||||
async sendOrder(order) {
|
async sendOrder(order) {
|
||||||
this.$q.notify({
|
this.$q.notify({
|
||||||
|
|
@ -276,7 +265,7 @@ async function customerStall(path) {
|
||||||
await relay.connect()
|
await relay.connect()
|
||||||
let pub = relay.publish(order)
|
let pub = relay.publish(order)
|
||||||
pub.on('ok', () => {
|
pub.on('ok', () => {
|
||||||
console.debug(`${relay.url} has accepted our event`)
|
console.debug(`${relay.url} has accepted our event: ${order.id}`)
|
||||||
relay.close()
|
relay.close()
|
||||||
})
|
})
|
||||||
pub.on('failed', reason => {
|
pub.on('failed', reason => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue