Skip to content

Commit

Permalink
fixes lnurl
Browse files Browse the repository at this point in the history
  • Loading branch information
arcbtc committed Feb 12, 2025
1 parent 56f89aa commit 640721d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 10 additions & 5 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions views_lnurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 640721d

Please sign in to comment.