From 257f5d34d277eb0027ebabc00ef97a98e9ebb239 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Thu, 2 Nov 2023 16:09:32 +0200 Subject: [PATCH] Fix update validations (#30) * fix: no `username` update * fix: update for old pay_links * chore: code format --- README.md | 8 +- __init__.py | 5 +- crud.py | 3 +- lnurl.py | 13 +- models.py | 2 +- static/js/index.js | 2 +- tasks.py | 14 +- templates/lnurlp/index.html | 297 ++++++++++++++++++++++++++++-------- views_api.py | 2 - 9 files changed, 252 insertions(+), 94 deletions(-) diff --git a/README.md b/README.md index 0c6021c..a3f4be3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # LNURLp - [LNbits](https://github.com/lnbits/lnbits) extension + For more about LNBits extension check [this tutorial](https://github.com/lnbits/lnbits/wiki/LNbits-Extensions) ## Create a static QR code or LNaddress people can use to pay over Lightning Network @@ -36,10 +37,10 @@ LNURL is a range of lightning-network standards that allow us to use lightning-n ## Update your LNURL-pay extension Now that the extensions are taken out of core LNbits we can update each extension separately without the need to reload or restart LNbits as a whole. -This new version of the extension will give you the option to add a Lightning Address to each LNURLpay link. +This new version of the extension will give you the option to add a Lightning Address to each LNURLpay link. - Open your LNbits instance as super admin (not as a regular user. You will find the SuperUser-ID in your server logs on restart of LNbits. Use that to bookmark and manage LNbits from there in the future.) -Now lets install the new version of a given extension like extensively [described in this guide](https://github.com/lnbits/lnbits/blob/main/docs/guide/extension-install.md#install-new-extension). In short: + Now lets install the new version of a given extension like extensively [described in this guide](https://github.com/lnbits/lnbits/blob/main/docs/guide/extension-install.md#install-new-extension). In short: - Go to "Mange extensions", click on "ALL", search for e.g. LNURLp, click on "Manage" - Open the details of the extension and click on version 0.2.1, click "Install". You´re done! @@ -55,7 +56,4 @@ Now you can receive sats to your newly created LN address. You will find this in [![lnurl-details.jpg](https://i.postimg.cc/zDwq1V2X/lnurl-details.jpg)](https://postimg.cc/3WwsXJHP) - - - diff --git a/__init__.py b/__init__.py index 291111b..5c0ccdb 100644 --- a/__init__.py +++ b/__init__.py @@ -1,17 +1,16 @@ import asyncio from typing import List +from environs import Env from fastapi import APIRouter +from loguru import logger from lnbits.db import Database from lnbits.helpers import template_renderer from lnbits.tasks import catch_everything_and_restart -from loguru import logger - from .nostr.event import Event from .nostr.key import PrivateKey, PublicKey -from environs import Env def generate_keys(private_key: str = ""): diff --git a/crud.py b/crud.py index de76cce..377484d 100644 --- a/crud.py +++ b/crud.py @@ -1,4 +1,3 @@ -import re from typing import List, Optional, Union from lnbits.helpers import urlsafe_short_hash @@ -105,7 +104,7 @@ async def get_pay_links(wallet_ids: Union[str, List[str]]) -> List[PayLink]: async def update_pay_link(link_id: str, **kwargs) -> Optional[PayLink]: - if "username" in kwargs and len(kwargs["username"]) > 0: + if "username" in kwargs and len(kwargs["username"] or "") > 0: await check_lnaddress_format(kwargs["username"]) await check_lnaddress_not_exists(kwargs["username"]) diff --git a/lnurl.py b/lnurl.py index 4bcfea3..d3703b1 100644 --- a/lnurl.py +++ b/lnurl.py @@ -3,18 +3,13 @@ from urllib.parse import urlparse from fastapi import Query, Request from lnurl import LnurlErrorResponse, LnurlPayActionResponse, LnurlPayResponse -from loguru import logger from starlette.exceptions import HTTPException from lnbits.core.services import create_invoice from lnbits.utils.exchange_rates import get_fiat_rate_satoshis -from . import lnurlp_ext -from .crud import increment_pay_link, get_pay_link, get_address_data -from loguru import logger -from urllib.parse import urlparse -import json -from . import nostr_publickey +from . import lnurlp_ext, nostr_publickey +from .crud import increment_pay_link @lnurlp_ext.get( @@ -132,7 +127,9 @@ async def api_lnurl_response(request: Request, link_id, lnaddress=False): if lnaddress: # for lnaddress, we have to set this otherwise the metadata won't have the identifier link.domain = urlparse(str(request.url)).netloc - callback = str(request.url_for("lnurlp.api_lnurl_lnaddr_callback", link_id=link.id)) + callback = str( + request.url_for("lnurlp.api_lnurl_lnaddr_callback", link_id=link.id) + ) else: callback = str(request.url_for("lnurlp.api_lnurl_callback", link_id=link.id)) diff --git a/models.py b/models.py index aae9b1b..e710558 100644 --- a/models.py +++ b/models.py @@ -24,7 +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) + zaps: Optional[bool] = Query(False) class PayLink(BaseModel): diff --git a/static/js/index.js b/static/js/index.js index 4c09507..ffbb53a 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -41,7 +41,7 @@ new Vue({ show: false, fixedAmount: true, data: { - zaps:false + zaps: false } }, qrCodeDialog: { diff --git a/tasks.py b/tasks.py index af736d5..d44948d 100644 --- a/tasks.py +++ b/tasks.py @@ -1,23 +1,21 @@ import asyncio import json +import time +from threading import Thread +from typing import List import httpx from loguru import logger +from websocket import WebSocketApp from lnbits.core.crud import update_payment_extra from lnbits.core.models import Payment from lnbits.helpers import get_current_extension_name from lnbits.tasks import register_invoice_listener -from websocket import WebSocketApp -from lnbits.settings import settings -from .crud import get_pay_link -from threading import Thread -from . import nostr_privatekey -from typing import List -import time +from . import nostr_privatekey +from .crud import get_pay_link from .nostr.event import Event -from .nostr.key import PrivateKey, PublicKey async def wait_for_paid_invoices(): diff --git a/templates/lnurlp/index.html b/templates/lnurlp/index.html index 544b332..914b0fc 100644 --- a/templates/lnurlp/index.html +++ b/templates/lnurlp/index.html @@ -4,7 +4,9 @@
- New pay link + New pay link @@ -15,7 +17,13 @@
Pay links
- + {% raw %}