chore: code clean-up

This commit is contained in:
Vlad Stan 2023-07-18 09:13:53 +03:00
parent d22c15d7a7
commit e6d65c0ade
6 changed files with 39 additions and 62 deletions

View file

@ -25,9 +25,7 @@
<span v-text="stall.currency" class="float-right"></span> <span v-text="stall.currency" class="float-right"></span>
</div> </div>
</q-card-section> </q-card-section>
<!-- <q-card-section class="q-pl-sm">
</q-card-section> -->
<q-card-section class="q-pl-sm"> <q-card-section class="q-pl-sm">
<div v-if="stall.categories" class="text-subtitle1"> <div v-if="stall.categories" class="text-subtitle1">
<q-virtual-scroll :items="stall.categories || []" virtual-scroll-horizontal> <q-virtual-scroll :items="stall.categories || []" virtual-scroll-horizontal>

View file

@ -65,13 +65,6 @@ async function customerStall(path) {
z => z.id == this.checkoutDialog.data.shippingzone z => z.id == this.checkoutDialog.data.shippingzone
) )
return +this.cart.total + zoneCost.cost return +this.cart.total + zoneCost.cost
},
dropIn() {
return {
privkey: this.customerPrivkey,
pubkey: this.customerPubkey,
useExtension: this.customerUseExtension
}
} }
}, },
methods: { methods: {
@ -97,33 +90,10 @@ async function customerStall(path) {
getAmountFormated(amount, unit = 'USD') { getAmountFormated(amount, unit = 'USD') {
return LNbits.utils.formatCurrency(amount, unit) return LNbits.utils.formatCurrency(amount, unit)
}, },
updateQty(id, qty) {
let prod = this.cart.products
let product = prod.get(id)
prod.set(id, {
...product,
quantity: qty
})
this.updateCart()
},
addToCart(item) { addToCart(item) {
this.$emit('add-to-cart', item) this.$emit('add-to-cart', item)
}, },
updateCart() {
this.cart.total = 0
this.cart.products.forEach(p => {
this.cart.total += p.quantity * p.price
})
this.cart.size = this.cart.products.size
this.cartMenu = Array.from(this.cart.products, item => {
return {id: item[0], ...item[1]}
})
this.$q.localStorage.set(`diagonAlley.carts.${this.stall.id}`, {
...this.cart,
products: Object.fromEntries(this.cart.products)
})
},
resetCart() { resetCart() {
this.cart = { this.cart = {
total: 0, total: 0,
@ -145,7 +115,7 @@ async function customerStall(path) {
email: orderData?.email email: orderData?.email
}, },
items: Array.from(this.cart.products, p => { items: Array.from(this.cart.products, p => {
return {product_id: p[0], quantity: p[1].quantity} return { product_id: p[0], quantity: p[1].quantity }
}), }),
shipping_id: orderData.shippingzone shipping_id: orderData.shippingzone
} }
@ -162,29 +132,12 @@ async function customerStall(path) {
this.customerUseExtension = true this.customerUseExtension = true
this.checkoutDialog.data.pubkey = this.customerPubkey this.checkoutDialog.data.pubkey = this.customerPubkey
}, },
async generateKeyPair() {
this.customerPrivkey = NostrTools.generatePrivateKey()
this.customerPubkey = NostrTools.getPublicKey(this.customerPrivkey)
this.customerUseExtension = false
this.checkoutDialog.data.pubkey = this.customerPubkey
this.checkoutDialog.data.privkey = this.customerPrivkey
},
checkLogIn() { checkLogIn() {
this.customerPubkey = this.account?.pubkey this.customerPubkey = this.account?.pubkey
this.customerPrivkey = this.account?.privkey this.customerPrivkey = this.account?.privkey
this.customerUseExtension = this.account?.useExtension this.customerUseExtension = this.account?.useExtension
}, },
openCheckout() {
// Check if user is logged in
this.checkLogIn()
if (this.customerPubkey) {
this.checkoutDialog.data.pubkey = this.customerPubkey
if (this.customerPrivkey && !this.useExtension) {
this.checkoutDialog.data.privkey = this.customerPrivkey
}
}
this.checkoutDialog.show = true
},
resetCheckout() { resetCheckout() {
this.loading = false this.loading = false
this.checkoutDialog = { this.checkoutDialog = {
@ -229,7 +182,7 @@ async function customerStall(path) {
email: orderData?.email email: orderData?.email
}, },
items: Array.from(this.cart.products, p => { items: Array.from(this.cart.products, p => {
return {product_id: p[0], quantity: p[1].quantity} return { product_id: p[0], quantity: p[1].quantity }
}), }),
shipping_id: orderData.shippingzone, shipping_id: orderData.shippingzone,
type: 0 type: 0
@ -327,7 +280,7 @@ async function customerStall(path) {
console.error(`Error: ${err}`) console.error(`Error: ${err}`)
} }
}, },
messageFilter(text, cb = () => {}) { messageFilter(text, cb = () => { }) {
if (!isJson(text)) return if (!isJson(text)) return
let json = JSON.parse(text) let json = JSON.parse(text)
if (json.id != this.activeOrder) return if (json.id != this.activeOrder) return
@ -372,7 +325,7 @@ async function customerStall(path) {
this.cart.products = new Map(Object.entries(storedCart.products)) this.cart.products = new Map(Object.entries(storedCart.products))
this.cartMenu = Array.from(this.cart.products, item => { this.cartMenu = Array.from(this.cart.products, item => {
return {id: item[0], ...item[1]} return { id: item[0], ...item[1] }
}) })
} }
setTimeout(() => { setTimeout(() => {

View file

@ -101,9 +101,11 @@
<q-input @change="updateUiConfig" outlined v-model="configData.ui.banner" type="text" label="Banner" <q-input @change="updateUiConfig" outlined v-model="configData.ui.banner" type="text" label="Banner"
class="q-mb-md"> class="q-mb-md">
</q-input> </q-input>
<q-select @input="updateUiConfig" filled v-model="configData.ui.theme" <q-select @input="updateUiConfig" filled v-model="configData.ui.theme" hint="Choose marketplace theme"
hint="Choose marketplace theme" :options="themeOptions" label="Marketplace Theme"></q-select> :options="themeOptions" label="Marketplace Theme"></q-select>
<q-checkbox @input="updateUiConfig" v-model="configData.ui.darkMode" label="Dark Mode"
size="sm"></q-checkbox>
</q-tab-panel> </q-tab-panel>
@ -115,8 +117,8 @@
<q-separator /> <q-separator />
<q-card-section> <q-card-section>
<div class="float-right"> <div class="float-right">
<q-btn rounded label="Copy Naddr" color="green"></q-btn> <q-btn flat label="Copy Naddr" color="green"></q-btn>
<q-btn rounded label="Update" class="q-ml-lg" color="primary"></q-btn> <q-btn flat label="Update" 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

@ -19,7 +19,8 @@ async function marketConfig(path) {
ui: { ui: {
picture: null, picture: null,
banner: null, banner: null,
theme: null theme: null,
darkMode: false
} }
}, },
themeOptions: [ themeOptions: [

View file

@ -15,7 +15,7 @@
standout standout
:max="products.find(pr => pr.id == p.id).quantity" :max="products.find(pr => pr.id == p.id).quantity"
></q-input> ></q-input>
<!-- <span class="text-center q-ma-xs">{{p.quantity}} x </span> -->
<q-btn color="green" size="xs" icon="add" @click="add(p.id)" /> <q-btn color="green" size="xs" icon="add" @click="add(p.id)" />
</q-item-section> </q-item-section>
<q-item-section avatar v-if="p.image"> <q-item-section avatar v-if="p.image">

View file

@ -150,7 +150,30 @@
</div> </div>
</q-page-container> </q-page-container>
<!-- END CHECKOUT DIALOG --> <!-- ACCOUNT DIALOG -->
<q-dialog v-model="accountDialog.show" position="top">
<q-card>
<q-card-section class="row">
<div class="text-h6">Account Setup</div>
<q-space></q-space>
</q-card-section>
<q-card-section>
<p>Enter your Nostr private key or generate a new one.</p>
</q-card-section>
<q-card-section class="q-pt-none">
<q-input dense label="Nsec/Hex" v-model="accountDialog.data.key" autofocus @keyup.enter="createAccount"
:error="accountDialog.data.key && !isValidAccountKey" hint="Enter you private key"></q-input>
</q-card-section>
<q-card-actions align="right" class="text-primary">
<q-btn v-if="isValidAccountKey" label="Login" color="primary" @click="() => createAccount()"></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>
</q-dialog>
<!-- INVOICE DIALOG --> <!-- INVOICE DIALOG -->
<q-dialog v-model="qrCodeDialog.show" position="top"> <q-dialog v-model="qrCodeDialog.show" position="top">
<q-card class="q-pa-lg q-pt-xl lnbits__dialog-card"> <q-card class="q-pa-lg q-pt-xl lnbits__dialog-card">