fixing import/create

htmx
lza_menace 1 year ago
parent 31002694c9
commit b0ca32fdab

@ -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 = {

@ -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/<address>/rescan/<height>")

@ -1,15 +1,26 @@
<div id="create_wallet">
<p>Seed: <span class="key">{{ seed }}</span></p>
<p>Public Address: <span class="key">{{ address }}</span></p>
<p>Public Spend Key: <span class="key">{{ psk }}</span></p>
<p>Public View Key: <span class="key">{{ pvk }}</span></p>
<p>Secret Spend Key: <span class="key">{{ ssk }}</span></p>
<p>Secret View Key: <span class="key">{{ svk }}</span></p>
<form method="post" action="{{ url_for('wallet.add') }}" hx-confirm="Please confirm">
<form hx-target="#show_wallets" hx-post="{{ url_for('wallet.add') }}" action="#" hx-confirm="hope you saved the seed">
<label for="label">Label</label>
<input type="text" name="label" />
<p>Seed: <span class="key">{{ seed }}</span></p>
<p>Public Address: <span class="key">{{ address }}</span></p>
<p>Public Spend Key: <span class="key">{{ psk }}</span></p>
<p>Public View Key: <span class="key">{{ pvk }}</span></p>
<p>Secret Spend Key: <span class="key">{{ ssk }}</span></p>
<p>Secret View Key: <span class="key">{{ svk }}</span></p>
<input type="text" name="address" value="{{ address }}" class="hidden" />
<input type="text" name="view_key" value="{{ svk }}" class="hidden" />
<input type="number" name="restore_height" value="-1" class="hidden" />
<button onclick="document.getElementById('create_wallet').innerHTML = ''">Cancel</button>
<button type="submit" >Create</button>
<button onsubmit="cancelCreate()" type="submit">Create</button>
<button onclick="cancelCreate()">Cancel</button>
</form>
<script>
function cancelCreate() {
document.getElementById("create_wallet").innerHTML = "";
}
document.getElementById("create_wallet").addEventListener("submit", function() {
cancelCreate();
})
</script>
</div>

@ -1,11 +1,22 @@
<form hx-post="{{ url_for('wallet.add') }}" id="import_wallet">
<label for="label">Label</label>
<input type="text" name="label" />
<label for="seed">Mnemonic Seed</label>
<p class="subtext">12, 13, or 25 word seeds</p>
<input type="password" name="seed" />
<label for="restore_height">Restore Height</label>
<input type="number" name="restore_height" />
<button onclick="document.getElementById('import_wallet').innerHTML = ''">Cancel</button>
<button type="submit">Import</button>
</form>
<div id="import_wallet">
<form hx-target="#show_wallets" hx-post="{{ url_for('wallet.add') }}" action="#" >
<label for="label">Label</label>
<input type="text" name="label" />
<label for="seed">Mnemonic Seed</label>
<p class="subtext">12, 13, or 25 word seeds</p>
<input type="password" name="seed" />
<label for="restore_height">Restore Height</label>
<input type="number" name="restore_height" value="-1" />
<button onsubmit="cancelImport()" type="submit">Import</button>
<button onclick="cancelImport()">Cancel</button>
</form>
<script>
function cancelImport() {
document.getElementById("import_wallet").innerHTML = "";
}
document.getElementById("import_wallet").addEventListener("submit", function() {
cancelImport();
})
</script>
</div>

@ -4,7 +4,7 @@
<a href="/utils">Go Back</a>
<h1>Parse Mnemonic Seed</h1>
<form method="post">
<label for="seed">25 Word Seed</label>
<label for="seed">12, 13, or 25 Word Seed</label>
<input type="password" name="seed" />
<button type="submit">Send</button>
</form>

Loading…
Cancel
Save