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(): def setup():
if current_user.wallet_created: if current_user.wallet_created:
return redirect(url_for('wallet.dashboard')) return redirect(url_for('wallet.dashboard'))
restore_form = Restore() else:
if restore_form.validate_on_submit(): restore_form = Restore()
if current_user.wallet_created is False: if restore_form.validate_on_submit():
docker.create_wallet(current_user.id, restore_form.seed.data) 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 current_user.wallet_created = True
db.session.commit() db.session.commit()
return redirect(url_for('wallet.loading')) return redirect(url_for('wallet.loading'))
else: else:
return redirect(url_for('wallet.dashboard')) return render_template(
return render_template( 'wallet/setup.html',
'wallet/setup.html', restore_form=restore_form
restore_form=restore_form )
)
@wallet_bp.route('/wallet/loading') @wallet_bp.route('/wallet/loading')
@login_required @login_required
@ -44,6 +44,8 @@ def loading():
if current_user.wallet_connected and current_user.wallet_created: if current_user.wallet_connected and current_user.wallet_created:
sleep(1) sleep(1)
return redirect(url_for('wallet.dashboard')) 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') return render_template('wallet/loading.html')
@wallet_bp.route('/wallet/dashboard') @wallet_bp.route('/wallet/dashboard')
@ -116,17 +118,27 @@ def create():
docker.create_wallet(current_user.id) docker.create_wallet(current_user.id)
current_user.wallet_created = True current_user.wallet_created = True
db.session.commit() db.session.commit()
return redirect(url_for('wallet.loading'))
return 'ok' else:
return redirect(url_for('wallet.dashboard'))
@wallet_bp.route('/wallet/status') @wallet_bp.route('/wallet/status')
@login_required @login_required
def status(): 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 = { data = {
'created': current_user.wallet_created, 'created': current_user.wallet_created,
'connected': current_user.wallet_connected, 'connected': current_user.wallet_connected,
'port': current_user.wallet_port, '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) return jsonify(data)

@ -17,6 +17,13 @@ class Cache(object):
value=data 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): def get_coin_info(self):
info = self.redis.get("coin_info") info = self.redis.get("coin_info")
if info: if info:

@ -47,21 +47,11 @@
xhr.open('GET', '{{ url_for("wallet.connect") }}'); xhr.open('GET', '{{ url_for("wallet.connect") }}');
xhr.send(); 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(){ window.setInterval(function(){
{% if current_user.wallet_connected == False and current_user.wallet_created == True %}
check_wallet_status('connected'); check_wallet_status('connected');
{% endif %}
}, 6000); }, 6000);
{% endif %}
</script> </script>
{% include 'footer.html' %} {% include 'footer.html' %}

Loading…
Cancel
Save