Skip to content

Commit 74852e3

Browse files
feat: add disable option for LNURLw (#70)
1 parent ab96594 commit 74852e3

7 files changed

Lines changed: 76 additions & 7 deletions

File tree

migrations.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,9 @@ async def m007_add_created_at_timestamp(db):
139139
"ALTER TABLE withdraw.withdraw_link "
140140
f"ADD COLUMN created_at TIMESTAMP DEFAULT {db.timestamp_column_default}"
141141
)
142+
143+
144+
async def m008_add_enabled_column(db):
145+
await db.execute(
146+
"ALTER TABLE withdraw.withdraw_link ADD COLUMN enabled BOOLEAN DEFAULT true;"
147+
)

models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class CreateWithdrawData(BaseModel):
1515
webhook_headers: str = Query(None)
1616
webhook_body: str = Query(None)
1717
custom_url: str = Query(None)
18+
enabled: bool = Query(True)
1819

1920

2021
class WithdrawLink(BaseModel):
@@ -37,6 +38,7 @@ class WithdrawLink(BaseModel):
3738
webhook_body: str = Query(None)
3839
custom_url: str = Query(None)
3940
created_at: datetime
41+
enabled: bool = Query(True)
4042
lnurl: str | None = Field(
4143
default=None,
4244
no_database=True,

static/js/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ window.app = Vue.createApp({
6868
data: {
6969
is_unique: false,
7070
use_custom: false,
71-
has_webhook: false
71+
has_webhook: false,
72+
enabled: true
7273
}
7374
},
7475
simpleformDialog: {
@@ -78,7 +79,8 @@ window.app = Vue.createApp({
7879
use_custom: false,
7980
title: 'Vouchers',
8081
min_withdrawable: 0,
81-
wait_time: 1
82+
wait_time: 1,
83+
enabled: true
8284
}
8385
},
8486
qrCodeDialog: {
@@ -125,13 +127,15 @@ window.app = Vue.createApp({
125127
this.formDialog.data = {
126128
is_unique: false,
127129
use_custom: false,
128-
has_webhook: false
130+
has_webhook: false,
131+
enabled: true
129132
}
130133
},
131134
simplecloseFormDialog() {
132135
this.simpleformDialog.data = {
133136
is_unique: false,
134-
use_custom: false
137+
use_custom: false,
138+
enabled: true
135139
}
136140
},
137141
openQrCodeDialog(linkId) {

templates/withdraw/display.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
<q-badge v-if="spent" color="red" class="q-mb-md"
88
>Withdraw is spent.</q-badge
99
>
10+
<q-badge v-if="spent" color="red" class="q-mb-md"
11+
>Withdraw is spent.</q-badge
12+
>
13+
<q-badge v-else-if="!enabled" color="grey" class="q-mb-md"
14+
>Withdraw is disabled.</q-badge
15+
>
1016
<a v-else class="text-secondary" :href="link">
1117
<lnbits-qrcode-lnurl
1218
prefix="lnurlw"
@@ -57,7 +63,8 @@ <h6 class="text-subtitle1 q-mb-sm q-mt-none">
5763
spent: {{ 'true' if spent else 'false' }},
5864
url: '{{ lnurl_url }}',
5965
lnurl: '',
60-
nfcTagWriting: false
66+
nfcTagWriting: false,
67+
enabled: {{ 'true' if enabled else 'false' }}
6168
}
6269
}
6370
})

templates/withdraw/index.html

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ <h5 class="text-subtitle1 q-my-none">Withdraw links</h5>
3838
>
3939
<template v-slot:header="props">
4040
<q-tr :props="props">
41+
<q-th auto-width></q-th>
4142
<q-th auto-width></q-th>
4243
<q-th auto-width></q-th>
4344
<q-th
@@ -51,6 +52,19 @@ <h5 class="text-subtitle1 q-my-none">Withdraw links</h5>
5152
</template>
5253
<template v-slot:body="props">
5354
<q-tr :props="props">
55+
<q-td auto-width>
56+
<q-icon
57+
name="power_settings_new"
58+
:color="props.row.enabled ? 'green' : 'red'"
59+
size="xs"
60+
>
61+
<q-tooltip>
62+
<span
63+
v-text="props.row.enabled ? 'Withdraw link is enabled' : 'Withdraw link is disabled'"
64+
></span>
65+
</q-tooltip>
66+
</q-icon>
67+
</q-td>
5468
<q-td auto-width>
5569
<q-btn
5670
unelevated
@@ -238,6 +252,20 @@ <h6 class="text-subtitle1 q-my-none">
238252
hint="Custom data as JSON string, will get posted along with webhook 'body' field."
239253
></q-input>
240254
<q-list>
255+
<q-item tag="label" class="rounded-borders">
256+
<q-item-section avatar>
257+
<q-checkbox
258+
v-model="formDialog.data.enabled"
259+
color="primary"
260+
></q-checkbox>
261+
</q-item-section>
262+
<q-item-section>
263+
<q-item-label>Enable / Disable </q-item-label>
264+
<q-item-label caption
265+
>You can enable or disable these vouchers</q-item-label
266+
>
267+
</q-item-section>
268+
</q-item>
241269
<q-item tag="label" class="rounded-borders">
242270
<q-item-section avatar>
243271
<q-checkbox
@@ -350,6 +378,20 @@ <h6 class="text-subtitle1 q-my-none">
350378
label="Number of vouchers"
351379
></q-input>
352380
<q-list>
381+
<q-item tag="label" class="rounded-borders">
382+
<q-item-section avatar>
383+
<q-checkbox
384+
v-model="simpleformDialog.data.enabled"
385+
color="primary"
386+
></q-checkbox>
387+
</q-item-section>
388+
<q-item-section>
389+
<q-item-label>Enable / Disable </q-item-label>
390+
<q-item-label caption
391+
>You can enable or disable these vouchers</q-item-label
392+
>
393+
</q-item-section>
394+
</q-item>
353395
<q-item tag="label" class="rounded-borders">
354396
<q-item-section avatar>
355397
<q-checkbox

views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ async def display(request: Request, link_id):
4747
"request": request,
4848
"spent": link.is_spent,
4949
"lnurl_url": str(lnurl.url),
50+
"enabled": link.enabled,
5051
},
5152
)
5253

@@ -60,7 +61,6 @@ async def print_qr(request: Request, link_id):
6061
)
6162

6263
if link.uses == 0:
63-
6464
return withdraw_renderer().TemplateResponse(
6565
"withdraw/print_qr.html",
6666
{"request": request, "link": link.json(), "unique": False},

views_lnurl.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ async def api_lnurl_response(
4343
if not link:
4444
return LnurlErrorResponse(reason="Withdraw link does not exist.")
4545

46+
if not link.enabled:
47+
return LnurlErrorResponse(reason="Withdraw link is disabled.")
48+
4649
if link.is_spent:
4750
return LnurlErrorResponse(reason="Withdraw is spent.")
4851

@@ -86,11 +89,13 @@ async def api_lnurl_callback(
8689
pr: str,
8790
id_unique_hash: str | None = None,
8891
) -> LnurlErrorResponse | LnurlSuccessResponse:
89-
9092
link = await get_withdraw_link_by_hash(unique_hash)
9193
if not link:
9294
return LnurlErrorResponse(reason="withdraw link not found.")
9395

96+
if not link.enabled:
97+
return LnurlErrorResponse(reason="Withdraw link is disabled.")
98+
9499
if link.is_spent:
95100
return LnurlErrorResponse(reason="withdraw is spent.")
96101

@@ -194,6 +199,9 @@ async def api_lnurl_multi_response(
194199
if not link:
195200
return LnurlErrorResponse(reason="Withdraw link does not exist.")
196201

202+
if not link.enabled:
203+
return LnurlErrorResponse(reason="Withdraw link is disabled.")
204+
197205
if link.is_spent:
198206
return LnurlErrorResponse(reason="Withdraw is spent.")
199207

0 commit comments

Comments
 (0)