feat: add disable option for LNURLw (#70)
This commit is contained in:
parent
ab96594f70
commit
74852e3494
7 changed files with 76 additions and 7 deletions
|
|
@ -139,3 +139,9 @@ async def m007_add_created_at_timestamp(db):
|
|||
"ALTER TABLE withdraw.withdraw_link "
|
||||
f"ADD COLUMN created_at TIMESTAMP DEFAULT {db.timestamp_column_default}"
|
||||
)
|
||||
|
||||
|
||||
async def m008_add_enabled_column(db):
|
||||
await db.execute(
|
||||
"ALTER TABLE withdraw.withdraw_link ADD COLUMN enabled BOOLEAN DEFAULT true;"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ class CreateWithdrawData(BaseModel):
|
|||
webhook_headers: str = Query(None)
|
||||
webhook_body: str = Query(None)
|
||||
custom_url: str = Query(None)
|
||||
enabled: bool = Query(True)
|
||||
|
||||
|
||||
class WithdrawLink(BaseModel):
|
||||
|
|
@ -37,6 +38,7 @@ class WithdrawLink(BaseModel):
|
|||
webhook_body: str = Query(None)
|
||||
custom_url: str = Query(None)
|
||||
created_at: datetime
|
||||
enabled: bool = Query(True)
|
||||
lnurl: str | None = Field(
|
||||
default=None,
|
||||
no_database=True,
|
||||
|
|
|
|||
|
|
@ -68,7 +68,8 @@ window.app = Vue.createApp({
|
|||
data: {
|
||||
is_unique: false,
|
||||
use_custom: false,
|
||||
has_webhook: false
|
||||
has_webhook: false,
|
||||
enabled: true
|
||||
}
|
||||
},
|
||||
simpleformDialog: {
|
||||
|
|
@ -78,7 +79,8 @@ window.app = Vue.createApp({
|
|||
use_custom: false,
|
||||
title: 'Vouchers',
|
||||
min_withdrawable: 0,
|
||||
wait_time: 1
|
||||
wait_time: 1,
|
||||
enabled: true
|
||||
}
|
||||
},
|
||||
qrCodeDialog: {
|
||||
|
|
@ -125,13 +127,15 @@ window.app = Vue.createApp({
|
|||
this.formDialog.data = {
|
||||
is_unique: false,
|
||||
use_custom: false,
|
||||
has_webhook: false
|
||||
has_webhook: false,
|
||||
enabled: true
|
||||
}
|
||||
},
|
||||
simplecloseFormDialog() {
|
||||
this.simpleformDialog.data = {
|
||||
is_unique: false,
|
||||
use_custom: false
|
||||
use_custom: false,
|
||||
enabled: true
|
||||
}
|
||||
},
|
||||
openQrCodeDialog(linkId) {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,12 @@
|
|||
<q-badge v-if="spent" color="red" class="q-mb-md"
|
||||
>Withdraw is spent.</q-badge
|
||||
>
|
||||
<q-badge v-if="spent" color="red" class="q-mb-md"
|
||||
>Withdraw is spent.</q-badge
|
||||
>
|
||||
<q-badge v-else-if="!enabled" color="grey" class="q-mb-md"
|
||||
>Withdraw is disabled.</q-badge
|
||||
>
|
||||
<a v-else class="text-secondary" :href="link">
|
||||
<lnbits-qrcode-lnurl
|
||||
prefix="lnurlw"
|
||||
|
|
@ -57,7 +63,8 @@
|
|||
spent: {{ 'true' if spent else 'false' }},
|
||||
url: '{{ lnurl_url }}',
|
||||
lnurl: '',
|
||||
nfcTagWriting: false
|
||||
nfcTagWriting: false,
|
||||
enabled: {{ 'true' if enabled else 'false' }}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@
|
|||
>
|
||||
<template v-slot:header="props">
|
||||
<q-tr :props="props">
|
||||
<q-th auto-width></q-th>
|
||||
<q-th auto-width></q-th>
|
||||
<q-th auto-width></q-th>
|
||||
<q-th
|
||||
|
|
@ -51,6 +52,19 @@
|
|||
</template>
|
||||
<template v-slot:body="props">
|
||||
<q-tr :props="props">
|
||||
<q-td auto-width>
|
||||
<q-icon
|
||||
name="power_settings_new"
|
||||
:color="props.row.enabled ? 'green' : 'red'"
|
||||
size="xs"
|
||||
>
|
||||
<q-tooltip>
|
||||
<span
|
||||
v-text="props.row.enabled ? 'Withdraw link is enabled' : 'Withdraw link is disabled'"
|
||||
></span>
|
||||
</q-tooltip>
|
||||
</q-icon>
|
||||
</q-td>
|
||||
<q-td auto-width>
|
||||
<q-btn
|
||||
unelevated
|
||||
|
|
@ -238,6 +252,20 @@
|
|||
hint="Custom data as JSON string, will get posted along with webhook 'body' field."
|
||||
></q-input>
|
||||
<q-list>
|
||||
<q-item tag="label" class="rounded-borders">
|
||||
<q-item-section avatar>
|
||||
<q-checkbox
|
||||
v-model="formDialog.data.enabled"
|
||||
color="primary"
|
||||
></q-checkbox>
|
||||
</q-item-section>
|
||||
<q-item-section>
|
||||
<q-item-label>Enable / Disable </q-item-label>
|
||||
<q-item-label caption
|
||||
>You can enable or disable these vouchers</q-item-label
|
||||
>
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
<q-item tag="label" class="rounded-borders">
|
||||
<q-item-section avatar>
|
||||
<q-checkbox
|
||||
|
|
@ -350,6 +378,20 @@
|
|||
label="Number of vouchers"
|
||||
></q-input>
|
||||
<q-list>
|
||||
<q-item tag="label" class="rounded-borders">
|
||||
<q-item-section avatar>
|
||||
<q-checkbox
|
||||
v-model="simpleformDialog.data.enabled"
|
||||
color="primary"
|
||||
></q-checkbox>
|
||||
</q-item-section>
|
||||
<q-item-section>
|
||||
<q-item-label>Enable / Disable </q-item-label>
|
||||
<q-item-label caption
|
||||
>You can enable or disable these vouchers</q-item-label
|
||||
>
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
<q-item tag="label" class="rounded-borders">
|
||||
<q-item-section avatar>
|
||||
<q-checkbox
|
||||
|
|
|
|||
2
views.py
2
views.py
|
|
@ -47,6 +47,7 @@ async def display(request: Request, link_id):
|
|||
"request": request,
|
||||
"spent": link.is_spent,
|
||||
"lnurl_url": str(lnurl.url),
|
||||
"enabled": link.enabled,
|
||||
},
|
||||
)
|
||||
|
||||
|
|
@ -60,7 +61,6 @@ async def print_qr(request: Request, link_id):
|
|||
)
|
||||
|
||||
if link.uses == 0:
|
||||
|
||||
return withdraw_renderer().TemplateResponse(
|
||||
"withdraw/print_qr.html",
|
||||
{"request": request, "link": link.json(), "unique": False},
|
||||
|
|
|
|||
|
|
@ -43,6 +43,9 @@ async def api_lnurl_response(
|
|||
if not link:
|
||||
return LnurlErrorResponse(reason="Withdraw link does not exist.")
|
||||
|
||||
if not link.enabled:
|
||||
return LnurlErrorResponse(reason="Withdraw link is disabled.")
|
||||
|
||||
if link.is_spent:
|
||||
return LnurlErrorResponse(reason="Withdraw is spent.")
|
||||
|
||||
|
|
@ -86,11 +89,13 @@ async def api_lnurl_callback(
|
|||
pr: str,
|
||||
id_unique_hash: str | None = None,
|
||||
) -> LnurlErrorResponse | LnurlSuccessResponse:
|
||||
|
||||
link = await get_withdraw_link_by_hash(unique_hash)
|
||||
if not link:
|
||||
return LnurlErrorResponse(reason="withdraw link not found.")
|
||||
|
||||
if not link.enabled:
|
||||
return LnurlErrorResponse(reason="Withdraw link is disabled.")
|
||||
|
||||
if link.is_spent:
|
||||
return LnurlErrorResponse(reason="withdraw is spent.")
|
||||
|
||||
|
|
@ -194,6 +199,9 @@ async def api_lnurl_multi_response(
|
|||
if not link:
|
||||
return LnurlErrorResponse(reason="Withdraw link does not exist.")
|
||||
|
||||
if not link.enabled:
|
||||
return LnurlErrorResponse(reason="Withdraw link is disabled.")
|
||||
|
||||
if link.is_spent:
|
||||
return LnurlErrorResponse(reason="Withdraw is spent.")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue