diff --git a/static/components/chat-dialog/chat-dialog.js b/static/components/chat-dialog/chat-dialog.js
index c111e27..405992b 100644
--- a/static/components/chat-dialog/chat-dialog.js
+++ b/static/components/chat-dialog/chat-dialog.js
@@ -17,7 +17,7 @@ async function chatDialog(path) {
},
computed: {
sortedMessages() {
- return this.nostrMessages.sort((a, b) => b.timestamp - a.timestamp)
+ return this.nostrMessages.sort((a, b) => b.created_at - a.created_at)
}
},
methods: {
@@ -36,11 +36,11 @@ async function chatDialog(path) {
let sub = this.pool.sub(Array.from(this.relays), [
{
kinds: [4],
- authors: [this.account.pubkey]
+ authors: [this.account.pubkey, this.merchant]
},
{
kinds: [4],
- '#p': [this.account.pubkey]
+ '#p': [this.account.pubkey, this.merchant]
}
])
sub.on('eose', () => {
@@ -68,18 +68,16 @@ async function chatDialog(path) {
)
}
messagesMap.set(event.id, {
+ created_at: event.created_at,
msg: plaintext,
timestamp: timeFromNow(event.created_at * 1000),
sender: `${mine ? 'Me' : 'Merchant'}`
})
+ this.nostrMessages = Array.from(messagesMap.values())
} catch {
console.error('Unable to decrypt message!')
}
})
- setTimeout(() => {
- this.nostrMessages = Array.from(messagesMap.values())
- this.loading = false
- }, 5000)
},
async sendMessage() {
if (this.newMessage && this.newMessage.length < 1) return
diff --git a/static/components/customer-stall/customer-stall.html b/static/components/customer-stall/customer-stall.html
index 572b90e..750d1e7 100644
--- a/static/components/customer-stall/customer-stall.html
+++ b/static/components/customer-stall/customer-stall.html
@@ -15,7 +15,7 @@
@@ -80,8 +80,8 @@
use a Nostr Signer Extension (NIP07)
- fill out the required fields, without keys, and download the
- order and send as a direct message to the merchant on any
+ fill out the required fields, with your publickey, download
+ the order and send as a direct message to the merchant on any
Nostr client
@@ -95,15 +95,6 @@
label="Get from Extension"
>Use a Nostr browser extension
- Download the order and send manually
@@ -123,7 +114,7 @@
:type="isPwd ? 'password' : 'text'"
v-if="!customerUseExtension"
v-model.trim="checkoutDialog.data.privkey"
- label="Private key"
+ label="Private key *optional"
hint="Enter your private key"
>
@@ -170,12 +161,13 @@
Download Order
@@ -214,12 +206,16 @@
+
+
+
Close
-
-
-
@@ -247,18 +240,36 @@
Order data
- {{ stall.pubkey }}
- Send the bellow message, to the merchant pubkey, in any Nostr
- client
+ Merchant pubkey
+
+ {{ `${stall.pubkey.slice(0,5)}...${stall.pubkey.slice(-5)}` }}
+
+
+
+ Click to copy
+
+
+ Send the bellow code as a message, to the merchant pubkey, in any
+ Nostr client
+
- {{JSON.stringify(downloadOrderDialog.data, null, 2)}}
+ {{JSON.stringify(downloadOrderDialog.data, null, 2)}}
+
+ Copy order
+ Close
+
diff --git a/static/components/customer-stall/customer-stall.js b/static/components/customer-stall/customer-stall.js
index 947c0b3..8b523b9 100644
--- a/static/components/customer-stall/customer-stall.js
+++ b/static/components/customer-stall/customer-stall.js
@@ -59,12 +59,28 @@ async function customerStall(path) {
z => z.id == this.checkoutDialog.data.shippingzone
)
return +this.cart.total + zoneCost.cost
+ },
+ dropIn() {
+ return {
+ privkey: this.customerPrivkey,
+ pubkey: this.customerPubkey,
+ useExtension: this.customerUseExtension
+ }
}
},
methods: {
changePageS(page, opts) {
this.$emit('change-page', page, opts)
},
+ copyText: function (text) {
+ var notify = this.$q.notify
+ Quasar.utils.copyToClipboard(text).then(function () {
+ notify({
+ message: 'Copied to clipboard!',
+ position: 'bottom'
+ })
+ })
+ },
getAmountFormated(amount, unit = 'USD') {
return LNbits.utils.formatCurrency(amount, unit)
},
@@ -120,24 +136,27 @@ async function customerStall(path) {
},
async downloadOrder() {
let created_at = Math.floor(Date.now() / 1000)
- let order = this.checkoutDialog.data
- // this.downloadOrderDialog.data = {
- // name: orderData?.username,
- // address: orderData.address,
- // message: orderData?.message,
- // contact: {
- // nostr: this.customerPubkey,
- // phone: null,
- // email: orderData?.email
- // },
- // items: Array.from(this.cart.products, p => {
- // return {product_id: p[0], quantity: p[1].quantity}
- // })
- // }
- // orderObj.id = await hash(
- // [this.customerPubkey, created_at, JSON.stringify(orderObj)].join(':')
- // )
+ let orderData = this.checkoutDialog.data
+ let orderObj = {
+ name: orderData?.username,
+ address: orderData.address,
+ message: orderData?.message,
+ contact: {
+ nostr: orderData.pubkey,
+ phone: null,
+ email: orderData?.email
+ },
+ items: Array.from(this.cart.products, p => {
+ return {product_id: p[0], quantity: p[1].quantity}
+ })
+ }
+ orderObj.id = await hash(
+ [orderData.pubkey, created_at, JSON.stringify(orderObj)].join(':')
+ )
+ this.downloadOrderDialog.data = orderObj
+ this.downloadOrderDialog.show = true
this.resetCheckout()
+ this.resetCart()
},
async getFromExtension() {
this.customerPubkey = await window.nostr.getPublicKey()
@@ -241,6 +260,8 @@ async function customerStall(path) {
})
relay.on('error', () => {
console.log(`failed to connect to ${relay.url}`)
+ relay.close()
+ return
})
await relay.connect()
@@ -261,17 +282,20 @@ async function customerStall(path) {
this.resetCheckout()
this.resetCart()
this.qrCodeDialog.show = true
- this.qrCodeDialog.dismissMsg = this.$q.notify({
- timeout: 0,
+ this.$q.notify({
message: 'Waiting for invoice from merchant...'
})
this.listenMessages()
},
async listenMessages() {
- console.log('LISTEN')
+ this.loading = true
try {
const pool = new NostrTools.SimplePool()
const filters = [
+ {
+ kinds: [4],
+ authors: [this.stall.pubkey]
+ },
{
kinds: [4],
'#p': [this.customerPubkey]
@@ -284,7 +308,6 @@ async function customerStall(path) {
let sender = mine
? event.tags.find(([k, v]) => k === 'p' && v && v !== '')[1]
: event.pubkey
-
try {
let plaintext
if (this.customerPrivkey) {
@@ -314,15 +337,17 @@ async function customerStall(path) {
if (!isJson(text)) return
let json = JSON.parse(text)
if (json.id != this.activeOrder) return
- if (json?.payment_options) {
- this.qrCodeDialog.data.payment_request = json.payment_options.find(
- o => o.type == 'ln'
- ).link
+ if (json.payment_options) {
+ let payment_request = json.payment_options.find(o => o.type == 'ln')
+ .link
+ if (!payment_request) return
+ this.loading = false
+ this.qrCodeDialog.data.payment_request = payment_request
this.qrCodeDialog.dismissMsg = this.$q.notify({
timeout: 0,
message: 'Waiting for payment...'
})
- } else if (json?.paid) {
+ } else if (json.paid) {
this.closeQrCodeDialog()
this.$q.notify({
type: 'positive',