From b0ca32fdab294ca164ec902c4c63721caa602625 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Mon, 13 Nov 2023 22:51:52 -0800 Subject: [PATCH] fixing import/create --- lwsadmin/lws/helpers.py | 3 ++ lwsadmin/lws/routes/wallet.py | 37 +++++++------------ .../lws/templates/htmx/create_wallet.html | 31 +++++++++++----- .../lws/templates/htmx/import_wallet.html | 33 +++++++++++------ lwsadmin/lws/templates/utils/mnemonic.html | 2 +- 5 files changed, 60 insertions(+), 46 deletions(-) diff --git a/lwsadmin/lws/helpers.py b/lwsadmin/lws/helpers.py index 65d917c..d02df8b 100644 --- a/lwsadmin/lws/helpers.py +++ b/lwsadmin/lws/helpers.py @@ -34,6 +34,9 @@ class LWS: def init(self, admin_key): self.admin_key = admin_key + def _init(self): + self.admin_key = User.select().first().view_key + def get_address_info(self, address, view_key): endpoint = f"{config.LWS_URL}/get_address_info" data = { diff --git a/lwsadmin/lws/routes/wallet.py b/lwsadmin/lws/routes/wallet.py index d3e8ae8..51f354a 100644 --- a/lwsadmin/lws/routes/wallet.py +++ b/lwsadmin/lws/routes/wallet.py @@ -1,4 +1,5 @@ import monero.address +from monero.seed import Seed from quart import Blueprint, render_template, request, flash, redirect, url_for from quart_auth import login_required, current_user @@ -14,39 +15,27 @@ bp = Blueprint("wallet", "wallet") async def add(): form = await request.form if form: + address = None label = form.get("label") - address = form.get("address", "") - view_key = form.get("view_key", "") + seed = form.get("seed") restore_height = form.get("restore_height", None) - valid_view_key = False - if not address: - await flash("must provide an address") - return redirect("/wallet/add") - if not view_key: - await flash("must provide a view_key") - return redirect("/wallet/add") try: - _a = monero.address.Address(address) - valid_view_key = _a.check_private_view_key(view_key) + seed = Seed(seed) except ValueError: - await flash("Invalid Monero address") - return redirect("/wallet/add") - if not valid_view_key: - await flash("Invalid view key provided for address") - return redirect("/wallet/add") - lws.add_wallet(address, view_key) + await flash("Invalid mnemonic seed") + return "" + lws._init() + address = str(seed.public_address()) + svk = str(seed.secret_view_key()) + lws.add_wallet(address, svk) if restore_height != "-1": - lws.rescan(address, int(restore_height)) + lws.rescan(address, str(restore_height)) w = Wallet( - address=address, - view_key=view_key, + address=seed.public_address(), label=label if label else get_random_words() ) w.save() - await flash("wallet added") - return redirect(f"/") - else: - return "" + return redirect(url_for("htmx.show_wallets")) @bp.route("/wallet/
/rescan/") diff --git a/lwsadmin/lws/templates/htmx/create_wallet.html b/lwsadmin/lws/templates/htmx/create_wallet.html index bc7550f..53a2393 100644 --- a/lwsadmin/lws/templates/htmx/create_wallet.html +++ b/lwsadmin/lws/templates/htmx/create_wallet.html @@ -1,15 +1,26 @@
-

Seed: {{ seed }}

-

Public Address: {{ address }}

-

Public Spend Key: {{ psk }}

-

Public View Key: {{ pvk }}

-

Secret Spend Key: {{ ssk }}

-

Secret View Key: {{ svk }}

-
+ + + +

Seed: {{ seed }}

+

Public Address: {{ address }}

+

Public Spend Key: {{ psk }}

+

Public View Key: {{ pvk }}

+

Secret Spend Key: {{ ssk }}

+

Secret View Key: {{ svk }}

- - + +
-
\ No newline at end of file + + diff --git a/lwsadmin/lws/templates/htmx/import_wallet.html b/lwsadmin/lws/templates/htmx/import_wallet.html index df61d05..ebc60d8 100644 --- a/lwsadmin/lws/templates/htmx/import_wallet.html +++ b/lwsadmin/lws/templates/htmx/import_wallet.html @@ -1,11 +1,22 @@ -
- - - -

12, 13, or 25 word seeds

- - - - - -
\ No newline at end of file +
+
+ + + +

12, 13, or 25 word seeds

+ + + + + +
+ +
\ No newline at end of file diff --git a/lwsadmin/lws/templates/utils/mnemonic.html b/lwsadmin/lws/templates/utils/mnemonic.html index 9b98d08..91eacb1 100644 --- a/lwsadmin/lws/templates/utils/mnemonic.html +++ b/lwsadmin/lws/templates/utils/mnemonic.html @@ -4,7 +4,7 @@ Go Back

Parse Mnemonic Seed

- +