fixing import/create

htmx
lza_menace 1 year ago
parent 31002694c9
commit b0ca32fdab

@ -34,6 +34,9 @@ class LWS:
def init(self, admin_key): def init(self, admin_key):
self.admin_key = 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): def get_address_info(self, address, view_key):
endpoint = f"{config.LWS_URL}/get_address_info" endpoint = f"{config.LWS_URL}/get_address_info"
data = { data = {

@ -1,4 +1,5 @@
import monero.address import monero.address
from monero.seed import Seed
from quart import Blueprint, render_template, request, flash, redirect, url_for from quart import Blueprint, render_template, request, flash, redirect, url_for
from quart_auth import login_required, current_user from quart_auth import login_required, current_user
@ -14,39 +15,27 @@ bp = Blueprint("wallet", "wallet")
async def add(): async def add():
form = await request.form form = await request.form
if form: if form:
address = None
label = form.get("label") label = form.get("label")
address = form.get("address", "") seed = form.get("seed")
view_key = form.get("view_key", "")
restore_height = form.get("restore_height", None) 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: try:
_a = monero.address.Address(address) seed = Seed(seed)
valid_view_key = _a.check_private_view_key(view_key)
except ValueError: except ValueError:
await flash("Invalid Monero address") await flash("Invalid mnemonic seed")
return redirect("/wallet/add") return ""
if not valid_view_key: lws._init()
await flash("Invalid view key provided for address") address = str(seed.public_address())
return redirect("/wallet/add") svk = str(seed.secret_view_key())
lws.add_wallet(address, view_key) lws.add_wallet(address, svk)
if restore_height != "-1": if restore_height != "-1":
lws.rescan(address, int(restore_height)) lws.rescan(address, str(restore_height))
w = Wallet( w = Wallet(
address=address, address=seed.public_address(),
view_key=view_key,
label=label if label else get_random_words() label=label if label else get_random_words()
) )
w.save() w.save()
await flash("wallet added") return redirect(url_for("htmx.show_wallets"))
return redirect(f"/")
else:
return ""
@bp.route("/wallet/<address>/rescan/<height>") @bp.route("/wallet/<address>/rescan/<height>")

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

@ -1,11 +1,22 @@
<form hx-post="{{ url_for('wallet.add') }}" id="import_wallet"> <div id="import_wallet">
<label for="label">Label</label> <form hx-target="#show_wallets" hx-post="{{ url_for('wallet.add') }}" action="#" >
<input type="text" name="label" /> <label for="label">Label</label>
<label for="seed">Mnemonic Seed</label> <input type="text" name="label" />
<p class="subtext">12, 13, or 25 word seeds</p> <label for="seed">Mnemonic Seed</label>
<input type="password" name="seed" /> <p class="subtext">12, 13, or 25 word seeds</p>
<label for="restore_height">Restore Height</label> <input type="password" name="seed" />
<input type="number" name="restore_height" /> <label for="restore_height">Restore Height</label>
<button onclick="document.getElementById('import_wallet').innerHTML = ''">Cancel</button> <input type="number" name="restore_height" value="-1" />
<button type="submit">Import</button> <button onsubmit="cancelImport()" type="submit">Import</button>
</form> <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> <a href="/utils">Go Back</a>
<h1>Parse Mnemonic Seed</h1> <h1>Parse Mnemonic Seed</h1>
<form method="post"> <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" /> <input type="password" name="seed" />
<button type="submit">Send</button> <button type="submit">Send</button>
</form> </form>

Loading…
Cancel
Save