Fixed create

This commit is contained in:
arcbtc 2023-12-28 21:53:57 +00:00
parent ea75373532
commit c749da80dd
4 changed files with 83 additions and 63 deletions

Binary file not shown.

View file

@ -11,14 +11,13 @@ async def create_temp(wallet_id: str, data: CreateTempData) -> Temp:
temp_id = urlsafe_short_hash() temp_id = urlsafe_short_hash()
await db.execute( await db.execute(
""" """
INSERT INTO tempextension.temp (id, wallet, name, total) INSERT INTO tempextension.temp (id, wallet, name, lnurlpayamount, lnurlwithdrawamount)
VALUES (?, ?, ?, ?) VALUES (?, ?, ?, ?, ?)
""", """,
( (
temp_id, temp_id,
wallet_id, wallet_id,
data.name, data.name,
data.total,
data.lnurlpayamount, data.lnurlpayamount,
data.lnurlwithdrawamount data.lnurlwithdrawamount
), ),

View file

@ -7,7 +7,7 @@
<q-btn unelevated color="primary" @click="formDialog.show = true" <q-btn unelevated color="primary" @click="formDialog.show = true"
>New Temp</q-btn >New Temp</q-btn
> >
</q-card-section> </q-card-section>
</q-card> </q-card>
<q-card> <q-card>
@ -30,13 +30,46 @@
> >
<temp v-slot:header="props"> <temp v-slot:header="props">
<q-tr :props="props"> <q-tr :props="props">
<q-th auto-width></q-th>
<q-th auto-width></q-th>
<q-th v-for="col in props.cols" :key="col.name" :props="props"> <q-th v-for="col in props.cols" :key="col.name" :props="props">
${ col.label } ${ col.label }
</q-th> </q-th>
<q-th auto-width>LNURL-pay</q-th>
<q-th auto-width>LNURL-withdraw</q-th>
</q-tr> </q-tr>
</temp> </temp>
<template v-slot:body="props">
<q-tr :props="props">
<q-td
v-for="col in props.cols"
:key="col.name"
:props="props"
>
${ col.value }
<q-btn
unelevated
dense
size="sm"
v-if="col.name == 'lnurlpayamount'"
icon="qr_code"
:color="($q.dark.isActive) ? 'grey-7' : 'grey-5'"
class="q-mr-sm"
@click="openUrlDialog(props.row.id)"
></q-btn>
<q-btn
unelevated
dense
size="sm"
v-if="col.name == 'lnurlwithdrawamount'"
icon="qr_code"
:color="($q.dark.isActive) ? 'grey-7' : 'grey-5'"
class="q-mr-sm"
@click="openUrlDialog(props.row.id)"
></q-btn>
</q-td>
</q-tr>
</template>
</q-table> </q-table>
</q-card-section> </q-card-section>
</q-card> </q-card>
@ -46,6 +79,7 @@
<q-card> <q-card>
<q-card-section> <q-card-section>
<h6 class="text-subtitle1 q-my-none">{{SITE_TITLE}} Temp extension</h6> <h6 class="text-subtitle1 q-my-none">{{SITE_TITLE}} Temp extension</h6>
<p>Simple extension you can use as a base for your own extension. <br/> Includes very simple LNURL-pay and LNURL-withdraw example.</p>
</q-card-section> </q-card-section>
<q-card-section class="q-pa-none"> <q-card-section class="q-pa-none">
<q-separator></q-separator> <q-separator></q-separator>
@ -79,14 +113,16 @@
<q-input <q-input
filled filled
dense dense
v-model.trim="itemDialog.data.description" type="number"
label="Description" v-model.trim="formDialog.data.lnurlwithdrawamount"
label="LNURL-withdraw amount"
></q-input> ></q-input>
<q-input <q-input
filled filled
dense dense
v-model.trim="itemDialog.data.description" type="number"
label="Description" v-model.trim="formDialog.data.lnurlpayamount"
label="LNURL-pay amount"
></q-input> ></q-input>
<div class="row q-mt-lg"> <div class="row q-mt-lg">
<q-btn <q-btn
@ -100,7 +136,7 @@
v-else v-else
unelevated unelevated
color="primary" color="primary"
:disable="formDialog.data.currency == null || formDialog.data.name == null" :disable="formDialog.data.name == null || formDialog.data.wallet == null || formDialog.data.lnurlwithdrawamount == null || formDialog.data.lnurlpayamount == null"
type="submit" type="submit"
>Create Temp</q-btn >Create Temp</q-btn
> >
@ -137,24 +173,13 @@
</div> </div>
{% endblock %} {% block scripts %} {{ window_vars(user) }} {% endblock %} {% block scripts %} {{ window_vars(user) }}
<script> <script>
// The object returned here will be merged with the data object of the Vue instance
const mapTemp = obj => { const mapTemp = obj => {
obj.date = Quasar.utils.date.formatDate( obj.date = Quasar.utils.date.formatDate(
new Date(obj.time * 1000), new Date(obj.time * 1000),
'YYYY-MM-DD HH:mm' 'YYYY-MM-DD HH:mm'
) )
obj.temp = ['/temp/', obj.id].join('') obj.temp = ['/temp/', obj.id].join('')
obj.shareUrl = [
window.location.protocol,
'//',
window.location.host,
obj.temp
].join('')
obj.items = JSON.parse(obj.items)
obj.itemsMap = new Map()
obj.items.forEach((item, idx) => {
let id = `${obj.id}:${idx + 1}`
obj.itemsMap.set(id, {...item, id})
})
return obj return obj
} }
@ -164,16 +189,28 @@
delimiters: ['${', '}'], delimiters: ['${', '}'],
data: function () { data: function () {
return { return {
temps: [],
tempsTable: { tempsTable: {
columns: [ columns: [
{name: 'id', align: 'left', label: 'ID', field: 'id'}, {name: 'id', align: 'left', label: 'ID', field: 'id'},
{name: 'name', align: 'left', label: 'Name', field: 'name'}, {name: 'name', align: 'left', label: 'Name', field: 'name'},
{ {
name: 'currency', name: 'wallet',
align: 'left', align: 'left',
label: 'Currency', label: 'Wallet',
field: 'currency' field: 'wallet'
},
{
name: 'lnurlwithdrawamount',
align: 'left',
label: 'LNURL Withdraw amount',
field: 'lnurlwithdrawamount'
},
{
name: 'lnurlpayamount',
align: 'left',
label: 'LNURL Pay amount',
field: 'lnurlpayamount'
} }
], ],
pagination: { pagination: {
@ -224,31 +261,15 @@
}, },
sendTPosData() { sendTPosData() {
const data = { const data = {
...this.formDialog.data, name: this.formDialog.data.name,
tip_options: lnurlwithdrawamount: this.formDialog.data.lnurlwithdrawamount,
this.formDialog.advanced.tips && this.formDialog.data.tip_options lnurlpayamount: this.formDialog.data.lnurlpayamount
? JSON.stringify(
this.formDialog.data.tip_options.map(str => parseInt(str))
)
: JSON.stringify([]),
tip_wallet:
(this.formDialog.advanced.tips &&
this.formDialog.data.tip_wallet) ||
'',
items: JSON.stringify(this.formDialog.data.items)
}
// delete withdrawbtwn if value is empty string, defaults to 10 minutes
if (this.formDialog.data.withdrawbtwn == '') {
delete data.withdrawbtwn
}
if (!this.formDialog.advanced.otc) {
data.withdrawlimit = null
data.withdrawpin = null
data.withdrawpremium = null
} }
const wallet = _.findWhere(this.g.user.wallets, { const wallet = _.findWhere(this.g.user.wallets, {
id: this.formDialog.data.wallet id: this.formDialog.data.wallet
}) })
console.log(data)
console.log(wallet)
if (data.id) { if (data.id) {
this.updateTPos(wallet, data) this.updateTPos(wallet, data)
} else { } else {
@ -334,24 +355,24 @@
const currency = _.findWhere(this.temps, {id: temp}).currency const currency = _.findWhere(this.temps, {id: temp}).currency
return LNbits.utils.formatCurrency(Number(price).toFixed(2), currency) return LNbits.utils.formatCurrency(Number(price).toFixed(2), currency)
}, },
openItemDialog(id) { openformDialog(id) {
const [tempId, itemId] = id.split(':') const [tempId, itemId] = id.split(':')
const temp = _.findWhere(this.temps, {id: tempId}) const temp = _.findWhere(this.temps, {id: tempId})
if (itemId) { if (itemId) {
const item = temp.itemsMap.get(id) const item = temp.itemsMap.get(id)
this.itemDialog.data = { this.formDialog.data = {
...item, ...item,
temp: tempId temp: tempId
} }
} else { } else {
this.itemDialog.data.temp = tempId this.formDialog.data.temp = tempId
} }
this.itemDialog.data.currency = temp.currency this.formDialog.data.currency = temp.currency
this.itemDialog.show = true this.formDialog.show = true
}, },
closeItemDialog() { closeformDialog() {
this.itemDialog.show = false this.formDialog.show = false
this.itemDialog.data = { this.formDialog.data = {
title: '', title: '',
image: '', image: '',
price: '', price: '',
@ -375,17 +396,17 @@
}) })
}, },
addItems() { addItems() {
const temp = _.findWhere(this.temps, {id: this.itemDialog.data.temp}) const temp = _.findWhere(this.temps, {id: this.formDialog.data.temp})
const wallet = _.findWhere(this.g.user.wallets, { const wallet = _.findWhere(this.g.user.wallets, {
id: temp.wallet id: temp.wallet
}) })
if (this.itemDialog.data.id) { if (this.formDialog.data.id) {
temp.itemsMap.set(this.itemDialog.data.id, this.itemDialog.data) temp.itemsMap.set(this.formDialog.data.id, this.formDialog.data)
} }
const data = { const data = {
items: this.itemDialog.data.id items: this.formDialog.data.id
? [...temp.itemsMap.values()] ? [...temp.itemsMap.values()]
: [...temp.items, this.itemDialog.data] : [...temp.items, this.formDialog.data]
} }
this.updateTempItems(temp.id, wallet, data) this.updateTempItems(temp.id, wallet, data)
}, },
@ -417,7 +438,7 @@
return obj.id == tempId return obj.id == tempId
}) })
this.temps.push(mapTemp(response.data)) this.temps.push(mapTemp(response.data))
this.closeItemDialog() this.closeformDialog()
}) })
.catch(error => { .catch(error => {
LNbits.utils.notifyApiError(error) LNbits.utils.notifyApiError(error)