refactor loading javascript, html, and status payload

seed-restores
lza_menace 4 years ago
parent ee8b65f87c
commit d4a6e927f6

@ -42,7 +42,6 @@ def setup():
@login_required @login_required
def loading(): def loading():
if current_user.wallet_connected and current_user.wallet_created: if current_user.wallet_connected and current_user.wallet_created:
sleep(1)
return redirect(url_for('wallet.dashboard')) return redirect(url_for('wallet.dashboard'))
if current_user.wallet_created is False: if current_user.wallet_created is False:
return redirect(url_for('wallet.setup')) return redirect(url_for('wallet.setup'))
@ -63,10 +62,12 @@ def dashboard():
password=current_user.wallet_password password=current_user.wallet_password
) )
if not docker.container_exists(current_user.wallet_container): if not docker.container_exists(current_user.wallet_container):
print('container does not exist.')
current_user.clear_wallet_data() current_user.clear_wallet_data()
return redirect(url_for('wallet.loading')) return redirect(url_for('wallet.loading'))
if not wallet.connected: if not wallet.connected:
print('container not connected')
return redirect(url_for('wallet.loading')) return redirect(url_for('wallet.loading'))
address = wallet.get_address() address = wallet.get_address()
@ -127,18 +128,13 @@ def create():
def status(): def status():
user_vol = docker.get_user_volume(current_user.id) user_vol = docker.get_user_volume(current_user.id)
restore_container = cache.get_data(f'restoring_{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), 'volume': docker.volume_exists(user_vol),
'restoring': restoring, 'restoring': docker.container_exists(restore_container)
'restore_container': restore_container
} }
return jsonify(data) return jsonify(data)

@ -4,6 +4,39 @@
<script src="/static/js/main.js"></script> <script src="/static/js/main.js"></script>
<script src="/static/js/noty.js"></script> <script src="/static/js/noty.js"></script>
{% if request.path == '/wallet/loading' %}
<script type="text/javascript">
function check_status(){
fetch('/wallet/status')
.then((resp) => resp.json())
.then(function(data) {
console.log(JSON.stringify(data));
// If we've created a wallet and volume, but not connected a container and are not restoring, attempt connecting
if(data['created'] && data['volume'] && data['connected'] == false && data['restoring'] == false){
fetch('/wallet/connect')
}
// If ...
if(data['created'] && data['volume'] && data['connected']){
window.setInterval(function(){
window.location.href = "{{ url_for('wallet.dashboard') }}"
}, 3000);
}
})
}
// Check every few seconds...
window.setInterval(function(){
check_status();
}, 6000);
// ...but also check on initial page load
check_status();
</script>
{% endif %}
{% if request.path == '/wallet/dashboard' %} {% if request.path == '/wallet/dashboard' %}
<script type="text/javascript" src="/static/js/zxing.js"></script> <script type="text/javascript" src="/static/js/zxing.js"></script>
<script type="text/javascript"> <script type="text/javascript">

@ -10,11 +10,7 @@
<section class="section2"> <section class="section2">
<div class="container"> <div class="container">
<div class="section-heading text-center"> <div class="section-heading text-center">
{% if current_user.wallet_created == False %}
<h2>Your wallet is being created</h2>
{% else %}
<h2>Your wallet is connecting</h2> <h2>Your wallet is connecting</h2>
{% endif %}
<p>Go smoke a fatty. This page should auto-refresh when it's ready...if not, click the button below. <br /><br />If you are restoring from a seed, please allow several minutes for the process to complete.</p> <p>Go smoke a fatty. This page should auto-refresh when it's ready...if not, click the button below. <br /><br />If you are restoring from a seed, please allow several minutes for the process to complete.</p>
<img src="/static/img/loading-cat.gif" width=300> <img src="/static/img/loading-cat.gif" width=300>
<span class="dashboard-buttons"> <span class="dashboard-buttons">
@ -26,34 +22,6 @@
</div> </div>
</section> </section>
<script>
function check_wallet_status(attrib) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4){
let res = JSON.parse(xhr.responseText);
if (res[attrib] == true) {
window.location.href = "{{ url_for('wallet.dashboard') }}"
}
}
};
xhr.open('GET', '{{ url_for("wallet.status") }}');
xhr.send();
}
{% if current_user.wallet_connected == False and current_user.wallet_created == True %}
document.addEventListener("DOMContentLoaded", function(){
var xhr = new XMLHttpRequest();
xhr.open('GET', '{{ url_for("wallet.connect") }}');
xhr.send();
});
window.setInterval(function(){
check_wallet_status('connected');
}, 6000);
{% endif %}
</script>
{% include 'footer.html' %} {% include 'footer.html' %}
{% include 'scripts.html' %} {% include 'scripts.html' %}

Loading…
Cancel
Save