tighten up logic and html template

seed-restores
lza_menace 4 years ago
parent 1c1b032d87
commit 951bbea61b

@ -24,19 +24,19 @@ from wowstash import config
def setup():
if current_user.wallet_created:
return redirect(url_for('wallet.dashboard'))
restore_form = Restore()
if restore_form.validate_on_submit():
if current_user.wallet_created is False:
docker.create_wallet(current_user.id, restore_form.seed.data)
else:
restore_form = Restore()
if restore_form.validate_on_submit():
c = docker.create_wallet(current_user.id, restore_form.seed.data)
cache.store_data(f'restoring_{current_user.id}', 30, c)
current_user.wallet_created = True
db.session.commit()
return redirect(url_for('wallet.loading'))
else:
return redirect(url_for('wallet.dashboard'))
return render_template(
'wallet/setup.html',
restore_form=restore_form
)
return render_template(
'wallet/setup.html',
restore_form=restore_form
)
@wallet_bp.route('/wallet/loading')
@login_required
@ -44,6 +44,8 @@ def loading():
if current_user.wallet_connected and current_user.wallet_created:
sleep(1)
return redirect(url_for('wallet.dashboard'))
if current_user.wallet_created is False:
return redirect(url_for('wallet.setup'))
return render_template('wallet/loading.html')
@wallet_bp.route('/wallet/dashboard')
@ -116,17 +118,27 @@ def create():
docker.create_wallet(current_user.id)
current_user.wallet_created = True
db.session.commit()
return 'ok'
return redirect(url_for('wallet.loading'))
else:
return redirect(url_for('wallet.dashboard'))
@wallet_bp.route('/wallet/status')
@login_required
def status():
user_vol = docker.get_user_volume(current_user.id)
restore_container = cache.get_data(f'restoring_{current_user.id}')
if restore_container:
restoring = True
else:
restoring = False
data = {
'created': current_user.wallet_created,
'connected': current_user.wallet_connected,
'port': current_user.wallet_port,
'container': current_user.wallet_container
'container': current_user.wallet_container,
'volume': docker.volume_exists(user_vol),
'restoring': restoring,
'restore_container': restore_container
}
return jsonify(data)

@ -17,6 +17,13 @@ class Cache(object):
value=data
)
def get_data(self, item_name):
data = self.redis.get(item_name)
if data:
return data.decode()
else:
return None
def get_coin_info(self):
info = self.redis.get("coin_info")
if info:

@ -47,21 +47,11 @@
xhr.open('GET', '{{ url_for("wallet.connect") }}');
xhr.send();
});
{% endif %}
{% if current_user.wallet_connected == False and current_user.wallet_created == False %}
// document.addEventListener("DOMContentLoaded", function(){
// var xhr = new XMLHttpRequest();
// xhr.open('GET', '{{ url_for("wallet.create") }}');
// xhr.send();
// });
{% endif %}
window.setInterval(function(){
{% if current_user.wallet_connected == False and current_user.wallet_created == True %}
check_wallet_status('connected');
{% endif %}
}, 6000);
{% endif %}
</script>
{% include 'footer.html' %}

Loading…
Cancel
Save