remove exception to black line-length and reformat.

This commit is contained in:
fiatjaf
2021-03-24 00:40:32 -03:00
parent 3333f1f3f3
commit 42bd5ea989
92 changed files with 1341 additions and 330 deletions
+3 -1
View File
@@ -4,7 +4,9 @@ from lnbits.db import Database
db = Database("ext_offlineshop")
offlineshop_ext: Blueprint = Blueprint("offlineshop", __name__, static_folder="static", template_folder="templates")
offlineshop_ext: Blueprint = Blueprint(
"offlineshop", __name__, static_folder="static", template_folder="templates"
)
from .views_api import * # noqa
+18 -4
View File
@@ -18,7 +18,11 @@ async def lnurl_response(item_id):
if not item.enabled:
return jsonify({"status": "ERROR", "reason": "Item disabled."})
price_msat = (await fiat_amount_as_satoshis(item.price, item.unit) if item.unit != "sat" else item.price) * 1000
price_msat = (
await fiat_amount_as_satoshis(item.price, item.unit)
if item.unit != "sat"
else item.price
) * 1000
resp = LnurlPayResponse(
callback=url_for("offlineshop.lnurl_callback", item_id=item.id, _external=True),
@@ -47,16 +51,26 @@ async def lnurl_callback(item_id):
amount_received = int(request.args.get("amount"))
if amount_received < min:
return jsonify(LnurlErrorResponse(reason=f"Amount {amount_received} is smaller than minimum {min}.").dict())
return jsonify(
LnurlErrorResponse(
reason=f"Amount {amount_received} is smaller than minimum {min}."
).dict()
)
elif amount_received > max:
return jsonify(LnurlErrorResponse(reason=f"Amount {amount_received} is greater than maximum {max}.").dict())
return jsonify(
LnurlErrorResponse(
reason=f"Amount {amount_received} is greater than maximum {max}."
).dict()
)
shop = await get_shop(item.shop)
payment_hash, payment_request = await create_invoice(
wallet_id=shop.wallet,
amount=int(amount_received / 1000),
memo=item.name,
description_hash=hashlib.sha256((await item.lnurlpay_metadata()).encode("utf-8")).digest(),
description_hash=hashlib.sha256(
(await item.lnurlpay_metadata()).encode("utf-8")
).digest(),
extra={"tag": "offlineshop", "item": item.id},
)
+9 -3
View File
@@ -89,7 +89,9 @@ class Item(NamedTuple):
@property
def lnurl(self) -> str:
return lnurl_encode(url_for("offlineshop.lnurl_response", item_id=self.id, _external=True))
return lnurl_encode(
url_for("offlineshop.lnurl_response", item_id=self.id, _external=True)
)
def values(self):
values = self._asdict()
@@ -104,11 +106,15 @@ class Item(NamedTuple):
return LnurlPayMetadata(json.dumps(metadata))
def success_action(self, shop: Shop, payment_hash: str) -> Optional[LnurlPaySuccessAction]:
def success_action(
self, shop: Shop, payment_hash: str
) -> Optional[LnurlPaySuccessAction]:
if not shop.wordlist:
return None
return UrlAction(
url=url_for("offlineshop.confirmation_code", p=payment_hash, _external=True),
url=url_for(
"offlineshop.confirmation_code", p=payment_hash, _external=True
),
description="Open to get the confirmation code for your purchase.",
)
+13 -3
View File
@@ -24,7 +24,13 @@ async def print_qr_codes():
for item_id in request.args.get("items").split(","):
item = await get_item(item_id)
if item:
items.append({"lnurl": item.lnurl, "name": item.name, "price": f"{item.price} {item.unit}"})
items.append(
{
"lnurl": item.lnurl,
"name": item.name,
"price": f"{item.price} {item.unit}",
}
)
return await render_template("offlineshop/print.html", items=items)
@@ -36,10 +42,14 @@ async def confirmation_code():
payment_hash = request.args.get("p")
payment: Payment = await get_standalone_payment(payment_hash)
if not payment:
return f"Couldn't find the payment {payment_hash}." + style, HTTPStatus.NOT_FOUND
return (
f"Couldn't find the payment {payment_hash}." + style,
HTTPStatus.NOT_FOUND,
)
if payment.pending:
return (
f"Payment {payment_hash} wasn't received yet. Please try again in a minute." + style,
f"Payment {payment_hash} wasn't received yet. Please try again in a minute."
+ style,
HTTPStatus.PAYMENT_REQUIRED,
)
+11 -2
View File
@@ -43,7 +43,11 @@ async def api_shop_from_wallet():
)
except LnurlInvalidUrl:
return (
jsonify({"message": "LNURLs need to be delivered over a publically accessible `https` domain or Tor."}),
jsonify(
{
"message": "LNURLs need to be delivered over a publically accessible `https` domain or Tor."
}
),
HTTPStatus.UPGRADE_REQUIRED,
)
@@ -98,7 +102,12 @@ async def api_delete_item(item_id):
@api_validate_post_request(
schema={
"method": {"type": "string", "required": True, "nullable": False},
"wordlist": {"type": "string", "empty": True, "nullable": True, "required": False},
"wordlist": {
"type": "string",
"empty": True,
"nullable": True,
"required": False,
},
}
)
async def api_set_method():