From 1af4fab24561a7d726c3a2cb0854c7745993c66c Mon Sep 17 00:00:00 2001 From: lza_menace Date: Thu, 4 May 2023 22:22:56 -0700 Subject: [PATCH] trying oob mgmt --- lws-web/lws/config.py | 5 +++-- lws-web/lws/filters.py | 5 +++++ lws-web/lws/helpers.py | 16 ++++++++++++++++ lws-web/lws/routes/meta.py | 3 --- lws-web/lws/routes/wallet.py | 11 +++++++++++ lws-web/lws/templates/index.html | 26 ++++++++++++++++++++++---- 6 files changed, 57 insertions(+), 9 deletions(-) diff --git a/lws-web/lws/config.py b/lws-web/lws/config.py index a59ce9e..5f49f0a 100644 --- a/lws-web/lws/config.py +++ b/lws-web/lws/config.py @@ -2,11 +2,12 @@ from os import environ as env from secrets import token_urlsafe from dotenv import load_dotenv -# load_dotenv() +DEBUG = 1 == env.get("DEBUG", 1) +if DEBUG: + load_dotenv() HOST = env.get("HOST", "127.0.0.1") TEMPLATES_AUTO_RELOAD = True -DEBUG = 1 == env.get("DEBUG", 1) QUART_ENV = env.get("QUART_ENV", "development") SECRET_KEY = env.get("SECRET_KEY", token_urlsafe(12)) QUART_AUTH_DURATION = 60 * 60 # 1 hour diff --git a/lws-web/lws/filters.py b/lws-web/lws/filters.py index 1a224a9..bd70a3a 100644 --- a/lws-web/lws/filters.py +++ b/lws-web/lws/filters.py @@ -8,3 +8,8 @@ bp = Blueprint('filters', 'filters') @bp.app_template_filter('atomic') def atomic(amt): return float(from_atomic(amt)) + + +@bp.app_template_filter('shorten') +def shorten(s): + return f"{s[:6]}...{s[-6:]}" \ No newline at end of file diff --git a/lws-web/lws/helpers.py b/lws-web/lws/helpers.py index c56a917..2e12001 100644 --- a/lws-web/lws/helpers.py +++ b/lws-web/lws/helpers.py @@ -19,3 +19,19 @@ class LWS: except Exception as e: print(f"Failed to list accounts: {e}") return {} + + def get_address_txs(self, address, view_key): + endpoint = f"{config.LWS_URL}/get_address_txs" + data = { + "address": address, + "view_key": view_key + } + try: + req = requests.post(endpoint, json=data, timeout=5) + req.raise_for_status() + if req.ok: + return req.json() + return {} + except Exception as e: + print(f"Failed to get wallet info {address}: {e}") + return False diff --git a/lws-web/lws/routes/meta.py b/lws-web/lws/routes/meta.py index 348ab79..b1b0a5c 100644 --- a/lws-web/lws/routes/meta.py +++ b/lws-web/lws/routes/meta.py @@ -12,9 +12,6 @@ bp = Blueprint('meta', 'meta') @bp.route("/") @login_required async def index(): - admin = User.select().first() - if not admin: - return redirect("/setup") wallets = Wallet.select().order_by(Wallet.date.desc()) lws = LWS(admin.view_key) return await render_template( diff --git a/lws-web/lws/routes/wallet.py b/lws-web/lws/routes/wallet.py index 3cbd8df..4c5fd58 100644 --- a/lws-web/lws/routes/wallet.py +++ b/lws-web/lws/routes/wallet.py @@ -8,6 +8,17 @@ from lws.models import Wallet, User bp = Blueprint('wallet', 'wallet') +# @bp.route("/") + +# accept_requests: {"type": "import"|"create", "addresses":[...]} +# add_account: {"address": ..., "key": ...} +# list_accounts: {} +# list_requests: {} +# modify_account_status: {"status": "active"|"hidden"|"inactive", "addresses":[...]} +# reject_requests: {"type": "import"|"create", "addresses":[...]} +# rescan: {"height":..., "addresses":[...]} + + @bp.route("/wallets") @login_required async def list(): diff --git a/lws-web/lws/templates/index.html b/lws-web/lws/templates/index.html index 123a44d..e16a947 100644 --- a/lws-web/lws/templates/index.html +++ b/lws-web/lws/templates/index.html @@ -6,10 +6,28 @@

LWS Admin: {{ config.LWS_ADMIN_URL }}

LWS RPC: {{ config.LWS_URL }}

-

Active Accounts

-{% for a in lws_accounts['active'] %} -
  • {{ a['address'] }} - {{ a['scan_height'] }}
  • -{% endfor %} + + + + + + + + + + {% for a in lws_accounts %} + {% if a != 'hidden' %} + {% for acc in lws_accounts[a] %} + + + + + + {% endfor %} + {% endif %} + {% endfor %} + +
    StatusAddressHeight
    {{ a | upper }}{{ acc['address'] | shorten }}{{ acc['scan_height'] }}
    {% endblock %}