Skip to content

Commit

Permalink
fix: v1 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
motorina0 committed Oct 4, 2024
1 parent 5e25d80 commit b79b88f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
19 changes: 5 additions & 14 deletions crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Optional, Union

from lnbits.db import Database
from lnbits.helpers import insert_query, update_query, urlsafe_short_hash
from lnbits.helpers import urlsafe_short_hash

from .models import CreateTposData, LnurlCharge, Tpos, TposClean

Expand All @@ -12,10 +12,7 @@
async def create_tpos(data: CreateTposData) -> Tpos:
tpos_id = urlsafe_short_hash()
tpos = Tpos(id=tpos_id, **data.dict())
await db.execute(
insert_query("tpos.pos", tpos),
tpos.dict(),
)
await db.insert("tpos.pos", tpos)
return tpos


Expand All @@ -42,7 +39,7 @@ async def start_lnurlcharge(tpos: Tpos) -> LnurlCharge:
token = urlsafe_short_hash()
await db.execute(
"""
INSERT INTO tpos.withdraws (id, tpos_id, amount)
INSERT INTO tpos.withdraws (id, tpos_id)
VALUES (:id, :tpos_id)
""",
{"id": token, "tpos_id": tpos.id},
Expand All @@ -60,10 +57,7 @@ async def get_lnurlcharge(lnurlcharge_id: str) -> Optional[LnurlCharge]:


async def update_lnurlcharge(data: LnurlCharge) -> LnurlCharge:
await db.execute(
update_query("tpos.withdraws", data),
data.dict(),
)
await db.update("tpos.withdraws", data)

lnurlcharge = await get_lnurlcharge(data.id)
assert lnurlcharge, "Withdraw couldn't be retrieved"
Expand All @@ -77,10 +71,7 @@ async def get_clean_tpos(tpos_id: str) -> Optional[TposClean]:


async def update_tpos(tpos: Tpos) -> Tpos:
await db.execute(
update_query("tpos.pos", tpos),
tpos.dict(),
)
await db.update("tpos.pos", tpos)
return tpos


Expand Down
2 changes: 1 addition & 1 deletion views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def tpos_renderer():
@tpos_generic_router.get("/", response_class=HTMLResponse)
async def index(request: Request, user: User = Depends(check_user_exists)):
return tpos_renderer().TemplateResponse(
"tpos/index.html", {"request": request, "user": user.dict()}
"tpos/index.html", {"request": request, "user": user.json()}
)


Expand Down
6 changes: 2 additions & 4 deletions views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,9 @@ async def api_tpos_check_invoice(tpos_id: str, payment_hash: str):
async def api_tpos_atm_pin_check(tpos_id: str, atmpin: int) -> LnurlCharge:
tpos = await get_tpos(tpos_id)
if not tpos:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="TPoS does not exist."
)
raise HTTPException(HTTPStatus.NOT_FOUND, "TPoS does not exist.")
if int(tpos.withdraw_pin or 0) != int(atmpin):
raise HTTPException(status_code=HTTPStatus.NOT_FOUND, detail="Wrong PIN.")
raise HTTPException(HTTPStatus.NOT_FOUND, "Wrong PIN.")
token = await start_lnurlcharge(tpos)
return token

Expand Down

0 comments on commit b79b88f

Please sign in to comment.