feat: basic merchant fixes

This commit is contained in:
Vlad Stan 2023-07-06 12:04:46 +03:00
parent 6cf354ad39
commit 8061894057
4 changed files with 87 additions and 51 deletions

View file

@ -10,28 +10,30 @@
<q-tab-panels v-model="tab">
<q-tab-panel name="merchants">
<div>
<q-input outlined v-model="inputPubkey" @keydown.enter="addPubkey(null)" type="text" label="Pubkey/Npub"
<q-input outlined v-model="inputPubkey" @keydown.enter="addMerchant" type="text" label="Pubkey/Npub"
hint="Add merchants">
<q-btn @click="addPubkey(null)" dense flat icon="add"></q-btn>
<q-btn @click="addMerchant" dense flat icon="add"></q-btn>
</q-input>
<q-list class="q-mt-md">
<q-item v-for="pub in Array.from(pubkeys)" :key="pub">
<q-item v-for="{publicKey, profile} in merchants" :key="publicKey">
<q-item-section avatar>
<q-avatar>
<img v-if="profiles.get(pub) && profiles.get(pub)?.picture" :src="profiles.get(pub).picture" />
<img v-if="profile?.picture" :src="profile.picture" />
<img v-else src="/nostrmarket/static/images/blank-avatar.webp" />
</q-avatar>
</q-item-section>
<q-item-section>
<q-item-label v-if="profiles.get(pub) && profiles.get(pub)?.name">{{ profiles.get(pub).name
}}</q-item-label>
<q-item-label v-else>{{ `${pub.slice(0, 5)}...${pub.slice(-5)}`
}}</q-item-label>
<q-tooltip>{{ pub }}</q-tooltip>
<q-item-section class="q-mt-sm">
<q-item-label><strong>{{ profile?.name}}</strong></q-item-label>
<q-item-label>
<div class="text-caption text-grey ellipsis-2-lines">
<p>{{ publicKey }}</p>
</div>
</q-item-label>
<q-tooltip>{{ publicKey }}</q-tooltip>
</q-item-section>
<q-item-section side>
<q-btn class="gt-xs" size="12px" flat dense round icon="delete" @click="removePubkey(pub)" />
<q-btn class="gt-xs" size="12px" flat dense round icon="delete" @click="removeMerchant(publicKey)" />
</q-item-section>
</q-item>

View file

@ -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 () {