make markets great again
This commit is contained in:
parent
715709ce25
commit
7c1a639796
7 changed files with 101 additions and 367 deletions
|
|
@ -399,8 +399,18 @@ async def create_shop_market_stalls(market_id: str, data: List[CreateMarketStall
|
||||||
return market_stalls
|
return market_stalls
|
||||||
|
|
||||||
|
|
||||||
async def update_shop_market(market_id):
|
async def update_shop_market(market_id: str, name: str):
|
||||||
pass
|
await db.execute(
|
||||||
|
"UPDATE shop.markets SET name = ? WHERE id = ?",
|
||||||
|
(name, market_id),
|
||||||
|
)
|
||||||
|
await db.execute(
|
||||||
|
"DELETE FROM shop.market_stalls WHERE marketid = ?",
|
||||||
|
(market_id,),
|
||||||
|
)
|
||||||
|
|
||||||
|
market = await get_shop_market(market_id)
|
||||||
|
return market
|
||||||
|
|
||||||
|
|
||||||
### CHAT / MESSAGES
|
### CHAT / MESSAGES
|
||||||
|
|
|
||||||
|
|
@ -195,12 +195,12 @@
|
||||||
></q-toggle>
|
></q-toggle>
|
||||||
<q-select
|
<q-select
|
||||||
filled
|
filled
|
||||||
dense
|
|
||||||
multiple
|
multiple
|
||||||
emit-value
|
emit-value
|
||||||
:options="stalls.map(s => ({label: s.name, value: s.id}))"
|
:options="stalls.map(s => ({label: s.name, value: s.id}))"
|
||||||
label="Stalls"
|
label="Stalls"
|
||||||
v-model.trim="marketDialog.data.stalls"
|
v-model="marketDialog.data.stalls"
|
||||||
|
map-options
|
||||||
></q-select>
|
></q-select>
|
||||||
<q-input
|
<q-input
|
||||||
filled
|
filled
|
||||||
|
|
|
||||||
|
|
@ -354,14 +354,14 @@
|
||||||
<q-tooltip> Link to pass to stall relay </q-tooltip>
|
<q-tooltip> Link to pass to stall relay </q-tooltip>
|
||||||
</q-td>
|
</q-td>
|
||||||
<q-td v-for="col in props.cols" :key="col.name" :props="props">
|
<q-td v-for="col in props.cols" :key="col.name" :props="props">
|
||||||
{{ col.value }}
|
{{ col.name == 'stalls' ? stallName(col.value) : col.value }}
|
||||||
</q-td>
|
</q-td>
|
||||||
<q-td auto-width>
|
<q-td auto-width>
|
||||||
<q-btn
|
<q-btn
|
||||||
flat
|
flat
|
||||||
dense
|
dense
|
||||||
size="xs"
|
size="xs"
|
||||||
@click="openStallUpdateDialog(props.row.id)"
|
@click="openMarketUpdateDialog(props.row.id)"
|
||||||
icon="edit"
|
icon="edit"
|
||||||
color="light-blue"
|
color="light-blue"
|
||||||
></q-btn>
|
></q-btn>
|
||||||
|
|
@ -369,7 +369,7 @@
|
||||||
flat
|
flat
|
||||||
dense
|
dense
|
||||||
size="xs"
|
size="xs"
|
||||||
@click="deleteStall(props.row.id)"
|
@click="deleteMarket(props.row.id)"
|
||||||
icon="cancel"
|
icon="cancel"
|
||||||
color="pink"
|
color="pink"
|
||||||
></q-btn>
|
></q-btn>
|
||||||
|
|
|
||||||
|
|
@ -213,12 +213,12 @@
|
||||||
|
|
||||||
const mapMarkets = obj => {
|
const mapMarkets = obj => {
|
||||||
obj._data = _.clone(obj)
|
obj._data = _.clone(obj)
|
||||||
obj.stores = []
|
obj.stalls = []
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request('GET', `/shop/api/v1/markets/${obj.id}/stalls`, null)
|
.request('GET', `/shop/api/v1/markets/${obj.id}/stalls`, null)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.data) {
|
if (response.data) {
|
||||||
obj.stores = response.data.map(s => s.name).toString()
|
obj.stalls = response.data.map(s => s.id) //.toString()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
|
@ -460,10 +460,10 @@
|
||||||
field: 'name'
|
field: 'name'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'stores',
|
name: 'stalls',
|
||||||
align: 'left',
|
align: 'left',
|
||||||
label: 'Stalls',
|
label: 'Stalls',
|
||||||
field: 'stores'
|
field: 'stalls'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
pagination: {
|
pagination: {
|
||||||
|
|
@ -637,6 +637,9 @@
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
////////////////STALLS//////////////////
|
////////////////STALLS//////////////////
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
|
stallName(id) {
|
||||||
|
return id.map(c => this.stalls.find(s => s.id == c).name).toString()
|
||||||
|
},
|
||||||
getStalls: function () {
|
getStalls: function () {
|
||||||
var self = this
|
var self = this
|
||||||
LNbits.api
|
LNbits.api
|
||||||
|
|
@ -1035,44 +1038,38 @@
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
openShopUpdateDialog: function (linkId) {
|
openMarketUpdateDialog(linkId) {
|
||||||
var self = this
|
var link = _.findWhere(this.markets, {id: linkId})
|
||||||
var link = _.findWhere(self.markets, {id: linkId})
|
this.marketDialog.data = link
|
||||||
|
|
||||||
this.marketDialog.data = _.clone(link._data)
|
|
||||||
this.marketDialog.show = true
|
this.marketDialog.show = true
|
||||||
},
|
},
|
||||||
sendMarketplaceFormData: function () {
|
sendMarketplaceFormData() {
|
||||||
let data = {...this.marketDialog.data}
|
let data = {...this.marketDialog.data}
|
||||||
|
|
||||||
if (!data.usr) {
|
if (!data.usr) {
|
||||||
data.usr = this.g.user.id
|
data.usr = this.g.user.id
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.id) {
|
if (data.id) {
|
||||||
this.updateZone(data)
|
this.updateMarketplace(data)
|
||||||
} else {
|
} else {
|
||||||
this.createMarketplace(data)
|
this.createMarketplace(data)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
updateShop: function (data) {
|
updateMarketplace(data) {
|
||||||
var self = this
|
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'PUT',
|
'PUT',
|
||||||
'/shop/api/v1/shops' + data.id,
|
'/shop/api/v1/markets/' + data.id,
|
||||||
_.findWhere(self.g.user.wallets, {
|
this.g.user.wallets[0].inkey,
|
||||||
id: self.marketDialog.data.wallet
|
data
|
||||||
}).inkey,
|
|
||||||
_.pick(data, 'countries', 'cost')
|
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.then(response => {
|
||||||
self.markets = _.reject(self.markets, function (obj) {
|
this.markets = _.reject(this.markets, obj => {
|
||||||
return obj.id == data.id
|
return obj.id == data.id
|
||||||
})
|
})
|
||||||
self.markets.push(mapShops(response.data))
|
this.markets.push(mapMarkets(response.data))
|
||||||
self.marketDialog.show = false
|
this.marketDialog.show = false
|
||||||
self.marketDialog.data = {}
|
this.marketDialog.data = {}
|
||||||
data = {}
|
data = {}
|
||||||
})
|
})
|
||||||
.catch(function (error) {
|
.catch(function (error) {
|
||||||
|
|
@ -1097,21 +1094,20 @@
|
||||||
LNbits.utils.notifyApiError(error)
|
LNbits.utils.notifyApiError(error)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
deleteShop: function (shopId) {
|
deleteMarket(shopId) {
|
||||||
var self = this
|
let market = _.findWhere(this.markets, {id: shopId})
|
||||||
var shop = _.findWhere(self.markets, {id: shopId})
|
|
||||||
|
|
||||||
LNbits.utils
|
LNbits.utils
|
||||||
.confirmDialog('Are you sure you want to delete this Shop link?')
|
.confirmDialog('Are you sure you want to delete this Marketplace?')
|
||||||
.onOk(function () {
|
.onOk(() => {
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'DELETE',
|
'DELETE',
|
||||||
'/shop/api/v1/shops/' + shopId,
|
'/shop/api/v1/markets/' + shopId,
|
||||||
_.findWhere(self.g.user.wallets, {id: shop.wallet}).inkey
|
this.g.user.wallets[0].inkey
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.then(response => {
|
||||||
self.markets = _.reject(self.markets, function (obj) {
|
this.markets = _.reject(this.markets, obj => {
|
||||||
return obj.id == shopId
|
return obj.id == shopId
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -1144,32 +1140,6 @@
|
||||||
LNbits.utils.notifyApiError(error)
|
LNbits.utils.notifyApiError(error)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
/*createOrder: function () {
|
|
||||||
var data = {
|
|
||||||
address: this.orderDialog.data.address,
|
|
||||||
email: this.orderDialog.data.email,
|
|
||||||
quantity: this.orderDialog.data.quantity,
|
|
||||||
shippingzone: this.orderDialog.data.shippingzone
|
|
||||||
}
|
|
||||||
var self = this
|
|
||||||
|
|
||||||
LNbits.api
|
|
||||||
.request(
|
|
||||||
'POST',
|
|
||||||
'/shop/api/v1/orders',
|
|
||||||
_.findWhere(self.g.user.wallets, {id: self.orderDialog.data.wallet})
|
|
||||||
.inkey,
|
|
||||||
data
|
|
||||||
)
|
|
||||||
.then(function (response) {
|
|
||||||
self.orders.push(mapOrders(response.data))
|
|
||||||
self.orderDialog.show = false
|
|
||||||
self.orderDialog.data = {}
|
|
||||||
})
|
|
||||||
.catch(function (error) {
|
|
||||||
LNbits.utils.notifyApiError(error)
|
|
||||||
})
|
|
||||||
},*/
|
|
||||||
deleteOrder: function (orderId) {
|
deleteOrder: function (orderId) {
|
||||||
var self = this
|
var self = this
|
||||||
var order = _.findWhere(self.orders, {id: orderId})
|
var order = _.findWhere(self.orders, {id: orderId})
|
||||||
|
|
@ -1195,7 +1165,6 @@
|
||||||
},
|
},
|
||||||
shipOrder(order_id) {
|
shipOrder(order_id) {
|
||||||
let shipped = this.orders.find(o => o.id == order_id).shipped
|
let shipped = this.orders.find(o => o.id == order_id).shipped
|
||||||
console.log(this.orders, order_id, shipped)
|
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'GET',
|
'GET',
|
||||||
|
|
@ -1383,7 +1352,6 @@
|
||||||
this.diagonAlley =
|
this.diagonAlley =
|
||||||
this.$q.localStorage.getItem('lnbits.DAmode') || false
|
this.$q.localStorage.getItem('lnbits.DAmode') || false
|
||||||
this.currencies.unit = '{{ currency }}'
|
this.currencies.unit = '{{ currency }}'
|
||||||
console.log(this.currencies.unit, '{{currency}}')
|
|
||||||
await this.getCurrencies()
|
await this.getCurrencies()
|
||||||
this.getStalls()
|
this.getStalls()
|
||||||
this.getProducts()
|
this.getProducts()
|
||||||
|
|
|
||||||
|
|
@ -21,49 +21,6 @@
|
||||||
</template>
|
</template>
|
||||||
</q-input>
|
</q-input>
|
||||||
</div>
|
</div>
|
||||||
<q-btn dense round flat icon="shopping_cart">
|
|
||||||
{% raw %}
|
|
||||||
<q-badge v-if="cart.size" color="red" class="text-bold" floating>
|
|
||||||
{{ cart.size }}
|
|
||||||
</q-badge>
|
|
||||||
{% endraw %}
|
|
||||||
<q-menu auto-close v-if="cart.size">
|
|
||||||
<q-list style="min-width: 100px">
|
|
||||||
{% raw %}
|
|
||||||
<q-item clickable :key="p.id" v-for="p in cartMenu">
|
|
||||||
<q-item-section side>
|
|
||||||
<span>{{p.quantity}} x </span>
|
|
||||||
</q-item-section>
|
|
||||||
<q-item-section avatar>
|
|
||||||
<q-avatar color="primary">
|
|
||||||
<img
|
|
||||||
size="sm"
|
|
||||||
:src="products.find(f => f.id == p.id).image"
|
|
||||||
/>
|
|
||||||
</q-avatar>
|
|
||||||
</q-item-section>
|
|
||||||
|
|
||||||
<q-item-section>
|
|
||||||
<q-item-label>{{ p.name }}</q-item-label>
|
|
||||||
</q-item-section>
|
|
||||||
|
|
||||||
<q-item-section side>
|
|
||||||
<span> {{p.price}} sats</span>
|
|
||||||
</q-item-section>
|
|
||||||
</q-item>
|
|
||||||
{% endraw %}
|
|
||||||
<q-separator />
|
|
||||||
</q-list>
|
|
||||||
<div class="q-pa-md q-gutter-md">
|
|
||||||
<q-btn
|
|
||||||
color="primary"
|
|
||||||
icon-right="checkout"
|
|
||||||
label="Checkout"
|
|
||||||
@click="checkoutDialog.show = true"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</q-menu>
|
|
||||||
</q-btn>
|
|
||||||
</q-toolbar>
|
</q-toolbar>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -85,22 +42,6 @@
|
||||||
></q-img>
|
></q-img>
|
||||||
|
|
||||||
<q-card-section class="q-pb-xs q-pt-md">
|
<q-card-section class="q-pb-xs q-pt-md">
|
||||||
<q-btn
|
|
||||||
round
|
|
||||||
:disabled="item.quantity < 1"
|
|
||||||
color="primary"
|
|
||||||
icon="shopping_cart"
|
|
||||||
size="lg"
|
|
||||||
style="
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
right: 0;
|
|
||||||
transform: translate(-50%, -50%);
|
|
||||||
"
|
|
||||||
@click="addToCart(item)"
|
|
||||||
><q-tooltip> Add to cart </q-tooltip></q-btn
|
|
||||||
>
|
|
||||||
|
|
||||||
<div class="row no-wrap items-center">
|
<div class="row no-wrap items-center">
|
||||||
<div class="col text-subtitle2 ellipsis-2-lines">
|
<div class="col text-subtitle2 ellipsis-2-lines">
|
||||||
{{ item.product }}
|
{{ item.product }}
|
||||||
|
|
@ -112,13 +53,23 @@
|
||||||
|
|
||||||
<q-card-section class="q-py-sm">
|
<q-card-section class="q-py-sm">
|
||||||
<div>
|
<div>
|
||||||
<!-- <div class="text-caption text-green-8 text-weight-bolder">
|
<div class="text-caption text-weight-bolder">
|
||||||
{{ stall.name }}
|
{{ item.stallName }}
|
||||||
</div> -->
|
</div>
|
||||||
|
<span v-if="item.currency == 'sat'">
|
||||||
<span class="text-h6">{{ item.price }} sats</span
|
<span class="text-h6">{{ item.price }} sats</span
|
||||||
><span class="q-ml-sm text-grey-6"
|
><span class="q-ml-sm text-grey-6"
|
||||||
>BTC {{ (item.price / 1e8).toFixed(8) }}</span
|
>BTC {{ (item.price / 1e8).toFixed(8) }}</span
|
||||||
>
|
>
|
||||||
|
</span>
|
||||||
|
<span v-else>
|
||||||
|
<span class="text-h6"
|
||||||
|
>{{ getAmountFormated(item.price, item.currency) }}</span
|
||||||
|
>
|
||||||
|
<span v-if="exchangeRates" class="q-ml-sm text-grey-6"
|
||||||
|
>({{ getValueInSats(item.price, item.currency) }} sats)</span
|
||||||
|
>
|
||||||
|
</span>
|
||||||
<span
|
<span
|
||||||
class="q-ml-md text-caption text-green-8 text-weight-bolder q-mt-md"
|
class="q-ml-md text-caption text-green-8 text-weight-bolder q-mt-md"
|
||||||
>{{item.quantity}} left</span
|
>{{item.quantity}} left</span
|
||||||
|
|
@ -140,7 +91,7 @@
|
||||||
<q-separator></q-separator>
|
<q-separator></q-separator>
|
||||||
|
|
||||||
<q-card-actions>
|
<q-card-actions>
|
||||||
<span>{{ stall.find(s => s.id == item.stall).name }}</span>
|
<span>{{ item.stallName }}</span>
|
||||||
<q-btn
|
<q-btn
|
||||||
flat
|
flat
|
||||||
class="text-weight-bold text-capitalize q-ml-auto"
|
class="text-weight-bold text-capitalize q-ml-auto"
|
||||||
|
|
@ -156,110 +107,6 @@
|
||||||
{% endraw %}
|
{% endraw %}
|
||||||
</q-card>
|
</q-card>
|
||||||
</div>
|
</div>
|
||||||
<!-- CHECKOUT DIALOG -->
|
|
||||||
<q-dialog v-model="checkoutDialog.show" position="top">
|
|
||||||
<q-card class="q-pa-lg q-pt-xl lnbits__dialog-card">
|
|
||||||
<q-form @submit="placeOrder" class="q-gutter-md">
|
|
||||||
<q-input
|
|
||||||
filled
|
|
||||||
dense
|
|
||||||
v-model.trim="checkoutDialog.data.username"
|
|
||||||
label="Name *optional"
|
|
||||||
></q-input>
|
|
||||||
<q-input
|
|
||||||
filled
|
|
||||||
dense
|
|
||||||
v-model.trim="checkoutDialog.data.address"
|
|
||||||
label="Address"
|
|
||||||
></q-input>
|
|
||||||
<!-- <q-input
|
|
||||||
filled
|
|
||||||
dense
|
|
||||||
v-model.trim="checkoutDialog.data.address_2"
|
|
||||||
label="Address (line 2)"
|
|
||||||
></q-input> -->
|
|
||||||
<q-input
|
|
||||||
v-model="checkoutDialog.data.email"
|
|
||||||
filled
|
|
||||||
dense
|
|
||||||
type="email"
|
|
||||||
label="Email"
|
|
||||||
></q-input>
|
|
||||||
<p>Select the shipping zone:</p>
|
|
||||||
<div class="row q-mt-lg">
|
|
||||||
<q-option-group
|
|
||||||
:options="stall.zones"
|
|
||||||
type="radio"
|
|
||||||
emit-value
|
|
||||||
v-model="checkoutDialog.data.shippingzone"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div class="row q-mt-lg">
|
|
||||||
{% raw %} Total: {{ finalCost }} {% endraw %}
|
|
||||||
</div>
|
|
||||||
<div class="row q-mt-lg">
|
|
||||||
<q-btn
|
|
||||||
unelevated
|
|
||||||
color="primary"
|
|
||||||
:disable="checkoutDialog.data.address == null
|
|
||||||
|| checkoutDialog.data.email == null
|
|
||||||
|| checkoutDialog.data.shippingzone == null"
|
|
||||||
type="submit"
|
|
||||||
>Checkout</q-btn
|
|
||||||
>
|
|
||||||
<q-btn
|
|
||||||
v-close-popup
|
|
||||||
flat
|
|
||||||
@click="checkoutDialog = {show: false, data: {}}"
|
|
||||||
color="grey"
|
|
||||||
class="q-ml-auto"
|
|
||||||
>Cancel</q-btn
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
</q-form>
|
|
||||||
</q-card>
|
|
||||||
</q-dialog>
|
|
||||||
<!-- INVOICE DIALOG -->
|
|
||||||
<q-dialog
|
|
||||||
v-model="qrCodeDialog.show"
|
|
||||||
position="top"
|
|
||||||
@hide="closeQrCodeDialog"
|
|
||||||
>
|
|
||||||
<q-card
|
|
||||||
v-if="!qrCodeDialog.data.payment_request"
|
|
||||||
class="q-pa-lg q-pt-xl lnbits__dialog-card"
|
|
||||||
>
|
|
||||||
</q-card>
|
|
||||||
<q-card v-else class="q-pa-lg q-pt-xl lnbits__dialog-card">
|
|
||||||
<div class="text-center q-mb-lg">
|
|
||||||
<a :href="'lightning:' + qrCodeDialog.data.payment_request">
|
|
||||||
<q-responsive :ratio="1" class="q-mx-xl">
|
|
||||||
<qrcode
|
|
||||||
:value="qrCodeDialog.data.payment_request"
|
|
||||||
:options="{width: 340}"
|
|
||||||
class="rounded-borders"
|
|
||||||
></qrcode>
|
|
||||||
</q-responsive>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="row q-mt-lg">
|
|
||||||
<q-btn
|
|
||||||
outline
|
|
||||||
color="grey"
|
|
||||||
@click="copyText(qrCodeDialog.data.payment_request)"
|
|
||||||
>Copy invoice</q-btn
|
|
||||||
>
|
|
||||||
<q-btn
|
|
||||||
@click="closeQrCodeDialog"
|
|
||||||
v-close-popup
|
|
||||||
flat
|
|
||||||
color="grey"
|
|
||||||
class="q-ml-auto"
|
|
||||||
>Close</q-btn
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
</q-card>
|
|
||||||
</q-dialog>
|
|
||||||
</div>
|
</div>
|
||||||
{% endblock %} {% block scripts %}
|
{% endblock %} {% block scripts %}
|
||||||
<script>
|
<script>
|
||||||
|
|
@ -269,25 +116,10 @@
|
||||||
mixins: [windowMixin],
|
mixins: [windowMixin],
|
||||||
data: function () {
|
data: function () {
|
||||||
return {
|
return {
|
||||||
stall: null,
|
stalls: null,
|
||||||
products: [],
|
products: [],
|
||||||
searchText: null,
|
searchText: null,
|
||||||
cart: {
|
exchangeRates: null
|
||||||
total: 0,
|
|
||||||
size: 0,
|
|
||||||
products: new Map()
|
|
||||||
},
|
|
||||||
cartMenu: [],
|
|
||||||
checkoutDialog: {
|
|
||||||
show: false,
|
|
||||||
data: {}
|
|
||||||
},
|
|
||||||
qrCodeDialog: {
|
|
||||||
data: {
|
|
||||||
payment_request: null
|
|
||||||
},
|
|
||||||
show: false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
|
@ -300,124 +132,47 @@
|
||||||
p.categories.includes(this.searchText)
|
p.categories.includes(this.searchText)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
},
|
|
||||||
finalCost() {
|
|
||||||
if (!this.checkoutDialog.data.shippingzone) return this.cart.total
|
|
||||||
|
|
||||||
let zoneCost = this.stall.zones.find(
|
|
||||||
z => z.value == this.checkoutDialog.data.shippingzone
|
|
||||||
)
|
|
||||||
|
|
||||||
return this.cart.total + zoneCost.cost
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
closeQrCodeDialog() {
|
async getRates() {
|
||||||
this.qrCodeDialog.dismissMsg()
|
let hasFiat = this.stalls.map(s => s.currency).every(c => c != 'sat')
|
||||||
this.qrCodeDialog.show = false
|
if (!hasFiat) return
|
||||||
},
|
try {
|
||||||
resetCart() {
|
let rates = await axios.get('https://api.opennode.co/v1/rates')
|
||||||
this.cart = {
|
this.exchangeRates = rates.data.data
|
||||||
total: 0,
|
console.log(this.exchangeRates)
|
||||||
size: 0,
|
} catch (error) {
|
||||||
products: new Map()
|
LNbits.utils.notifyApiError(error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
addToCart(item) {
|
getValueInSats(amount, unit = 'USD') {
|
||||||
let prod = this.cart.products
|
if (!this.exchangeRates) return 0
|
||||||
if (prod.has(item.id)) {
|
return Math.ceil(
|
||||||
let qty = prod.get(item.id).quantity
|
(amount / this.exchangeRates[`BTC${unit}`][unit]) * 1e8
|
||||||
prod.set(item.id, {
|
|
||||||
...prod.get(item.id),
|
|
||||||
quantity: qty + 1
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
prod.set(item.id, {
|
|
||||||
name: item.product,
|
|
||||||
quantity: 1,
|
|
||||||
price: item.price
|
|
||||||
})
|
|
||||||
}
|
|
||||||
this.cart.products = prod
|
|
||||||
this.updateCart(item.price)
|
|
||||||
},
|
|
||||||
removeFromCart() {},
|
|
||||||
updateCart(price) {
|
|
||||||
this.cart.total += price
|
|
||||||
this.cart.size++
|
|
||||||
this.cartMenu = Array.from(this.cart.products, item => {
|
|
||||||
return {id: item[0], ...item[1]}
|
|
||||||
})
|
|
||||||
console.log(this.cartMenu, this.cart)
|
|
||||||
},
|
|
||||||
placeOrder() {
|
|
||||||
let dialog = this.checkoutDialog.data
|
|
||||||
let data = {
|
|
||||||
...this.checkoutDialog.data,
|
|
||||||
wallet: this.stall.wallet,
|
|
||||||
total: this.finalCost,
|
|
||||||
products: Array.from(this.cart.products, p => {
|
|
||||||
return {product_id: p[0], quantity: p[1].quantity}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
LNbits.api
|
|
||||||
.request('POST', '/shop/api/v1/orders', null, data)
|
|
||||||
.then(res => {
|
|
||||||
this.checkoutDialog = {show: false, data: {}}
|
|
||||||
|
|
||||||
return res.data
|
|
||||||
})
|
|
||||||
.then(data => {
|
|
||||||
this.qrCodeDialog.data = data
|
|
||||||
this.qrCodeDialog.show = true
|
|
||||||
|
|
||||||
this.qrCodeDialog.dismissMsg = this.$q.notify({
|
|
||||||
timeout: 0,
|
|
||||||
message: 'Waiting for payment...'
|
|
||||||
})
|
|
||||||
return data
|
|
||||||
})
|
|
||||||
.then(data => {
|
|
||||||
this.qrCodeDialog.paymentChecker = setInterval(() => {
|
|
||||||
LNbits.api
|
|
||||||
.request(
|
|
||||||
'GET',
|
|
||||||
`/shop/api/v1/orders/payments/${this.qrCodeDialog.data.payment_hash}`
|
|
||||||
)
|
)
|
||||||
.then(res => {
|
},
|
||||||
if (res.data.paid) {
|
getAmountFormated(amount, unit = 'USD') {
|
||||||
this.$q.notify({
|
return LNbits.utils.formatCurrency(amount, unit)
|
||||||
type: 'positive',
|
|
||||||
message: 'Sats received, thanks!',
|
|
||||||
icon: 'thumb_up'
|
|
||||||
})
|
|
||||||
clearInterval(this.qrCodeDialog.paymentChecker)
|
|
||||||
this.resetCart()
|
|
||||||
this.closeQrCodeDialog()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error(error)
|
|
||||||
LNbits.utils.notifyApiError(error)
|
|
||||||
})
|
|
||||||
}, 3000)
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error(error)
|
|
||||||
LNbits.utils.notifyApiError(error)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
async created() {
|
||||||
this.stall = JSON.parse('{{ stalls | tojson }}')
|
this.stalls = JSON.parse('{{ stalls | tojson }}')
|
||||||
this.products = JSON.parse('{{ products | tojson }}')
|
let products = JSON.parse('{{ products | tojson }}')
|
||||||
|
|
||||||
console.log(this.stall, this.products)
|
this.products = products.map(obj => {
|
||||||
|
let stall = this.stalls.find(s => s.id == obj.stall)
|
||||||
|
obj.currency = stall.currency
|
||||||
|
if (obj.currency != 'sat') {
|
||||||
|
obj.price = parseFloat((obj.price / 100).toFixed(2))
|
||||||
|
}
|
||||||
|
obj.stallName = stall.name
|
||||||
|
return obj
|
||||||
|
})
|
||||||
|
await this.getRates()
|
||||||
|
|
||||||
|
console.log(this.stalls, this.products)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
<style scoped>
|
|
||||||
.card--product {
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
||||||
|
|
@ -300,7 +300,7 @@
|
||||||
{% endblock %} {% block scripts %}
|
{% endblock %} {% block scripts %}
|
||||||
<script>
|
<script>
|
||||||
const mapProductsItems = obj => {
|
const mapProductsItems = obj => {
|
||||||
obj.price = (obj.price / 100).toFixed(2)
|
obj.price = parseFloat((obj.price / 100).toFixed(2))
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -439,9 +439,10 @@ async def api_shop_stall_create(
|
||||||
if market.usr != wallet.wallet.user:
|
if market.usr != wallet.wallet.user:
|
||||||
return {"message": "Not your market."}
|
return {"message": "Not your market."}
|
||||||
|
|
||||||
market = await update_shop_market(market_id, **data.dict())
|
market = await update_shop_market(market_id, data.name)
|
||||||
else:
|
else:
|
||||||
market = await create_shop_market(data=data)
|
market = await create_shop_market(data=data)
|
||||||
|
|
||||||
await create_shop_market_stalls(market_id=market.id, data=data.stalls)
|
await create_shop_market_stalls(market_id=market.id, data=data.stalls)
|
||||||
|
|
||||||
return market.dict()
|
return market.dict()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue