From 6d921d7559fff548894165f55207f296b9d1b939 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Tue, 11 Jul 2023 18:08:32 +0300 Subject: [PATCH] feat: UI improvements --- .../customer-orders/customer-orders.html | 35 ++++++---- .../customer-orders/customer-orders.js | 64 +++++++++++++++---- .../shopping-cart-checkout.html | 4 +- static/js/market.js | 22 +++++-- templates/nostrmarket/market.html | 2 +- 5 files changed, 95 insertions(+), 32 deletions(-) diff --git a/static/components/customer-orders/customer-orders.html b/static/components/customer-orders/customer-orders.html index 285dbc6..eb87462 100644 --- a/static/components/customer-orders/customer-orders.html +++ b/static/components/customer-orders/customer-orders.html @@ -6,8 +6,6 @@
- - @@ -20,13 +18,10 @@ - - Todo: merchant name + - By - @@ -40,30 +35,44 @@
- + - xxxx + diff --git a/static/components/customer-orders/customer-orders.js b/static/components/customer-orders/customer-orders.js index 788d828..9484622 100644 --- a/static/components/customer-orders/customer-orders.js +++ b/static/components/customer-orders/customer-orders.js @@ -5,32 +5,74 @@ async function customerOrders(path) { name: 'orders', template, - props: ['orders', 'products', 'stalls'], + props: ['orders', 'products', 'stalls', 'merchants'], data: function () { return {} }, computed: { merchantOrders: function () { - return Object.keys(this.orders).map(pubkey => ({ pubkey, orders: this.orders[pubkey] })) + return Object.keys(this.orders).map(pubkey => ({ pubkey, orders: this.orders[pubkey].map(this.enrichOrder) })) } }, methods: { + enrichOrder: function (order) { + return { + ...order, + stallName: this.stallNameForOrder(order), + invoice: this.invoiceForOrder(order) + } + }, stallNameForOrder: function (order) { - console.log('### stallNameForOrder', order) - const productId = order.items[0]?.product_id - if (!productId) return 'Stall Name' - const product = this.products.find(p => p.id === productId) - if (!product) return 'Stall Name' - const stall = this.stalls.find(s => s.id === product.stall_id) - if (!stall) return 'Stall Name' - return stall.name - } + try { + console.log('### stallNameForOrder', order) + const productId = order.items[0]?.product_id + if (!productId) return 'Stall Name' + const product = this.products.find(p => p.id === productId) + if (!product) return 'Stall Name' + const stall = this.stalls.find(s => s.id === product.stall_id) + if (!stall) return 'Stall Name' + return stall.name + } catch (error) { + return 'Stall Name' + } + }, + invoiceForOrder: function (order) { + try { + const lnPaymentOption = order?.payment_options?.find(p => p.type === 'ln') + if (!lnPaymentOption?.link) return + return decode(lnPaymentOption.link) + } catch (error) { + console.warn(error) + } + }, + + merchantProfile: function (pubkey) { + const merchant = this.merchants.find(m => m.publicKey === pubkey) + return merchant?.profile + }, + + showInvoice: function (order) { + if (order.paid) return + const invoice = order?.payment_options?.find(p => p.type === 'ln').link + if (!invoice) return + this.$emit('show-invoice', invoice) + }, + + formatCurrency: function (value, unit) { + return formatCurrency(value, unit) + }, + + fromNow: function (date) { + if (!date) return '' + return moment(date * 1000).fromNow() + } }, created() { console.log('### orders', this.orders) console.log('### products', this.products) console.log('### stall', this.stalls) + console.log('### merchants', this.merchants) } }) } diff --git a/static/components/shopping-cart-checkout/shopping-cart-checkout.html b/static/components/shopping-cart-checkout/shopping-cart-checkout.html index 5f01a2c..65619ac 100644 --- a/static/components/shopping-cart-checkout/shopping-cart-checkout.html +++ b/static/components/shopping-cart-checkout/shopping-cart-checkout.html @@ -118,7 +118,9 @@
- + + Back + Place Order diff --git a/static/js/market.js b/static/js/market.js index 4bc39c9..0cc81ea 100644 --- a/static/js/market.js +++ b/static/js/market.js @@ -695,7 +695,7 @@ const market = async () => { event.sig = await NostrTools.signEvent(event, this.account.privkey) this.sendOrderEvent(event) - this.persistOrderUpdate(this.checkoutStall.pubkey, order) + this.persistOrderUpdate(this.checkoutStall.pubkey, event.created_at, order) }, sendOrderEvent(event) { @@ -768,10 +768,10 @@ const market = async () => { const jsonData = JSON.parse(plainText) if (jsonData.type === 1) { this.handlePaymentRequest(jsonData) - this.persistOrderUpdate(event.pubkey, jsonData) + this.persistOrderUpdate(event.pubkey, event.created_at, jsonData) } else if (jsonData.type === 2) { this.handleOrderStatusUpdate(jsonData) - this.persistOrderUpdate(event.pubkey, jsonData) + this.persistOrderUpdate(event.pubkey, event.created_at, jsonData) } } catch (e) { console.warn('Unable to handle incomming DM', e) @@ -829,12 +829,11 @@ const market = async () => { return dms.lastCreatedAt }, - persistOrderUpdate(pubkey, orderUpdate) { - console.log('### persistOrderUpdate', pubkey, orderUpdate) + persistOrderUpdate(pubkey, createdAt, orderUpdate) { let orders = this.$q.localStorage.getItem(`nostrmarket.orders.${pubkey}`) || [] let order = orders.find(o => o.id === orderUpdate.id) if (!order) { - orders.unshift({ ...orderUpdate, messages: orderUpdate.message ? [orderUpdate.message] : [] }) + orders.unshift({ ...orderUpdate, createdAt, messages: orderUpdate.message ? [orderUpdate.message] : [] }) this.orders[pubkey] = orders this.$q.localStorage.set(`nostrmarket.orders.${pubkey}`, orders) return @@ -855,6 +854,17 @@ const market = async () => { orders = [order].concat(orders.filter(o => o.id !== order.id)) this.orders[pubkey] = orders this.$q.localStorage.set(`nostrmarket.orders.${pubkey}`, orders) + }, + + showInvoiceQr(invoice){ + if (!invoice) return + this.qrCodeDialog = { + data: { + payment_request: invoice + }, + dismissMsg: null, + show: true + } } } diff --git a/templates/nostrmarket/market.html b/templates/nostrmarket/market.html index 96d0593..f8308c6 100644 --- a/templates/nostrmarket/market.html +++ b/templates/nostrmarket/market.html @@ -219,7 +219,7 @@ :stall="checkoutStall" :customer-pubkey="account?.pubkey" @login-required="openAccountDialog" @place-order="placeOrder"> + :stalls="stalls" :merchants="merchants" @show-invoice="showInvoiceQr">