diff --git a/static/components/market-config/market-config.html b/static/components/market-config/market-config.html index d335f59..309c5f7 100644 --- a/static/components/market-config/market-config.html +++ b/static/components/market-config/market-config.html @@ -117,7 +117,7 @@
- +
diff --git a/static/components/market-config/market-config.js b/static/components/market-config/market-config.js index 90fb813..c87757e 100644 --- a/static/components/market-config/market-config.js +++ b/static/components/market-config/market-config.js @@ -86,6 +86,9 @@ async function marketConfig(path) { const { name, about, ui } = this.configData console.log('### this.info', { name, about, ui }) this.$emit('ui-config-update', { name, about, ui }) + }, + publishNaddr(){ + this.$emit('publish-naddr') } }, created: async function () { diff --git a/static/js/market.js b/static/js/market.js index c185fd6..73e5074 100644 --- a/static/js/market.js +++ b/static/js/market.js @@ -263,7 +263,7 @@ const market = async () => { this.account = this.$q.localStorage.getItem('nostrmarket.account') || null - const uiConfig = this.$q.localStorage.getItem('nostrmarket.marketplace-config') || {} + const uiConfig = this.$q.localStorage.getItem('nostrmarket.marketplaceConfig') || { ui: { darkMode: false } } console.log('### uiConfig storage: ', uiConfig) // trigger the `watch` logic this.config = { ...this.config, opts: { ...this.config.opts, ...uiConfig } } @@ -354,47 +354,7 @@ const market = async () => { const { name, about, ui } = updateData this.config = { ...this.config, opts: { ...this.config.opts, name, about, ui } } this.applyUiConfigs(this.config) - this.$q.localStorage.set('nostrmarket.marketplace-config', { name, about, ui }) - - - if (!this.account?.privkey) return - - const merchants = Array.from(this.merchants.map(m => m.publicKey)) - const identifier = this.config.identifier ?? crypto.randomUUID() - const event = { - ...(await NostrTools.getBlankEvent()), - kind: 30019, - content: JSON.stringify({ name, about, ui, merchants }), - created_at: Math.floor(Date.now() / 1000), - tags: [['d', identifier]], - pubkey: this.account.pubkey - } - event.id = NostrTools.getEventHash(event) - try { - if (this.account.useExtension) { - event = await window.nostr.signEvent(event) - } else if (this.account.privkey) { - event.sig = await NostrTools.signEvent(event, this.account.privkey) - } - let pub = this.pool.publish(Array.from(this.relays), event) - pub.on('ok', () => console.debug(`Config event was sent`)) - pub.on('failed', error => console.error(error)) - } catch (err) { - console.error(err) - this.$q.notify({ - message: `Error signing event.`, - color: 'negative', - icon: 'warning' - }) - return - } - this.naddr = NostrTools.nip19.naddrEncode({ - pubkey: event.pubkey, - kind: 30019, - identifier: identifier, - relays: Array.from(this.relays) - }) - return + this.$q.localStorage.set('nostrmarket.marketplaceConfig', { name, about, ui }) }, async updateData(events) { @@ -718,7 +678,7 @@ const market = async () => { }, async placeOrder({ event, order, cartId }) { - if (!this.account.privkey) { + if (!this.account?.privkey) { this.openAccountDialog() return } @@ -961,6 +921,51 @@ const market = async () => { } } catch { } return defaultValue + }, + + async publishNaddr() { + if (!this.account?.privkey) { + this.openAccountDialog() + return + } + + + const merchants = Array.from(this.merchants.map(m => m.publicKey)) + const identifier = this.config.identifier ?? crypto.randomUUID() + const event = { + ...(await NostrTools.getBlankEvent()), + kind: 30019, + content: JSON.stringify({ name, about, ui, merchants }), + created_at: Math.floor(Date.now() / 1000), + tags: [['d', identifier]], + pubkey: this.account.pubkey + } + event.id = NostrTools.getEventHash(event) + try { + if (this.account.useExtension) { + event = await window.nostr.signEvent(event) + } else if (this.account.privkey) { + event.sig = await NostrTools.signEvent(event, this.account.privkey) + } + let pub = this.pool.publish(Array.from(this.relays), event) + pub.on('ok', () => console.debug(`Config event was sent`)) + pub.on('failed', error => console.error(error)) + } catch (err) { + console.error(err) + this.$q.notify({ + message: `Error signing event.`, + color: 'negative', + icon: 'warning' + }) + return + } + this.naddr = NostrTools.nip19.naddrEncode({ + pubkey: event.pubkey, + kind: 30019, + identifier: identifier, + relays: Array.from(this.relays) + }) + return } } diff --git a/templates/nostrmarket/market.html b/templates/nostrmarket/market.html index af3626d..d44a9f8 100644 --- a/templates/nostrmarket/market.html +++ b/templates/nostrmarket/market.html @@ -114,7 +114,7 @@
-
@@ -127,7 +127,7 @@ + :config-ui="config?.opts" @ui-config-update="updateUiConfig" @publish-naddr="publishNaddr">