fet: ui bla

This commit is contained in:
Vlad Stan 2023-07-18 12:29:58 +03:00
parent 81bb93c7b4
commit 04d087c65d
4 changed files with 54 additions and 46 deletions

View file

@ -117,7 +117,7 @@
<q-separator /> <q-separator />
<q-card-section> <q-card-section>
<div class="float-right"> <div class="float-right">
<q-btn flat label="Publish Update" class="q-ml-lg" color="primary"></q-btn> <q-btn @click="publishNaddr" flat label="Publish Naddr" icon="share" class="q-ml-lg" color="primary"></q-btn>
</div> </div>
</q-card-section> </q-card-section>
<q-card-section></q-card-section> <q-card-section></q-card-section>

View file

@ -86,6 +86,9 @@ async function marketConfig(path) {
const { name, about, ui } = this.configData const { name, about, ui } = this.configData
console.log('### this.info', { name, about, ui }) console.log('### this.info', { name, about, ui })
this.$emit('ui-config-update', { name, about, ui }) this.$emit('ui-config-update', { name, about, ui })
},
publishNaddr(){
this.$emit('publish-naddr')
} }
}, },
created: async function () { created: async function () {

View file

@ -263,7 +263,7 @@ const market = async () => {
this.account = this.$q.localStorage.getItem('nostrmarket.account') || null 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) console.log('### uiConfig storage: ', uiConfig)
// trigger the `watch` logic // trigger the `watch` logic
this.config = { ...this.config, opts: { ...this.config.opts, ...uiConfig } } this.config = { ...this.config, opts: { ...this.config.opts, ...uiConfig } }
@ -354,47 +354,7 @@ const market = async () => {
const { name, about, ui } = updateData const { name, about, ui } = updateData
this.config = { ...this.config, opts: { ...this.config.opts, name, about, ui } } this.config = { ...this.config, opts: { ...this.config.opts, name, about, ui } }
this.applyUiConfigs(this.config) this.applyUiConfigs(this.config)
this.$q.localStorage.set('nostrmarket.marketplace-config', { name, about, ui }) this.$q.localStorage.set('nostrmarket.marketplaceConfig', { 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
}, },
async updateData(events) { async updateData(events) {
@ -718,7 +678,7 @@ const market = async () => {
}, },
async placeOrder({ event, order, cartId }) { async placeOrder({ event, order, cartId }) {
if (!this.account.privkey) { if (!this.account?.privkey) {
this.openAccountDialog() this.openAccountDialog()
return return
} }
@ -961,6 +921,51 @@ const market = async () => {
} }
} catch { } } catch { }
return defaultValue 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
} }
} }

View file

@ -114,7 +114,7 @@
<div class="col-lg-1 col-md-1 col-sm-0 auto-width"> <div class="col-lg-1 col-md-1 col-sm-0 auto-width">
<q-btn v-if="activePage === 'customer-stall'" flat color="grey" icon="content_copy" @click="copyUrl()" <q-btn v-if="activePage === 'customer-stall'" flat color="grey" icon="content_copy" @click="copyUrl()"
class="float-right"></q-btn> class="float-right"></q-btn>
<q-btn v-if="activePage === 'market-config'" flat color="primary" label="Naddr" icon="share" @click="copyUrl()" <q-btn v-if="activePage === 'market-config'" flat color="primary" label="Naddr" icon="share" @click="publishNaddr"
class="float-right"></q-btn> class="float-right"></q-btn>
</div> </div>
<div class="col-lg-2 col-md-1 col-sm-0 auto-width"></div> <div class="col-lg-2 col-md-1 col-sm-0 auto-width"></div>
@ -127,7 +127,7 @@
<market-config v-if="activePage === 'market-config'" :merchants="merchants" @add-merchant="addMerchant" <market-config v-if="activePage === 'market-config'" :merchants="merchants" @add-merchant="addMerchant"
@remove-merchant="removeMerchant" :relays="relays" @add-relay="addRelay" @remove-relay="removeRelay" @remove-merchant="removeMerchant" :relays="relays" @add-relay="addRelay" @remove-relay="removeRelay"
:config-ui="config?.opts" @ui-config-update="updateUiConfig"></market-config> :config-ui="config?.opts" @ui-config-update="updateUiConfig" @publish-naddr="publishNaddr"></market-config>
<user-config v-else-if="activePage === 'user-config'"></user-config> <user-config v-else-if="activePage === 'user-config'"></user-config>