From 640721d5ca89cb86c58fb4a7ebc703cb4626f3aa Mon Sep 17 00:00:00 2001 From: arcbtc Date: Wed, 12 Feb 2025 17:08:55 +0000 Subject: [PATCH] fixes lnurl --- models.py | 15 ++++++++++----- views_lnurl.py | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/models.py b/models.py index 1213d90..5f0a988 100644 --- a/models.py +++ b/models.py @@ -106,16 +106,21 @@ def values(self, req: Request): str(req.url_for("offlineshop.lnurl_response", item_id=self.id)) ) return values - - async def lnurlpay_metadata(self) -> LnurlPayMetadata: - metadata = [["text/plain", self.description]] + + @property + def lnurlpay_metadata(self) -> LnurlPayMetadata: + metadata = [("text/plain", self.description)] if self.image: - metadata.append(self.image.split(":")[1].split(",")) + try: + image_tuple = tuple(self.image.split(":")[1].split(",")[:2]) + if len(image_tuple) == 2: + metadata.append(image_tuple) + except IndexError: + pass return LnurlPayMetadata(json.dumps(metadata)) - class CreateItem(BaseModel): name: str description: str diff --git a/views_lnurl.py b/views_lnurl.py index 525e411..32efeb8 100644 --- a/views_lnurl.py +++ b/views_lnurl.py @@ -45,7 +45,7 @@ async def lnurl_response(req: Request, item_id: str) -> dict: callback=url, minSendable=MilliSatoshi(price_msat), maxSendable=MilliSatoshi(price_msat), - metadata=await item.lnurlpay_metadata(), + metadata=item.lnurlpay_metadata, ) return resp.dict() @@ -84,7 +84,7 @@ async def lnurl_callback(request: Request, item_id: str): wallet_id=shop.wallet, amount=int(amount_received / 1000), memo=item.name, - unhashed_description=(await item.lnurlpay_metadata()).encode(), + unhashed_description=item.lnurlpay_metadata.encode(), extra={"tag": "offlineshop", "item": item.id}, ) except Exception as exc: