From 951bbea61bab7548104be681fa32fba05a67f1d1 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Mon, 28 Dec 2020 23:31:06 -0800 Subject: [PATCH] tighten up logic and html template --- wowstash/blueprints/wallet/routes.py | 36 +++++++++++++++++--------- wowstash/library/cache.py | 7 +++++ wowstash/templates/wallet/loading.html | 12 +-------- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/wowstash/blueprints/wallet/routes.py b/wowstash/blueprints/wallet/routes.py index 1429c58..77de7dd 100644 --- a/wowstash/blueprints/wallet/routes.py +++ b/wowstash/blueprints/wallet/routes.py @@ -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) diff --git a/wowstash/library/cache.py b/wowstash/library/cache.py index 1099215..78b9eec 100644 --- a/wowstash/library/cache.py +++ b/wowstash/library/cache.py @@ -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: diff --git a/wowstash/templates/wallet/loading.html b/wowstash/templates/wallet/loading.html index 3b9bdb5..e8ff36f 100644 --- a/wowstash/templates/wallet/loading.html +++ b/wowstash/templates/wallet/loading.html @@ -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 %} {% include 'footer.html' %}