diff --git a/migrations.py b/migrations.py index f006d36..d6c3ffe 100644 --- a/migrations.py +++ b/migrations.py @@ -43,7 +43,7 @@ async def m001_initial(db): id TEXT PRIMARY KEY, stall_id TEXT NOT NULL, name TEXT NOT NULL, - image TEXT DEFAULT, + image TEXT, price REAL NOT NULL, quantity INTEGER NOT NULL, category_list TEXT DEFAULT '[]', diff --git a/static/components/chat-dialog/chat-dialog.html b/static/components/chat-dialog/chat-dialog.html index a428044..7eddfc0 100644 --- a/static/components/chat-dialog/chat-dialog.html +++ b/static/components/chat-dialog/chat-dialog.html @@ -8,8 +8,14 @@ > - -
Chat Box
+ + @@ -17,49 +23,64 @@ Close
- - - - - - - - - - - +
+ + + + + + + + + + +
+
+ + + +
diff --git a/static/components/chat-dialog/chat-dialog.js b/static/components/chat-dialog/chat-dialog.js index c111e27..0e0d36f 100644 --- a/static/components/chat-dialog/chat-dialog.js +++ b/static/components/chat-dialog/chat-dialog.js @@ -9,15 +9,70 @@ async function chatDialog(path) { data: function () { return { dialog: false, + isChat: true, loading: false, pool: null, nostrMessages: [], - newMessage: '' + newMessage: '', + ordersTable: { + columns: [ + { + name: 'id', + align: 'left', + label: 'ID', + field: 'id' + }, + { + name: 'created_at', + align: 'left', + label: 'Created/Updated', + field: 'created_at', + sortable: true + }, + { + name: 'paid', + align: 'left', + label: 'Paid', + field: 'paid', + sortable: true + }, + { + name: 'shipped', + align: 'left', + label: 'Shipped', + field: 'shipped', + sortable: true + }, + { + name: 'invoice', + align: 'left', + label: 'Invoice', + field: row => + row.payment_options && + row.payment_options.find(p => p.type == 'ln').link + } + ], + pagination: { + rowsPerPage: 10 + } + } } }, computed: { sortedMessages() { - return this.nostrMessages.sort((a, b) => b.timestamp - a.timestamp) + return this.nostrMessages.sort((a, b) => b.created_at - a.created_at) + }, + ordersList() { + let orders = this.nostrMessages + .sort((a, b) => b.created_at - a.created_at) + .filter(o => isJson(o.msg)) + .reduce((acc, cur) => { + const obj = JSON.parse(cur.msg) + const key = obj.id + const curGroup = acc[key] ?? {created_at: cur.timestamp} + return {...acc, [key]: {...curGroup, ...obj}} + }, {}) + return Object.values(orders) } }, methods: { @@ -49,9 +104,7 @@ async function chatDialog(path) { }) sub.on('event', async event => { let mine = event.pubkey == this.account.pubkey - let sender = mine - ? event.tags.find(([k, v]) => k === 'p' && v && v !== '')[1] - : event.pubkey + let sender = mine ? this.merchant : event.pubkey try { let plaintext @@ -67,19 +120,19 @@ async function chatDialog(path) { event.content ) } - messagesMap.set(event.id, { - msg: plaintext, - timestamp: timeFromNow(event.created_at * 1000), - sender: `${mine ? 'Me' : 'Merchant'}` - }) + if (plaintext) { + 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 d6afaba..2afd57a 100644 --- a/static/components/customer-stall/customer-stall.html +++ b/static/components/customer-stall/customer-stall.html @@ -15,7 +15,7 @@ @@ -80,13 +80,17 @@
  • 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 - Nostr client + generate a key pair to make the order (you should backup up + your keys) +
  • +
  • + fill out the required fields and with your public key, + download the order and send as a direct message to the + merchant on any Nostr client
  • - + Use a Nostr browser extension Download the order and send manuallyGenerate a new key pair
    @@ -123,7 +126,8 @@ :type="isPwd ? 'password' : 'text'" v-if="!customerUseExtension" v-model.trim="checkoutDialog.data.privkey" - hint="Enter your private key or see bellow for instructions" + label="Private key *optional" + hint="Enter your private key" >