refactor: extract restoreFromStorage
This commit is contained in:
parent
e6d65c0ade
commit
6c3f2b529b
1 changed files with 29 additions and 44 deletions
|
|
@ -213,57 +213,15 @@ const market = async () => {
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async created() {
|
async created() {
|
||||||
this.bannerImage = this.defaultBanner
|
this.bannerImage = this.defaultBanner
|
||||||
this.logoImage = this.defaultLogo
|
this.logoImage = this.defaultLogo
|
||||||
|
|
||||||
this.merchants = this.$q.localStorage.getItem('nostrmarket.merchants') || []
|
this.restoreFromStorage()
|
||||||
this.shoppingCarts = this.$q.localStorage.getItem('nostrmarket.shoppingCarts') || []
|
|
||||||
|
|
||||||
this.account = this.$q.localStorage.getItem('nostrmarket.account') || null
|
|
||||||
|
|
||||||
const uiConfig = this.$q.localStorage.getItem('nostrmarket.marketplace-config') || {}
|
|
||||||
// trigger the `watch` logic
|
|
||||||
this.config = { ...this.config, opts: { ...this.config.opts, ...uiConfig } }
|
|
||||||
if (this.config?.opts?.ui?.theme) {
|
|
||||||
document.body.setAttribute('data-theme', this.config.opts.ui.theme)
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('### uiConfig', uiConfig)
|
|
||||||
console.log('### this.config', this.config)
|
|
||||||
|
|
||||||
const prefix = 'nostrmarket.orders.'
|
|
||||||
const orderKeys = this.$q.localStorage.getAllKeys().filter(k => k.startsWith(prefix))
|
|
||||||
orderKeys.forEach(k => {
|
|
||||||
const pubkey = k.substring(prefix.length)
|
|
||||||
this.orders[pubkey] = this.$q.localStorage.getItem(k)
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//console.log("UUID", crypto.randomUUID())
|
|
||||||
|
|
||||||
// Check for stored merchants and relays on localStorage
|
|
||||||
try {
|
|
||||||
let merchants = this.$q.localStorage.getItem(`diagonAlley.merchants`)
|
|
||||||
let relays = this.$q.localStorage.getItem(`nostrmarket.relays`)
|
|
||||||
if (merchants && merchants.length) {
|
|
||||||
this.pubkeys = new Set(merchants)
|
|
||||||
}
|
|
||||||
if (this.account) {
|
|
||||||
this.pubkeys.add(this.account.pubkey)
|
|
||||||
}
|
|
||||||
if (relays && relays.length) {
|
|
||||||
this.relays = new Set(relays)
|
|
||||||
} else {
|
|
||||||
this.relays = new Set(defaultRelays)
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e)
|
|
||||||
}
|
|
||||||
|
|
||||||
let params = new URLSearchParams(window.location.search)
|
let params = new URLSearchParams(window.location.search)
|
||||||
let merchant_pubkey = params.get('merchant_pubkey')
|
let merchant_pubkey = params.get('merchant_pubkey')
|
||||||
let stall_id = params.get('stall_id')
|
let stall_id = params.get('stall_id')
|
||||||
|
|
@ -313,6 +271,33 @@ 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: {
|
||||||
|
restoreFromStorage() {
|
||||||
|
this.merchants = this.$q.localStorage.getItem('nostrmarket.merchants') || []
|
||||||
|
this.shoppingCarts = this.$q.localStorage.getItem('nostrmarket.shoppingCarts') || []
|
||||||
|
|
||||||
|
this.account = this.$q.localStorage.getItem('nostrmarket.account') || null
|
||||||
|
|
||||||
|
const uiConfig = this.$q.localStorage.getItem('nostrmarket.marketplace-config') || {}
|
||||||
|
// trigger the `watch` logic
|
||||||
|
this.config = { ...this.config, opts: { ...this.config.opts, ...uiConfig } }
|
||||||
|
if (this.config?.opts?.ui?.theme) {
|
||||||
|
document.body.setAttribute('data-theme', this.config.opts.ui.theme)
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('### uiConfig', uiConfig)
|
||||||
|
console.log('### this.config', this.config)
|
||||||
|
|
||||||
|
const prefix = 'nostrmarket.orders.'
|
||||||
|
const orderKeys = this.$q.localStorage.getAllKeys().filter(k => k.startsWith(prefix))
|
||||||
|
orderKeys.forEach(k => {
|
||||||
|
const pubkey = k.substring(prefix.length)
|
||||||
|
this.orders[pubkey] = this.$q.localStorage.getItem(k)
|
||||||
|
})
|
||||||
|
|
||||||
|
const relays = this.$q.localStorage.getItem('nostrmarket.relays')
|
||||||
|
this.relays = new Set(relays?.length ? relays : defaultRelays)
|
||||||
|
|
||||||
|
},
|
||||||
async deleteAccount() {
|
async deleteAccount() {
|
||||||
await LNbits.utils
|
await LNbits.utils
|
||||||
.confirmDialog(
|
.confirmDialog(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue