fix: login

This commit is contained in:
Vlad Stan 2023-07-07 10:53:48 +03:00
parent 602d6858cd
commit 14bb0ff6e6
2 changed files with 20 additions and 34 deletions

View file

@ -135,7 +135,7 @@ const market = async () => {
this.shoppingCarts = this.$q.localStorage.getItem('nostrmarket.shoppingCarts') || [] this.shoppingCarts = this.$q.localStorage.getItem('nostrmarket.shoppingCarts') || []
// Check for user stored // Check for user stored
this.account = this.$q.localStorage.getItem('diagonAlley.account') || null this.account = this.$q.localStorage.getItem('nostrmarket.account') || null
//console.log("UUID", crypto.randomUUID()) //console.log("UUID", crypto.randomUUID())
// Check for stored merchants and relays on localStorage // Check for stored merchants and relays on localStorage
@ -209,23 +209,24 @@ const market = async () => {
`This will delete all stored data. If you didn't backup the Key Pair (Private and Public Keys), you will lose it. Continue?` `This will delete all stored data. If you didn't backup the Key Pair (Private and Public Keys), you will lose it. Continue?`
) )
.onOk(() => { .onOk(() => {
window.localStorage.removeItem('diagonAlley.account') window.localStorage.removeItem('nostrmarket.account')
this.account = null this.account = null
}) })
}, },
async createAccount(useExtension = false) { async createAccount(useExtension = false) {
console.log('### createAccount',)
let nip07 let nip07
if (useExtension) { if (useExtension) {
await this.getFromExtension() await this.getFromExtension()
nip07 = true nip07 = true
} }
if (this.isValidKey) { if (isValidKey(this.accountDialog.data.key, 'nsec')) {
let { key, watchOnly } = this.accountDialog.data let { key, watchOnly } = this.accountDialog.data
if (key.startsWith('n')) { if (key.startsWith('n')) {
let { type, data } = NostrTools.nip19.decode(key) let { type, data } = NostrTools.nip19.decode(key)
key = data key = data
} }
this.$q.localStorage.set('diagonAlley.account', { this.$q.localStorage.set('nostrmarket.account', {
privkey: watchOnly ? null : key, privkey: watchOnly ? null : key,
pubkey: watchOnly ? key : NostrTools.getPublicKey(key), pubkey: watchOnly ? key : NostrTools.getPublicKey(key),
useExtension: nip07 ?? false useExtension: nip07 ?? false
@ -235,8 +236,9 @@ const market = async () => {
key: null key: null
} }
this.accountDialog.show = false this.accountDialog.show = false
this.account = this.$q.localStorage.getItem('diagonAlley.account') this.account = this.$q.localStorage.getItem('nostrmarket.account')
} }
this.accountDialog.show = false
}, },
generateKeyPair() { generateKeyPair() {
this.accountDialog.data.key = NostrTools.generatePrivateKey() this.accountDialog.data.key = NostrTools.generatePrivateKey()
@ -585,7 +587,7 @@ const market = async () => {
if (!product) { if (!product) {
product = { ...item, orderedQuantity: 1 } product = { ...item, orderedQuantity: 1 }
stallCart.products.push(product) stallCart.products.push(product)
} }
product.orderedQuantity = Math.min(product.quantity, item.orderedQuantity || (product.orderedQuantity + 1)) product.orderedQuantity = Math.min(product.quantity, item.orderedQuantity || (product.orderedQuantity + 1))
@ -597,8 +599,8 @@ const market = async () => {
const stallCart = this.shoppingCarts.find(c => c.id === item.stallId) const stallCart = this.shoppingCarts.find(c => c.id === item.stallId)
if (stallCart) { if (stallCart) {
stallCart.products = stallCart.products.filter(p => p.id !== item.productId) stallCart.products = stallCart.products.filter(p => p.id !== item.productId)
if (!stallCart.products.length){ if (!stallCart.products.length) {
this.shoppingCarts = this.shoppingCarts.filter(s => s.id !== item.stallId) this.shoppingCarts = this.shoppingCarts.filter(s => s.id !== item.stallId)
} }
this.$q.localStorage.set('nostrmarket.shoppingCarts', this.shoppingCarts) this.$q.localStorage.set('nostrmarket.shoppingCarts', this.shoppingCarts)
} }

View file

@ -224,44 +224,28 @@
</q-page-container> </q-page-container>
<!-- ACCOUNT DIALOG --> <!-- ACCOUNT DIALOG -->
<q-dialog v-model="accountDialog.show" persistent> <q-dialog v-model="accountDialog.show" position="top">
<q-card style="min-width: 350px"> <q-card >
<q-card-section class="row items-center q-pb-none"> <q-card-section class="row">
<div class="text-h6">Account Setup</div> <div class="text-h6">Account Setup</div>
<q-space></q-space> <q-space></q-space>
<q-btn icon="close" flat round dense v-close-popup></q-btn>
</q-card-section> </q-card-section>
<q-card-section> <q-card-section>
<p>Type your Nostr private key or generate a new one.</p> <p>Enter your Nostr private key or generate a new one.</p>
<small> You can also use a Nostr-capable extension. </small>
</q-card-section> </q-card-section>
<q-card-section class="q-pt-none"> <q-card-section class="q-pt-none">
<q-input dense label="nsec/npub/hex" v-model="accountDialog.data.key" autofocus @keyup.enter="createAccount" <q-input dense label="Nsec/Hex" v-model="accountDialog.data.key" autofocus @keyup.enter="createAccount"
:error="accountDialog.data.key && !isValidAccountKey" :error="accountDialog.data.key && !isValidAccountKey"
hint="Enter you private key (recommended) or public key"></q-input> hint="Enter you private key"></q-input>
<q-item tag="label">
<q-item-section avatar top>
<q-checkbox v-model="accountDialog.data.watchOnly"></q-checkbox>
</q-item-section>
<q-item-section>
<q-item-label>Is this a Public Key?</q-item-label>
<q-item-label caption>
If not using an Nostr capable extension, you'll have to sign
events manually! Better to use a Private Key that you can delete
later, or just generate an ephemeral key pair to use in the
Marketplace!
</q-item-label>
</q-item-section>
</q-item>
</q-card-section> </q-card-section>
<q-card-actions align="right" class="text-primary"> <q-card-actions align="right" class="text-primary">
<q-btn v-if="hasExtension" flat label="Use Public Key from Extension" <q-btn v-if="isValidAccountKey" label="Login" color="primary" @click="() => createAccount()"></q-btn>
@click="() => createAccount(true)"></q-btn>
<q-btn v-if="isValidAccountKey" label="Add key" color="primary" @click="() => createAccount()"></q-btn>
<q-btn v-else flat label="Generate" @click="generateKeyPair"></q-btn> <q-btn v-else flat label="Generate" @click="generateKeyPair"></q-btn>
<q-btn v-close-popup flat color="grey" class="q-ml-auto"
>Close</q-btn
>
</q-card-actions> </q-card-actions>
</q-card> </q-card>
</q-dialog> </q-dialog>