diff --git a/static/components/market-config/market-config.html b/static/components/market-config/market-config.html index 38b6235..1579cd5 100644 --- a/static/components/market-config/market-config.html +++ b/static/components/market-config/market-config.html @@ -11,7 +11,7 @@
- @@ -43,24 +43,53 @@
- Relays +
+ + + + + + + + + + + {{ relay}} + + + + + + + + + +
Information
- + -
UI Configurations
- + - + - + diff --git a/static/components/market-config/market-config.js b/static/components/market-config/market-config.js index b81c400..6255fed 100644 --- a/static/components/market-config/market-config.js +++ b/static/components/market-config/market-config.js @@ -2,7 +2,7 @@ async function marketConfig(path) { const template = await loadTemplateAsync(path) Vue.component('market-config', { name: 'market-config', - props: ['merchants',], + props: ['merchants', 'relays'], template, data: function () { @@ -10,25 +10,63 @@ async function marketConfig(path) { tab: 'merchants', pubkeys: new Set(), profiles: new Map(), - inputPubkey: null, + merchantPubkey: null, + relayUrl: null, + info: { + name: null, + description: null, + theme: null, + logo: null, + banner: null + } } }, methods: { addMerchant: async function () { - if (!isValidKey(this.inputPubkey, 'npub')) { + if (!isValidKey(this.merchantPubkey, 'npub')) { this.$q.notify({ message: 'Invalid Public Key!', type: 'warning' }) return } - const publicKey = isValidKeyHex(this.inputPubkey) ? this.inputPubkey : NostrTools.nip19.decode(this.inputPubkey).data + const publicKey = isValidKeyHex(this.merchantPubkey) ? this.merchantPubkey : NostrTools.nip19.decode(this.merchantPubkey).data this.$emit('add-merchant', publicKey) - this.inputPubkey = null + this.merchantPubkey = null }, removeMerchant: async function (publicKey) { this.$emit('remove-merchant', publicKey) }, + addRelay: async function () { + const relayUrl = (this.relayUrl || '').trim() + if (!relayUrl.startsWith('wss://') && !relayUrl.startsWith('ws://')) { + this.relayUrl = null + this.$q.notify({ + timeout: 5000, + type: 'warning', + message: `Invalid relay URL.`, + caption: "Should start with 'wss://'' or 'ws://'" + }) + return + } + try { + new URL(relayUrl); + this.$emit('add-relay', relayUrl) + } catch (error) { + this.$q.notify({ + timeout: 5000, + type: 'warning', + message: `Invalid relay URL.`, + caption: `Error: ${error}` + }) + } + + + this.relayUrl = null + }, + removeRelay: async function (relay) { + this.$emit('remove-relay', relay) + }, }, created: async function () { diff --git a/static/js/market.js b/static/js/market.js index fd3e0d1..3efd8e0 100644 --- a/static/js/market.js +++ b/static/js/market.js @@ -213,7 +213,7 @@ const market = async () => { // Check for stored merchants and relays on localStorage try { let merchants = this.$q.localStorage.getItem(`diagonAlley.merchants`) - let relays = this.$q.localStorage.getItem(`diagonAlley.relays`) + let relays = this.$q.localStorage.getItem(`nostrmarket.relays`) if (merchants && merchants.length) { this.pubkeys = new Set(merchants) } @@ -604,29 +604,25 @@ const market = async () => { ) this.initNostr() }, - async addRelay() { - let relay = String(this.inputRelay).trim() - if (!relay.startsWith('ws')) { - console.debug('invalid url') - return - } - this.relays.add(relay) - this.$q.localStorage.set(`diagonAlley.relays`, Array.from(this.relays)) - this.inputRelay = null - this.initNostr() - }, - removeRelay(relay) { - // Needs a hack for Vue reactivity - let relays = this.relays - relays.delete(relay) - this.relays = new Set(Array.from(relays)) - this.$q.localStorage.set(`diagonAlley.relays`, Array.from(this.relays)) - this.initNostr() - }, setActivePage(page = 'market') { this.activePage = page }, + async addRelay(relayUrl) { + let relay = String(relayUrl).trim() + + this.relays.add(relay) + this.$q.localStorage.set(`nostrmarket.relays`, Array.from(this.relays)) + this.initNostr() // todo: improve + }, + removeRelay(relayUrl) { + this.relays.delete(relayUrl) + this.relays = new Set(Array.from(this.relays)) + this.$q.localStorage.set(`nostrmarket.relays`, Array.from(this.relays)) + this.initNostr() // todo: improve + }, + + addMerchant(publicKey) { console.log('### addMerchat', publicKey) diff --git a/templates/nostrmarket/market.html b/templates/nostrmarket/market.html index 08cde74..8c7c17d 100644 --- a/templates/nostrmarket/market.html +++ b/templates/nostrmarket/market.html @@ -265,7 +265,8 @@ + @remove-merchant="removeMerchant" :relays="relays" @add-relay="addRelay" + @remove-relay="removeRelay">