Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;"
)
2 changes: 2 additions & 0 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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,
Expand Down
12 changes: 8 additions & 4 deletions static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ window.app = Vue.createApp({
data: {
is_unique: false,
use_custom: false,
has_webhook: false
has_webhook: false,
enabled: true
}
},
simpleformDialog: {
Expand All @@ -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: {
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 8 additions & 1 deletion templates/withdraw/display.html
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -57,7 +63,8 @@ <h6 class="text-subtitle1 q-mb-sm q-mt-none">
spent: {{ 'true' if spent else 'false' }},
url: '{{ lnurl_url }}',
lnurl: '',
nfcTagWriting: false
nfcTagWriting: false,
enabled: {{ 'true' if enabled else 'false' }}
}
}
})
Expand Down
42 changes: 42 additions & 0 deletions templates/withdraw/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ <h5 class="text-subtitle1 q-my-none">Withdraw links</h5>
>
<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
Expand All @@ -51,6 +52,19 @@ <h5 class="text-subtitle1 q-my-none">Withdraw links</h5>
</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
Expand Down Expand Up @@ -238,6 +252,20 @@ <h6 class="text-subtitle1 q-my-none">
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
Expand Down Expand Up @@ -350,6 +378,20 @@ <h6 class="text-subtitle1 q-my-none">
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
Expand Down
2 changes: 1 addition & 1 deletion views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
)

Expand All @@ -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},
Expand Down
10 changes: 9 additions & 1 deletion views_lnurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand Down Expand Up @@ -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.")

Expand Down Expand Up @@ -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.")

Expand Down