fetch profiles
This commit is contained in:
parent
5b1f83d6f8
commit
f9f8b65843
1 changed files with 66 additions and 38 deletions
|
|
@ -24,20 +24,31 @@
|
||||||
>
|
>
|
||||||
<q-btn @click="addPubkey" dense flat icon="add"></q-btn>
|
<q-btn @click="addPubkey" dense flat icon="add"></q-btn>
|
||||||
</q-input>
|
</q-input>
|
||||||
<q-list dense class="q-mt-md">
|
<q-list class="q-mt-md">
|
||||||
<q-item v-for="pub in Array.from(pubkeys)" :key="pub">
|
<q-item v-for="pub in Array.from(pubkeys)" :key="pub">
|
||||||
|
{%raw%}
|
||||||
<q-item-section avatar>
|
<q-item-section avatar>
|
||||||
<q-avatar>
|
<q-avatar>
|
||||||
<img src="https://cdn.quasar.dev/img/boy-avatar.png" />
|
<img
|
||||||
|
v-if="profiles.get(pub) && profiles.get(pub).picture"
|
||||||
|
:src="profiles.get(pub).picture"
|
||||||
|
/>
|
||||||
|
<img
|
||||||
|
v-else
|
||||||
|
src="/nostrmarket/static/images/blank-avatar.webp"
|
||||||
|
/>
|
||||||
</q-avatar>
|
</q-avatar>
|
||||||
</q-item-section>
|
</q-item-section>
|
||||||
{%raw%}
|
|
||||||
<q-item-section>
|
<q-item-section>
|
||||||
<q-item-label
|
<q-item-label
|
||||||
>{{ `${pub.slice(0, 5)}...${pub.slice(-5)}` }}<q-tooltip
|
v-if="profiles.get(pub) && profiles.get(pub).name"
|
||||||
>{{ pub }}</q-tooltip
|
>{{ profiles.get(pub).name }}</q-item-label
|
||||||
></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>
|
</q-item-section>
|
||||||
<q-item-section side>
|
<q-item-section side>
|
||||||
<q-btn
|
<q-btn
|
||||||
|
|
@ -135,7 +146,7 @@
|
||||||
<q-card class="card--product">
|
<q-card class="card--product">
|
||||||
{% raw %}
|
{% raw %}
|
||||||
<q-img
|
<q-img
|
||||||
:src="item.image ? item.image : '/market/static/images/placeholder.png'"
|
:src="item.image ? item.image : '/nostrmarket/static/images/placeholder.png'"
|
||||||
alt="Product Image"
|
alt="Product Image"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
spinner-color="white"
|
spinner-color="white"
|
||||||
|
|
@ -252,9 +263,10 @@
|
||||||
drawer: false,
|
drawer: false,
|
||||||
pubkeys: new Set(),
|
pubkeys: new Set(),
|
||||||
relays: new Set(),
|
relays: new Set(),
|
||||||
stalls: [],
|
|
||||||
products: [],
|
|
||||||
events: [],
|
events: [],
|
||||||
|
stalls: new Map(),
|
||||||
|
products: [],
|
||||||
|
profiles: new Map(),
|
||||||
searchText: null,
|
searchText: null,
|
||||||
exchangeRates: null,
|
exchangeRates: null,
|
||||||
inputPubkey: null,
|
inputPubkey: null,
|
||||||
|
|
@ -271,44 +283,55 @@
|
||||||
p.categories.includes(this.searchText)
|
p.categories.includes(this.searchText)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
},
|
|
||||||
relayList() {
|
|
||||||
return Array.from(this.relays)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async created() {
|
async created() {
|
||||||
// Hardcode pubkey for testing
|
// Hardcode pubkeys for testing
|
||||||
this.pubkeys.add(
|
this.pubkeys.add(
|
||||||
'855ea22a88d7df7ccd8497777db81f115575d5362f51df3af02ead383f5eaba2'
|
'855ea22a88d7df7ccd8497777db81f115575d5362f51df3af02ead383f5eaba2'
|
||||||
)
|
)
|
||||||
|
this.pubkeys.add(
|
||||||
|
'8f69ac99b96f7c4ad58b98cc38fe5d35ce02daefae7d1609c797ce3b4f92f5fd'
|
||||||
|
)
|
||||||
|
this.$q.loading.show()
|
||||||
this.relays = new Set(defaultRelays)
|
this.relays = new Set(defaultRelays)
|
||||||
await this.initNostr()
|
await this.initNostr()
|
||||||
|
this.$q.loading.hide()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async initNostr() {
|
async initNostr() {
|
||||||
this.pool = new nostr.SimplePool()
|
const pool = new nostr.SimplePool()
|
||||||
let sub = await this.pool
|
let relays = Array.from(this.relays)
|
||||||
.list(Array.from(this.relays), [
|
let products = new Map()
|
||||||
|
let stalls = new Map()
|
||||||
|
// Get metadata and market data from the pubkeys
|
||||||
|
let sub = await pool
|
||||||
|
.list(relays, [
|
||||||
{
|
{
|
||||||
kinds: [30005],
|
kinds: [0, 30005],
|
||||||
authors: Array.from(this.pubkeys)
|
authors: Array.from(this.pubkeys)
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
.then(events => {
|
.then(events => {
|
||||||
this.events = events || []
|
this.events = events || []
|
||||||
this.events.map(eventToObj).map(e => {
|
this.events.map(eventToObj).map(e => {
|
||||||
if (e.content.stall) {
|
if (e.kind == 0) {
|
||||||
//it's a product
|
this.profiles.set(e.pubkey, e.content)
|
||||||
this.products.push(e.content)
|
return
|
||||||
|
} else if (e.content.stall) {
|
||||||
|
//it's a product `d` is the prod. id
|
||||||
|
products.set(e.d, e.content)
|
||||||
} else {
|
} else {
|
||||||
// it's a stall
|
// it's a stall `d` is the stall id
|
||||||
this.stalls.push(e.content)
|
stalls.set(e.d, e.content)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
await Promise.resolve(sub)
|
await Promise.resolve(sub)
|
||||||
this.pool.close()
|
this.products = Array.from(products.values())
|
||||||
|
this.stalls = Array.from(stalls.values())
|
||||||
|
pool.close(relays)
|
||||||
},
|
},
|
||||||
async getRates() {
|
async getRates() {
|
||||||
let noFiat = this.stalls.map(s => s.currency).every(c => c == 'sat')
|
let noFiat = this.stalls.map(s => s.currency).every(c => c == 'sat')
|
||||||
|
|
@ -329,32 +352,36 @@
|
||||||
getAmountFormated(amount, unit = 'USD') {
|
getAmountFormated(amount, unit = 'USD') {
|
||||||
return LNbits.utils.formatCurrency(amount, unit)
|
return LNbits.utils.formatCurrency(amount, unit)
|
||||||
},
|
},
|
||||||
addPubkey() {
|
async addPubkey() {
|
||||||
let pubkey = String(this.inputPubkey).trim()
|
let pubkey = String(this.inputPubkey).trim()
|
||||||
let regExp = /^#([0-9a-f]{3}){1,2}$/i
|
let regExp = /^#([0-9a-f]{3}){1,2}$/i
|
||||||
if (regExp.test(pubkey)) {
|
if (pubkey.startsWith('n')) {
|
||||||
return this.pubkeys.add(pubkey)
|
try {
|
||||||
}
|
let {type, data} = nostr.nip19.decode(pubkey)
|
||||||
try {
|
if (type === 'npub') pubkey = data
|
||||||
let {type, data} = nostr.nip19.decode(pubkey)
|
else if (type === 'nprofile') {
|
||||||
if (type === 'npub') pubkey = data
|
pubkey = data.pubkey
|
||||||
else if (type === 'nprofile') {
|
givenRelays = data.relays
|
||||||
pubkey = data.pubkey
|
}
|
||||||
givenRelays = data.relays
|
this.pubkeys.add(pubkey)
|
||||||
|
this.inputPubkey = null
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err)
|
||||||
}
|
}
|
||||||
this.pubkeys.add(pubkey)
|
} else if (regExp.test(pubkey)) {
|
||||||
this.inputPubkey = null
|
pubkey = pubkey
|
||||||
} catch (err) {
|
|
||||||
console.error(err)
|
|
||||||
}
|
}
|
||||||
|
this.pubkeys.add(pubkey)
|
||||||
|
await this.initNostr()
|
||||||
},
|
},
|
||||||
removePubkey(pubkey) {
|
removePubkey(pubkey) {
|
||||||
// Needs a hack for Vue reactivity
|
// Needs a hack for Vue reactivity
|
||||||
let pubkeys = this.pubkeys
|
let pubkeys = this.pubkeys
|
||||||
pubkeys.delete(pubkey)
|
pubkeys.delete(pubkey)
|
||||||
|
this.profiles.delete(pubkey)
|
||||||
this.pubkeys = new Set(Array.from(pubkeys))
|
this.pubkeys = new Set(Array.from(pubkeys))
|
||||||
},
|
},
|
||||||
addRelay() {
|
async addRelay() {
|
||||||
let relay = String(this.inputRelay).trim()
|
let relay = String(this.inputRelay).trim()
|
||||||
if (!relay.startsWith('ws')) {
|
if (!relay.startsWith('ws')) {
|
||||||
console.debug('invalid url')
|
console.debug('invalid url')
|
||||||
|
|
@ -362,6 +389,7 @@
|
||||||
}
|
}
|
||||||
this.relays.add(relay)
|
this.relays.add(relay)
|
||||||
this.inputRelay = null
|
this.inputRelay = null
|
||||||
|
await this.initNostr()
|
||||||
},
|
},
|
||||||
removeRelay(relay) {
|
removeRelay(relay) {
|
||||||
// Needs a hack for Vue reactivity
|
// Needs a hack for Vue reactivity
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue