initial
This commit is contained in:
parent
5574fa7263
commit
395b4379a4
12 changed files with 33 additions and 34 deletions
|
|
@ -24,7 +24,6 @@ def scrub_renderer():
|
|||
return template_renderer(["lnbits/extensions/scrub/templates"])
|
||||
|
||||
|
||||
from .lnurl import * # noqa
|
||||
from .tasks import wait_for_paid_invoices
|
||||
from .views import * # noqa
|
||||
from .views_api import * # noqa
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ from typing import List, Optional, Union
|
|||
|
||||
from lnbits.db import SQLITE
|
||||
from . import db
|
||||
from .models import ScrubLink, CreateScrubLinkData
|
||||
from .models import ScrubLink
|
||||
|
||||
|
||||
async def create_scrub_link(wallet_id: str, data: CreateSatsDiceLink) -> satsdiceLink:
|
||||
async def create_scrub_link(wallet_id: str, data: ScrubLink) -> ScrubLink:
|
||||
satsdice_id = urlsafe_short_hash()
|
||||
await db.execute(
|
||||
"""
|
||||
|
|
@ -29,14 +29,14 @@ async def create_scrub_link(wallet_id: str, data: CreateSatsDiceLink) -> satsdic
|
|||
return link
|
||||
|
||||
|
||||
async def get_scrub_link(link_id: str) -> Optional[satsdiceLink]:
|
||||
async def get_scrub_link(link_id: str) -> Optional[ScrubLink]:
|
||||
row = await db.fetchone(
|
||||
"SELECT * FROM scrub.scrub_links WHERE id = ?", (link_id,)
|
||||
)
|
||||
return satsdiceLink(**row) if row else None
|
||||
return ScrubLink(**row) if row else None
|
||||
|
||||
|
||||
async def get_scrub_links(wallet_ids: Union[str, List[str]]) -> List[satsdiceLink]:
|
||||
async def get_scrub_links(wallet_ids: Union[str, List[str]]) -> List[ScrubLink]:
|
||||
if isinstance(wallet_ids, str):
|
||||
wallet_ids = [wallet_ids]
|
||||
|
||||
|
|
@ -48,10 +48,10 @@ async def get_scrub_links(wallet_ids: Union[str, List[str]]) -> List[satsdiceLin
|
|||
""",
|
||||
(*wallet_ids,),
|
||||
)
|
||||
return [satsdiceLink(**row) for row in rows]
|
||||
return [ScrubLink(**row) for row in rows]
|
||||
|
||||
|
||||
async def update_scrub_link(link_id: int, **kwargs) -> Optional[satsdiceLink]:
|
||||
async def update_scrub_link(link_id: int, **kwargs) -> Optional[ScrubLink]:
|
||||
q = ", ".join([f"{field[0]} = ?" for field in kwargs.items()])
|
||||
await db.execute(
|
||||
f"UPDATE scrub.scrub_links SET {q} WHERE id = ?",
|
||||
|
|
@ -60,7 +60,7 @@ async def update_scrub_link(link_id: int, **kwargs) -> Optional[satsdiceLink]:
|
|||
row = await db.fetchone(
|
||||
"SELECT * FROM scrub.scrub_links WHERE id = ?", (link_id,)
|
||||
)
|
||||
return satsdiceLink(**row) if row else None
|
||||
return ScrubLink(**row) if row else None
|
||||
|
||||
async def delete_scrub_link(link_id: int) -> None:
|
||||
await db.execute("DELETE FROM scrub.scrub_links WHERE id = ?", (link_id,))
|
||||
|
|
|
|||
|
|
@ -4,10 +4,16 @@ from starlette.requests import Request
|
|||
from fastapi.param_functions import Query
|
||||
from typing import Optional, Dict
|
||||
from lnbits.lnurl import encode as lnurl_encode # type: ignore
|
||||
from lnurl.types import LnurlScrubMetadata # type: ignore
|
||||
from sqlite3 import Row
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class CreateScrubLink(BaseModel):
|
||||
wallet: str
|
||||
description: str
|
||||
payoraddress: str
|
||||
|
||||
|
||||
class ScrubLink(BaseModel):
|
||||
id: int
|
||||
wallet: str
|
||||
|
|
@ -22,7 +28,3 @@ class ScrubLink(BaseModel):
|
|||
def lnurl(self, req: Request) -> str:
|
||||
url = req.url_for("scrub.api_lnurl_response", link_id=self.id)
|
||||
return lnurl_encode(url)
|
||||
|
||||
@property
|
||||
def scrubay_metadata(self) -> LnurlScrubMetadata:
|
||||
return LnurlScrubMetadata(json.dumps([["text/plain", self.description]]))
|
||||
|
|
@ -106,11 +106,7 @@ new Vue({
|
|||
const wallet = _.findWhere(this.g.user.wallets, {
|
||||
id: this.formDialog.data.wallet
|
||||
})
|
||||
var data = _.omit(this.formDialog.data, 'wallet')
|
||||
|
||||
if (this.formDialog.fixedAmount) data.max = data.min
|
||||
if (data.currency === 'satoshis') data.currency = null
|
||||
if (isNaN(parseInt(data.comment_chars))) data.comment_chars = 0
|
||||
console.log(wallet)
|
||||
|
||||
if (data.id) {
|
||||
this.updateScrubLink(wallet, data)
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@ import json
|
|||
import httpx
|
||||
|
||||
from lnbits.core import db as core_db
|
||||
from lnbits.core.models import Scrubment
|
||||
from .models import ScrubLink
|
||||
from lnbits.tasks import register_invoice_listener
|
||||
|
||||
from .crud import get_pay_link
|
||||
from .crud import get_scrub_link
|
||||
|
||||
|
||||
async def wait_for_paid_invoices():
|
||||
|
|
@ -18,7 +18,7 @@ async def wait_for_paid_invoices():
|
|||
await on_invoice_paid(payment)
|
||||
|
||||
|
||||
async def on_invoice_paid(payment: Scrubment) -> None:
|
||||
async def on_invoice_paid(payment: ScrubLink) -> None:
|
||||
if "scrub" != payment.extra.get("tag"):
|
||||
# not an scrub invoice
|
||||
return
|
||||
|
|
@ -31,7 +31,7 @@ async def on_invoice_paid(payment: Scrubment) -> None:
|
|||
# PAY LNURLP AND LNADDRESS
|
||||
|
||||
|
||||
async def mark_webhook_sent(payment: Scrubment, status: int) -> None:
|
||||
async def mark_webhook_sent(payment: ScrubLink, status: int) -> None:
|
||||
payment.extra["wh_status"] = status
|
||||
|
||||
await core_db.execute(
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<q-card>
|
||||
<q-card-section>
|
||||
<q-btn unelevated color="primary" @click="formDialog.show = true"
|
||||
>New pay link</q-btn
|
||||
>New scrub link</q-btn
|
||||
>
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
|
|
@ -28,9 +28,9 @@
|
|||
<template v-slot:header="props">
|
||||
<q-tr :props="props">
|
||||
<q-th auto-width></q-th>
|
||||
<q-th auto-width>Wallet</q-th>
|
||||
<q-th auto-width>Description</q-th>
|
||||
<q-th auto-width>Amount</q-th>
|
||||
<q-th auto-width>Currency</q-th>
|
||||
<q-th auto-width>LNURLPay/Address</q-th>
|
||||
<q-th auto-width></q-th>
|
||||
<q-th auto-width></q-th>
|
||||
</q-tr>
|
||||
|
|
@ -152,7 +152,7 @@
|
|||
dense
|
||||
v-model.trim="formDialog.data.description"
|
||||
type="text"
|
||||
label="Item description *"
|
||||
label="Description *"
|
||||
></q-input>
|
||||
|
||||
<q-input
|
||||
|
|
@ -10,7 +10,7 @@ from lnbits.core.models import User
|
|||
from lnbits.decorators import check_user_exists
|
||||
|
||||
from . import scrub_ext, scrub_renderer
|
||||
from .crud import get_pay_link
|
||||
from .crud import get_scrub_link
|
||||
|
||||
templates = Jinja2Templates(directory="templates")
|
||||
|
||||
|
|
@ -24,7 +24,7 @@ async def index(request: Request, user: User = Depends(check_user_exists)):
|
|||
|
||||
@scrub_ext.get("/{link_id}", response_class=HTMLResponse)
|
||||
async def display(request: Request, link_id):
|
||||
link = await get_pay_link(link_id)
|
||||
link = await get_scrub_link(link_id)
|
||||
if not link:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND, detail="Scrub link does not exist."
|
||||
|
|
@ -35,7 +35,7 @@ async def display(request: Request, link_id):
|
|||
|
||||
@scrub_ext.get("/print/{link_id}", response_class=HTMLResponse)
|
||||
async def print_qr(request: Request, link_id):
|
||||
link = await get_pay_link(link_id)
|
||||
link = await get_scrub_link(link_id)
|
||||
if not link:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND, detail="Scrub link does not exist."
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ from .crud import (
|
|||
get_scrub_links,
|
||||
update_scrub_link,
|
||||
)
|
||||
from .models import CreateScrubLinkData
|
||||
from .models import ScrubLink
|
||||
|
||||
|
||||
@scrub_ext.get("/api/v1/currencies")
|
||||
|
|
@ -46,7 +46,7 @@ async def api_links(
|
|||
except:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND,
|
||||
detail="No links available",
|
||||
detail="No SCRUB links made yet",
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -72,10 +72,11 @@ async def api_link_retrieve(
|
|||
@scrub_ext.post("/api/v1/links", status_code=HTTPStatus.CREATED)
|
||||
@scrub_ext.put("/api/v1/links/{link_id}", status_code=HTTPStatus.OK)
|
||||
async def api_link_create_or_update(
|
||||
data: CreateScrubLinkData,
|
||||
data: ScrubLink,
|
||||
link_id=None,
|
||||
wallet: WalletTypeInfo = Depends(get_key_type),
|
||||
):
|
||||
print("WAH")
|
||||
if data.min < 1:
|
||||
raise HTTPException(
|
||||
detail="Min must be more than 1.", status_code=HTTPStatus.BAD_REQUEST
|
||||
|
|
@ -115,6 +116,7 @@ async def api_link_create_or_update(
|
|||
link = await update_pay_link(**data.dict(), link_id=link_id)
|
||||
else:
|
||||
link = await create_pay_link(data, wallet_id=wallet.wallet.id)
|
||||
|
||||
return {**link.dict(), "lnurl": link.lnurl}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue