refactor: param parsnig

This commit is contained in:
Vlad Stan 2023-07-18 10:34:05 +03:00
parent b9ca9e325a
commit edb9fffdc3

View file

@ -218,34 +218,12 @@ const market = async () => {
this.restoreFromStorage() this.restoreFromStorage()
const params = new URLSearchParams(window.location.search)
let params = new URLSearchParams(window.location.search)
let merchant_pubkey = params.get('merchant_pubkey')
let stall_id = params.get('stall_id')
let product_id = params.get('product_id')
await this.checkMarketplaceNaddr(params.get('naddr')) await this.checkMarketplaceNaddr(params.get('naddr'))
await this.handleQueryParams(params)
// What component to render on start
if (stall_id) {
if (product_id) {
this.activeProduct = product_id
}
this.activeStall = stall_id
}
if (merchant_pubkey && !this.pubkeys.has(merchant_pubkey)) {
await LNbits.utils
.confirmDialog(
`We found a merchant pubkey in your request. Do you want to add it to the merchants list?`
)
.onOk(async () => {
await this.addPubkey(merchant_pubkey)
})
}
// Get notes from Nostr // Get notes from Nostr
await this.initNostr() await this.initNostr()
@ -255,6 +233,29 @@ const market = async () => {
await this.listenForIncommingDms(this.merchants.map(m => ({ publicKey: m.publicKey, since: this.lastDmForPubkey(m.publicKey) }))) await this.listenForIncommingDms(this.merchants.map(m => ({ publicKey: m.publicKey, since: this.lastDmForPubkey(m.publicKey) })))
}, },
methods: { methods: {
async handleQueryParams(params) {
const merchantPubkey = params.get('merchant_pubkey')
const stallId = params.get('stall_id')
const productId = params.get('product_id')
// What component to render on start
if (stallId) {
if (productId) {
this.activeProduct = productId
}
this.activeStall = stallId
}
if (merchantPubkey && !(this.merchants.find(m => m.publicKey === merchantPubkey))) {
await LNbits.utils
.confirmDialog(
`We found a merchant pubkey in your request. Do you want to add it to the merchants list?`
)
.onOk(async () => {
await this.merchants.push({ publicKey: merchantPubkey, profile: null })
})
}
},
restoreFromStorage() { restoreFromStorage() {
this.merchants = this.$q.localStorage.getItem('nostrmarket.merchants') || [] this.merchants = this.$q.localStorage.getItem('nostrmarket.merchants') || []
this.shoppingCarts = this.$q.localStorage.getItem('nostrmarket.shoppingCarts') || [] this.shoppingCarts = this.$q.localStorage.getItem('nostrmarket.shoppingCarts') || []