From 80618940573a7b8a281fcf0fac10a9e652c9093e Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Thu, 6 Jul 2023 12:04:46 +0300 Subject: [PATCH] feat: basic merchant fixes --- .../market-config/market-config.html | 24 +++--- .../components/market-config/market-config.js | 82 ++++++++++--------- static/js/market.js | 29 ++++++- templates/nostrmarket/market.html | 3 +- 4 files changed, 87 insertions(+), 51 deletions(-) diff --git a/static/components/market-config/market-config.html b/static/components/market-config/market-config.html index 76f5e0b..3ac87fc 100644 --- a/static/components/market-config/market-config.html +++ b/static/components/market-config/market-config.html @@ -10,28 +10,30 @@
- - + - + - + - - {{ profiles.get(pub).name - }} - {{ `${pub.slice(0, 5)}...${pub.slice(-5)}` - }} - {{ pub }} + + {{ profile?.name}} + +
+

{{ publicKey }}

+
+
+ {{ publicKey }}
- +
diff --git a/static/components/market-config/market-config.js b/static/components/market-config/market-config.js index aa2bf7b..7a5d2fc 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: ['adminkey',], + props: ['merchants',], template, data: function () { @@ -14,45 +14,53 @@ async function marketConfig(path) { } }, methods: { - async addPubkey(pubkey) { - if (!pubkey) { - pubkey = String(this.inputPubkey).trim() - } - let regExp = /^#([0-9a-f]{3}){1,2}$/i - if (pubkey.startsWith('n')) { - try { - let { type, data } = NostrTools.nip19.decode(pubkey) - if (type === 'npub') pubkey = data - else if (type === 'nprofile') { - pubkey = data.pubkey - givenRelays = data.relays - } - } catch (err) { - console.error(err) - } - } else if (regExp.test(pubkey)) { - pubkey = pubkey - } - this.pubkeys.add(pubkey) + addMerchant: async function() { + console.log('### market config', this.merchants) + this.$emit('add-merchant', this.inputPubkey) this.inputPubkey = null - this.$q.localStorage.set( - `diagonAlley.merchants`, - Array.from(this.pubkeys) - ) - // this.initNostr()// todo: emit }, - removePubkey(pubkey) { - // Needs a hack for Vue reactivity - let pubkeys = this.pubkeys - pubkeys.delete(pubkey) - this.profiles.delete(pubkey) - this.pubkeys = new Set(Array.from(pubkeys)) - this.$q.localStorage.set( - `diagonAlley.merchants`, - Array.from(this.pubkeys) - ) - // this.initNostr() // todo: emit + removeMerchant: async function(publicKey) { + this.$emit('remove-merchant', publicKey) }, + // async addPubkey(pubkey) { + // if (!pubkey) { + // pubkey = String(this.inputPubkey).trim() + // } + // let regExp = /^#([0-9a-f]{3}){1,2}$/i + // if (pubkey.startsWith('n')) { + // try { + // let { type, data } = NostrTools.nip19.decode(pubkey) + // if (type === 'npub') pubkey = data + // else if (type === 'nprofile') { + // pubkey = data.pubkey + // givenRelays = data.relays + // } + // } catch (err) { + // console.error(err) + // } + // } else if (regExp.test(pubkey)) { + // pubkey = pubkey + // } + // this.pubkeys.add(pubkey) + // this.inputPubkey = null + // this.$q.localStorage.set( + // `diagonAlley.merchants`, + // Array.from(this.pubkeys) + // ) + // // this.initNostr()// todo: emit + // }, + // removePubkey(pubkey) { + // // Needs a hack for Vue reactivity + // let pubkeys = this.pubkeys + // pubkeys.delete(pubkey) + // this.profiles.delete(pubkey) + // this.pubkeys = new Set(Array.from(pubkeys)) + // this.$q.localStorage.set( + // `diagonAlley.merchants`, + // Array.from(this.pubkeys) + // ) + // // this.initNostr() // todo: emit + // }, }, created: async function () { diff --git a/static/js/market.js b/static/js/market.js index 8f6eaa0..a4996ce 100644 --- a/static/js/market.js +++ b/static/js/market.js @@ -48,6 +48,9 @@ const market = async () => { key: null } }, + + merchants: [], + showMarketConfig: false, searchNostr: false, drawer: true, @@ -317,6 +320,7 @@ const market = async () => { } }, async updateData(events) { + console.log('### updateData', events) if (events.length < 1) { this.$q.notify({ message: 'No matches were found!' @@ -335,6 +339,9 @@ const market = async () => { if (e.pubkey == this.account?.pubkey) { this.accountMetadata = this.profiles.get(this.account.pubkey) } + this.merchants.filter(m => m.publicKey === e.pubkey).forEach(m => m.profile = e.content) + this.merchants = this.merchants.concat([]) + console.log('### this.merchants', this.merchants) return } else if (e.kind == 30018) { //it's a product `d` is the prod. id @@ -390,15 +397,18 @@ const market = async () => { let relays = Array.from(this.relays) + const authors = Array.from(this.pubkeys).concat(this.merchants.map(m => m.publicKey)) + console.log('### stupid', authors) // Get metadata and market data from the pubkeys await pool .list(relays, [ { kinds: [0, 30017, 30018], // for production kind is 30017 - authors: Array.from(this.pubkeys) + authors } ]) .then(async events => { + console.log('### stupid response', events) if (!events || events.length == 0) return await this.updateData(events) }) @@ -409,10 +419,12 @@ const market = async () => { return }, async poolSubscribe() { + const authors = Array.from(this.pubkeys).concat(this.merchants.map(m => m.publicKey)) + console.log('### poolSubscribe.authors', authors) this.poolSub = this.pool.sub(Array.from(this.relays), [ { kinds: [0, 30017, 30018], - authors: Array.from(this.pubkeys), + authors, since: Date.now() / 1000 } ]) @@ -525,6 +537,19 @@ const market = async () => { this.relays = new Set(Array.from(relays)) this.$q.localStorage.set(`diagonAlley.relays`, Array.from(this.relays)) this.initNostr() + }, + addMerchant(publicKey){ + console.log('### addMerchat', publicKey) + this.merchants.unshift({ + publicKey, + profile: null + }) + this.initNostr() // todo: improve + }, + removeMerchant(publicKey){ + console.log('### removeMerchat', publicKey) + this.merchants = this.merchants.filter(m => m.publicKey !== publicKey) + this.initNostr() // todo: improve } } }) diff --git a/templates/nostrmarket/market.html b/templates/nostrmarket/market.html index de0cb20..d3a9c6d 100644 --- a/templates/nostrmarket/market.html +++ b/templates/nostrmarket/market.html @@ -203,7 +203,8 @@ - +