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