diff --git a/lnbits/extensions/tpos/__init__.py b/lnbits/extensions/tpos/__init__.py new file mode 100644 index 0000000..b661fd2 --- /dev/null +++ b/lnbits/extensions/tpos/__init__.py @@ -0,0 +1,8 @@ +from flask import Blueprint + + +tpos_ext = Blueprint("tpos", __name__, static_folder="static", template_folder="templates") + + +from .views_api import * # noqa +from .views import * # noqa diff --git a/lnbits/extensions/tpos/example.config.json b/lnbits/extensions/tpos/example.config.json new file mode 100644 index 0000000..03a1d97 --- /dev/null +++ b/lnbits/extensions/tpos/example.config.json @@ -0,0 +1,5 @@ +{ + "name": "TPOS", + "short_description": "A shareable POS.", + "ion_icon": "calculator" +} diff --git a/lnbits/extensions/tpos/schema.sql b/lnbits/extensions/tpos/schema.sql new file mode 100644 index 0000000..24c1d25 --- /dev/null +++ b/lnbits/extensions/tpos/schema.sql @@ -0,0 +1,9 @@ +/* create your extensions table and the variables needed here */ +CREATE TABLE IF NOT EXISTS tpos ( + key INTEGER PRIMARY KEY AUTOINCREMENT, + nme TEXT, + uni TEXT, + usr TEXT, + invkey TEXT +); + diff --git a/lnbits/extensions/tpos/templates/tpos/index.html b/lnbits/extensions/tpos/templates/tpos/index.html new file mode 100644 index 0000000..946edd0 --- /dev/null +++ b/lnbits/extensions/tpos/templates/tpos/index.html @@ -0,0 +1,211 @@ + + +{% extends "base.html" %} {% block messages %} + + + + ! + + +{% endblock %} + + +{% block menuitems %} +
  • + + Wallets + + + +
  • +
  • + + Extensions + + + +
  • +{% endblock %} + +{% block body %} + +
    + +
    +

    + Withdraw link maker + powered by LNURL + +

    + +

    + + + + + +
    + +
    + +
    + +
    +
    +

    Make a POS

    +
    + +
    +
    + +
    + + +
    + + +
    + + +
    +
    + + +
    +
    +

    Select POS

    +
    +
    +
    +
    + + +
    + +


    +
    +
    + +
    + + +
    + + + +
    + + +
    + + +
    +{% endblock %} diff --git a/lnbits/extensions/tpos/templates/tpos/tpos.html b/lnbits/extensions/tpos/templates/tpos/tpos.html new file mode 100644 index 0000000..ae306d1 --- /dev/null +++ b/lnbits/extensions/tpos/templates/tpos/tpos.html @@ -0,0 +1,249 @@ + + + + + + + + + sparkpos + + + + + + + + + + + + + + + + + + + + + +
    +
    + +
    + +
    + + + +
    +
    + + + + + + + + + + + + + + +
    +
    + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lnbits/extensions/tpos/views.py b/lnbits/extensions/tpos/views.py new file mode 100644 index 0000000..f4748f8 --- /dev/null +++ b/lnbits/extensions/tpos/views.py @@ -0,0 +1,64 @@ +import uuid +import json +import requests + +from flask import jsonify, render_template, request, redirect, url_for +from lnbits.db import open_db, open_ext_db +from lnbits.extensions.tpos import tpos_ext + +#add your endpoints here + +@tpos_ext.route("/") +def index(): + """Try to add descriptions for others.""" + usr = request.args.get("usr") + nme = request.args.get("nme") + + if usr: + if not len(usr) > 20: + return redirect(url_for("home")) + + # Get all the data + with open_db() as db: + user_wallets = db.fetchall("SELECT * FROM wallets WHERE user = ?", (usr,)) + user_ext = db.fetchall("SELECT extension FROM extensions WHERE user = ? AND active = 1", (usr,)) + user_ext = [v[0] for v in user_ext] + + if nme: + uni = uuid.uuid4().hex + with open_ext_db("tpos") as pos_ext_db: + pos_ext_db.execute( + """ + INSERT OR IGNORE INTO tpos + (nme, uni, usr, invkey) + VALUES (?, ?, ?, ?) + """, + ( + nme, + uni, + usr, + user_wallets[0][3], + + ), + ) + with open_ext_db("tpos") as pos_ext_dbb: + user_fau = pos_ext_dbb.fetchall("SELECT * FROM tpos WHERE usr = ?", (usr,)) + + return render_template( + "tpos/index.html", user_wallets=user_wallets, user_ext=user_ext, usr=usr, user_fau=user_fau + ) + +@tpos_ext.route("/tpos") +def tpos(): + """Try to add descriptions for others.""" + pos = request.args.get("pos") + exc = request.args.get("exc") + + with open_ext_db("tpos") as pos_ext_dbb: + user_fau = pos_ext_dbb.fetchall("SELECT * FROM tpos WHERE uni = ?", (pos,)) + if not user_fau: + return jsonify({"status": "ERROR", "reason":"NO POS"}), 400 + + return render_template( + "tpos/tpos.html", pos=pos, exchange=exc + ) diff --git a/lnbits/extensions/tpos/views_api.py b/lnbits/extensions/tpos/views_api.py new file mode 100644 index 0000000..cfe744f --- /dev/null +++ b/lnbits/extensions/tpos/views_api.py @@ -0,0 +1,37 @@ +#views_api.py is for you API endpoints that could be hit by another service + +#add your dependencies here + +import json +import requests +from flask import jsonify, render_template, request, redirect, url_for +from lnbits.db import open_db, open_ext_db +from lnbits.extensions.tpos import tpos_ext + +#add your endpoints here + +@tpos_ext.route("/api/v1/fetch", methods=["GET","POST"]) +def api_tpos(): + """Try to add descriptions for others.""" + + data = request.json + sats = data["sats"] + pos = data["pos"] + + with open_ext_db("tpos") as events_ext_db: + user_pos = events_ext_db.fetchall("SELECT * FROM tpos WHERE uni = ?", (pos,)) + if not user_pos: + return jsonify({"status": "ERROR", "reason":"NO POS"}), 400 + print(user_pos[0][4]) + header = {"Content-Type": "application/json", "Grpc-Metadata-macaroon": user_pos[0][4]} + data = {"value": sats, "memo": "TPOS"} + print(url_for("api_invoices", _external=True)) + r = requests.post(url=url_for("api_invoices", _external=True), headers=header, data=json.dumps(data)) + r_json = r.json() + + if "ERROR" in r_json: + return jsonify({"status": "ERROR", "reason": r_json["ERROR"]}), 400 + + return jsonify({"status": "TRUE"}), 200 + +