Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Create github release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -19,7 +19,7 @@ jobs:
needs: [release]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
token: ${{ secrets.EXT_GITHUB }}
repository: lnbits/lnbits-extensions
Expand Down
24 changes: 12 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,42 @@ format: prettier black ruff
check: mypy pyright checkblack checkruff checkprettier

prettier:
poetry run ./node_modules/.bin/prettier --write .
uv run ./node_modules/.bin/prettier --write .
pyright:
poetry run ./node_modules/.bin/pyright
uv run ./node_modules/.bin/pyright

mypy:
poetry run mypy .
uv run mypy .

black:
poetry run black .
uv run black .

ruff:
poetry run ruff check . --fix
uv run ruff check . --fix

checkruff:
poetry run ruff check .
uv run ruff check .

checkprettier:
poetry run ./node_modules/.bin/prettier --check .
uv run ./node_modules/.bin/prettier --check .

checkblack:
poetry run black --check .
uv run black --check .

checkeditorconfig:
editorconfig-checker

test:
PYTHONUNBUFFERED=1 \
DEBUG=true \
poetry run pytest
uv run pytest
install-pre-commit-hook:
@echo "Installing pre-commit hook to git"
@echo "Uninstall the hook with poetry run pre-commit uninstall"
poetry run pre-commit install
@echo "Uninstall the hook with uv run pre-commit uninstall"
uv run pre-commit install

pre-commit:
poetry run pre-commit run --all-files
uv run pre-commit run --all-files


checkbundle:
Expand Down
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
offlineshop_ext.include_router(offlineshop_api_router)
offlineshop_ext.include_router(offlineshop_lnurl_router)

__all__ = ["offlineshop_ext", "offlineshop_static_files", "db"]
__all__ = ["db", "offlineshop_ext", "offlineshop_static_files"]
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "OfflineShop",
"short_description": "Receive payments for products offline!",
"tile": "/offlineshop/static/image/offlineshop.png",
"version": "1.1.0",
"version": "1.1.1",
"min_lnbits_version": "1.3.0",
"contributors": [
{
Expand Down
8 changes: 3 additions & 5 deletions crud.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Optional

from lnbits.db import Database
from lnbits.helpers import urlsafe_short_hash

Expand All @@ -16,15 +14,15 @@ async def create_shop(data: CreateShop) -> Shop:
return shop


async def get_shop(shop_id: str) -> Optional[Shop]:
async def get_shop(shop_id: str) -> Shop | None:
return await db.fetchone(
"SELECT * FROM offlineshop.shops WHERE id = :id",
{"id": shop_id},
Shop,
)


async def get_or_create_shop_by_wallet(wallet: str) -> Optional[Shop]:
async def get_or_create_shop_by_wallet(wallet: str) -> Shop | None:
shop = await db.fetchone(
"SELECT * FROM offlineshop.shops WHERE wallet = :wallet",
{"wallet": wallet},
Expand Down Expand Up @@ -52,7 +50,7 @@ async def update_item(item: Item) -> Item:
return item


async def get_item(item_id: str) -> Optional[Item]:
async def get_item(item_id: str) -> Item | None:
return await db.fetchone(
"SELECT * FROM offlineshop.items WHERE id = :id LIMIT 1",
{"id": item_id},
Expand Down
23 changes: 7 additions & 16 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
import hashlib
import json
from collections import OrderedDict
from typing import Optional

from lnurl import encode as lnurl_encode
from fastapi import Request
from lnurl.types import LnurlPayMetadata
from pydantic import BaseModel
from starlette.requests import Request

from .helpers import totp

Expand Down Expand Up @@ -58,8 +56,8 @@ def get_word(self, payment_hash):

class CreateShop(BaseModel):
wallet: str
method: Optional[str] = "wordlist"
wordlist: Optional[str] = None
method: str | None = "wordlist"
wordlist: str | None = None


class Shop(BaseModel):
Expand Down Expand Up @@ -90,21 +88,14 @@ class Item(BaseModel):
id: str
name: str
description: str
image: Optional[str]
enabled: Optional[bool] = True
image: str | None = None
enabled: bool | None = True
price: float
unit: str

def lnurl(self, req: Request) -> str:
return lnurl_encode(
str(req.url_for("offlineshop.lnurl_response", item_id=self.id))
)

def values(self, req: Request):
values = self.dict()
values["lnurl"] = lnurl_encode(
str(req.url_for("offlineshop.lnurl_response", item_id=self.id))
)
values["url"] = str(req.url_for("offlineshop.lnurl_response", item_id=self.id))
return values

@property
Expand All @@ -127,4 +118,4 @@ class CreateItem(BaseModel):
description: str
price: float
unit: str
image: Optional[str] = None
image: str | None = None
Loading