mirror of
https://github.com/lnbits/lnbits.git
synced 2025-09-28 04:46:18 +02:00
withdraw bug fixing/can't withdraw
This commit is contained in:
@@ -57,11 +57,12 @@ async def get_withdraw_link(link_id: str, num=0) -> Optional[WithdrawLink]:
|
||||
if not row:
|
||||
return None
|
||||
|
||||
link = []
|
||||
for item in row:
|
||||
link.append(item)
|
||||
link.append(num)
|
||||
return WithdrawLink._make(link)
|
||||
# link = []
|
||||
# for item in row:
|
||||
# link.append(item)
|
||||
# link.append(num)
|
||||
print("GET_LINK", WithdrawLink.from_row(row))
|
||||
return WithdrawLink.from_row(row)
|
||||
|
||||
|
||||
async def get_withdraw_link_by_hash(unique_hash: str, num=0) -> Optional[WithdrawLink]:
|
||||
@@ -71,11 +72,11 @@ async def get_withdraw_link_by_hash(unique_hash: str, num=0) -> Optional[Withdra
|
||||
if not row:
|
||||
return None
|
||||
|
||||
link = []
|
||||
for item in row:
|
||||
link.append(item)
|
||||
link.append(num)
|
||||
return WithdrawLink._make(link)
|
||||
# link = []
|
||||
# for item in row:
|
||||
# link.append(item)
|
||||
# link.append(num)
|
||||
return WithdrawLink.from_row(row)
|
||||
|
||||
|
||||
async def get_withdraw_links(wallet_ids: Union[str, List[str]]) -> List[WithdrawLink]:
|
||||
|
@@ -3,6 +3,7 @@ from http import HTTPStatus
|
||||
from datetime import datetime
|
||||
|
||||
from lnbits.core.services import pay_invoice
|
||||
from starlette.requests import Request
|
||||
|
||||
from . import withdraw_ext
|
||||
from .crud import get_withdraw_link_by_hash, update_withdraw_link
|
||||
@@ -11,8 +12,8 @@ from .crud import get_withdraw_link_by_hash, update_withdraw_link
|
||||
# FOR LNURLs WHICH ARE NOT UNIQUE
|
||||
|
||||
|
||||
@withdraw_ext.get("/api/v1/lnurl/{unique_hash}", status_code=HTTPStatus.OK)
|
||||
async def api_lnurl_response(unique_hash):
|
||||
@withdraw_ext.get("/api/v1/lnurl/{unique_hash}", status_code=HTTPStatus.OK, name="withdraw.api_lnurl_response")
|
||||
async def api_lnurl_response(request: Request, unique_hash):
|
||||
link = await get_withdraw_link_by_hash(unique_hash)
|
||||
|
||||
if not link:
|
||||
@@ -33,14 +34,14 @@ async def api_lnurl_response(unique_hash):
|
||||
# HTTPStatus.OK,
|
||||
# )
|
||||
|
||||
return link.lnurl_response.dict()
|
||||
return link.lnurl_response(request).dict()
|
||||
|
||||
|
||||
# FOR LNURLs WHICH ARE UNIQUE
|
||||
|
||||
|
||||
@withdraw_ext.get("/api/v1/lnurl/{unique_hash}/{id_unique_hash}", status_code=HTTPStatus.OK)
|
||||
async def api_lnurl_multi_response(unique_hash, id_unique_hash):
|
||||
@withdraw_ext.get("/api/v1/lnurl/{unique_hash}/{id_unique_hash}", status_code=HTTPStatus.OK, name="withdraw.api_lnurl_multi_response")
|
||||
async def api_lnurl_multi_response(request: Request, unique_hash, id_unique_hash):
|
||||
link = await get_withdraw_link_by_hash(unique_hash)
|
||||
|
||||
if not link:
|
||||
@@ -79,17 +80,17 @@ async def api_lnurl_multi_response(unique_hash, id_unique_hash):
|
||||
# HTTPStatus.OK,
|
||||
# )
|
||||
|
||||
return link.lnurl_response.dict()
|
||||
return link.lnurl_response(request).dict()
|
||||
|
||||
|
||||
# CALLBACK
|
||||
|
||||
|
||||
@withdraw_ext.get("/api/v1/lnurl/cb/{unique_hash}", status_code=HTTPStatus.OK)
|
||||
@withdraw_ext.get("/api/v1/lnurl/cb/{unique_hash}", status_code=HTTPStatus.OK, name="withdraw.api_lnurl_callback")
|
||||
async def api_lnurl_callback(unique_hash):
|
||||
link = await get_withdraw_link_by_hash(unique_hash)
|
||||
k1 = request.path_params['k1']
|
||||
payment_request = request.path_params['pr']
|
||||
k1 = request.query_params['k1']
|
||||
payment_request = request.query_params['pr']
|
||||
now = int(datetime.now().timestamp())
|
||||
|
||||
if not link:
|
||||
|
@@ -49,20 +49,18 @@ class WithdrawLink(BaseModel):
|
||||
url = req.url_for(
|
||||
"withdraw.api_lnurl_multi_response",
|
||||
unique_hash=self.unique_hash,
|
||||
id_unique_hash=multihash,
|
||||
_external=True,
|
||||
id_unique_hash=multihash
|
||||
)
|
||||
else:
|
||||
url = req.url_for(
|
||||
"withdraw.api_lnurl_response",
|
||||
unique_hash=self.unique_hash,
|
||||
_external=True,
|
||||
unique_hash=self.unique_hash
|
||||
)
|
||||
|
||||
return lnurl_encode(url)
|
||||
|
||||
@property
|
||||
def lnurl_response(self) -> LnurlWithdrawResponse:
|
||||
|
||||
def lnurl_response(self, req: Request) -> LnurlWithdrawResponse:
|
||||
url = req.url_for(
|
||||
"withdraw.api_lnurl_callback", unique_hash=self.unique_hash, _external=True
|
||||
)
|
||||
|
@@ -240,7 +240,7 @@ new Vue({
|
||||
getWithdrawLinks()
|
||||
this.checker = setInterval(function () {
|
||||
getWithdrawLinks()
|
||||
}, 20000)
|
||||
}, 300000)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@@ -25,6 +25,7 @@ async def index(request: Request, user: User = Depends(check_user_exists)):
|
||||
@withdraw_ext.get("/{link_id}", response_class=HTMLResponse)
|
||||
async def display(request: Request, link_id):
|
||||
link = await get_withdraw_link(link_id, 0)
|
||||
|
||||
if not link:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND,
|
||||
@@ -32,7 +33,7 @@ async def display(request: Request, link_id):
|
||||
)
|
||||
# response.status_code = HTTPStatus.NOT_FOUND
|
||||
# return "Withdraw link does not exist." #probably here is where we should return the 404??
|
||||
return withdraw_renderer().TemplateResponse("withdraw/display.html", {"request":request,"link":link, "unique":True})
|
||||
return withdraw_renderer().TemplateResponse("withdraw/display.html", {"request":request,"link":{**link.dict(), "lnurl": link.lnurl(request)}, "unique":True})
|
||||
|
||||
|
||||
@withdraw_ext.get("/img/{link_id}", response_class=HTMLResponse)
|
||||
@@ -45,7 +46,8 @@ async def img(request: Request, link_id):
|
||||
)
|
||||
# response.status_code = HTTPStatus.NOT_FOUND
|
||||
# return "Withdraw link does not exist."
|
||||
qr = pyqrcode.create(link.lnurl)
|
||||
qr = pyqrcode.create(link.lnurl(request))
|
||||
print(qr)
|
||||
stream = BytesIO()
|
||||
qr.svg(stream, scale=3)
|
||||
return (
|
||||
@@ -70,10 +72,13 @@ async def print_qr(request: Request, link_id):
|
||||
)
|
||||
# response.status_code = HTTPStatus.NOT_FOUND
|
||||
# return "Withdraw link does not exist."
|
||||
|
||||
if link.uses == 0:
|
||||
return withdraw_renderer().TemplateResponse("withdraw/print_qr.html", {"request":request,link:link, unique:False})
|
||||
|
||||
return withdraw_renderer().TemplateResponse("withdraw/print_qr.html", {"request":request,"link":link.dict(), unique:False})
|
||||
links = []
|
||||
count = 0
|
||||
|
||||
for x in link.usescsv.split(","):
|
||||
linkk = await get_withdraw_link(link_id, count)
|
||||
if not linkk:
|
||||
@@ -83,8 +88,9 @@ async def print_qr(request: Request, link_id):
|
||||
)
|
||||
# response.status_code = HTTPStatus.NOT_FOUND
|
||||
# return "Withdraw link does not exist."
|
||||
links.append(str(linkk.lnurl))
|
||||
links.append(str(linkk.lnurl(request)))
|
||||
count = count + 1
|
||||
page_link = list(chunks(links, 2))
|
||||
linked = list(chunks(page_link, 5))
|
||||
print("LINKED", linked)
|
||||
return withdraw_renderer().TemplateResponse("withdraw/print_qr.html", {"request":request,"link":linked, "unique":True})
|
||||
|
@@ -33,6 +33,7 @@ async def api_links(req: Request, wallet: WalletTypeInfo = Depends(get_key_type)
|
||||
|
||||
if all_wallets:
|
||||
wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids
|
||||
|
||||
try:
|
||||
return [
|
||||
{
|
||||
@@ -71,8 +72,7 @@ async def api_link_retrieve(link_id, wallet: WalletTypeInfo = Depends(get_key_ty
|
||||
)
|
||||
# response.status_code = HTTPStatus.FORBIDDEN
|
||||
# return {"message": "Not your withdraw link."}
|
||||
|
||||
return {**link, **{"lnurl": link.lnurl}}
|
||||
return {**link, **{"lnurl": link.lnurl(request)}}
|
||||
|
||||
# class CreateData(BaseModel):
|
||||
# title: str = Query(...)
|
||||
@@ -120,7 +120,7 @@ async def api_link_create_or_update(req: Request, data: CreateWithdrawData, link
|
||||
)
|
||||
# response.status_code = HTTPStatus.FORBIDDEN
|
||||
# return {"message": "Not your withdraw link."}
|
||||
link = await update_withdraw_link(link_id, **data, usescsv=usescsv, used=0)
|
||||
link = await update_withdraw_link(link_id, data=data, usescsv=usescsv, used=0)
|
||||
else:
|
||||
link = await create_withdraw_link(
|
||||
wallet_id=wallet.wallet.id, data=data, usescsv=usescsv
|
||||
|
Reference in New Issue
Block a user