diff --git a/crud.py b/crud.py index d708e93..4104b37 100644 --- a/crud.py +++ b/crud.py @@ -58,10 +58,11 @@ async def create_pay_link(data: CreatePayLinkData, wallet_id: str) -> PayLink: comment_chars, currency, fiat_base_multiplier, - username + username, + zaps ) - VALUES (?, ?, ?, ?, ?, 0, 0, ?, ?, ?, ?, ?, ?, ?, ?, ?) + VALUES (?, ?, ?, ?, ?, 0, 0, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, ( link_id, @@ -78,6 +79,7 @@ async def create_pay_link(data: CreatePayLinkData, wallet_id: str) -> PayLink: data.currency, data.fiat_base_multiplier, data.username, + data.zaps, ), ) assert result diff --git a/lnurl.py b/lnurl.py index 38fd911..139a9f9 100644 --- a/lnurl.py +++ b/lnurl.py @@ -147,6 +147,7 @@ async def api_lnurl_response(request: Request, link_id, lnaddress=False): if link.comment_chars > 0: params["commentAllowed"] = link.comment_chars - params["allowsNostr"] = True - params["nostrPubkey"] = nostr_publickey.hex() + if link.zaps: + params["allowsNostr"] = True + params["nostrPubkey"] = nostr_publickey.hex() return params diff --git a/migrations.py b/migrations.py index 879bec3..705b55f 100644 --- a/migrations.py +++ b/migrations.py @@ -150,6 +150,13 @@ async def m006_redux(db): async def m007_add_lnaddress_username(db): """ - Add headers and body to webhooks + Add Lightning address to pay links """ await db.execute("ALTER TABLE lnurlp.pay_links ADD COLUMN username TEXT;") + + +async def m008_add_zap_enabled_column(db): + """ + Add Nostr zaps to pay links + """ + await db.execute("ALTER TABLE lnurlp.pay_links ADD COLUMN zaps BOOLEAN;") diff --git a/models.py b/models.py index 9611d41..1973ee9 100644 --- a/models.py +++ b/models.py @@ -24,6 +24,7 @@ class CreatePayLinkData(BaseModel): success_url: str = Query(None) fiat_base_multiplier: int = Query(100, ge=1) username: str = Query(None) + zaps: bool = Query(False) class PayLink(BaseModel): @@ -34,6 +35,7 @@ class PayLink(BaseModel): served_meta: int served_pr: int username: Optional[str] + zaps: Optional[bool] domain: Optional[str] webhook_url: Optional[str] webhook_headers: Optional[str] diff --git a/static/js/index.js b/static/js/index.js index 8edc055..e9951f1 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -40,7 +40,9 @@ new Vue({ formDialog: { show: false, fixedAmount: true, - data: {} + data: { + zaps:false + } }, qrCodeDialog: { show: false, @@ -140,7 +142,8 @@ new Vue({ 'success_url', 'comment_chars', 'currency', - 'username' + 'username', + 'zaps' ), (value, key) => (key === 'webhook_url' || diff --git a/tasks.py b/tasks.py index ca77b16..af736d5 100644 --- a/tasks.py +++ b/tasks.py @@ -72,9 +72,9 @@ async def on_invoice_paid(payment: Payment): ) # NIP-57 + # load the zap request nostr = payment.extra.get("nostr") - if nostr: - + if pay_link and pay_link.zaps and nostr: event_json = json.loads(nostr) def get_tag(event_json, tag): @@ -114,7 +114,7 @@ async def on_invoice_paid(payment: Payment): wsts: List[Thread] = [] # # send zap via nostrclient - # ws, wst = send_zap(f"ws://localhost:{settings.port}/nostrclient/api/v1/relay") + # ws, wst = send_zap(f"wss://localhost:{settings.port}/nostrclient/api/v1/relay") # wss += [ws] # wsts += [wst] @@ -138,7 +138,6 @@ async def on_invoice_paid(payment: Payment): async def mark_webhook_sent( payment_hash: str, status: int, is_success: bool, reason_phrase="", text="" ) -> None: - await update_payment_extra( payment_hash, { diff --git a/templates/lnurlp/index.html b/templates/lnurlp/index.html index 1ecd490..4b8202e 100644 --- a/templates/lnurlp/index.html +++ b/templates/lnurlp/index.html @@ -26,7 +26,7 @@ > {% raw %} @@ -125,7 +132,7 @@
- {{SITE_TITLE}} LNURL-pay extension + {{ SITE_TITLE }} LNURL-pay extension
@@ -152,29 +159,30 @@ > - + filled + dense + v-model.trim="formDialog.data.description" + type="text" + label="Item description *" + > +
- +
-
-   @ {% raw %} {{domain}} {% endraw %} +
+ +   @ {% raw %} {{ domain }} {% endraw %} +
-
-
+
- - - - - - - - + + +
LNURL
+
+
+ + +
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+ + +
+
+
+ +
Nostr
+
+
+ +
+
+
+
+
ID: {{ qrCodeDialog.data.id }}
Amount: {{ qrCodeDialog.data.amount }}
{{ qrCodeDialog.data.currency }} price: {{ - fiatRates[qrCodeDialog.data.currency] ? - fiatRates[qrCodeDialog.data.currency] + ' sat' : 'Loading...' }}
{{ qrCodeDialog.data.currency }} price: + {{ + fiatRates[qrCodeDialog.data.currency] + ? fiatRates[qrCodeDialog.data.currency] + ' sat' + : 'Loading...' + }}
- Accepts comments: {{ qrCodeDialog.data.comments }}
+ Accepts comments: {{ qrCodeDialog.data.comments + }}
Dispatches webhook to: {{ qrCodeDialog.data.webhook }}
On success: {{ qrCodeDialog.data.success }}
- Lightning Address: {{ qrCodeDialog.data.username}}@{{domain}} -
+ Lightning Address: + {{ qrCodeDialog.data.username }}@{{ domain }} +

{% endraw %}