mirror of
https://git.wownero.com/lza_menace/wowstash.git
synced 2024-08-15 00:33:15 +00:00
refactor loading javascript, html, and status payload
This commit is contained in:
parent
ee8b65f87c
commit
d4a6e927f6
3 changed files with 36 additions and 39 deletions
|
@ -42,7 +42,6 @@ def setup():
|
|||
@login_required
|
||||
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'))
|
||||
|
@ -63,10 +62,12 @@ def dashboard():
|
|||
password=current_user.wallet_password
|
||||
)
|
||||
if not docker.container_exists(current_user.wallet_container):
|
||||
print('container does not exist.')
|
||||
current_user.clear_wallet_data()
|
||||
return redirect(url_for('wallet.loading'))
|
||||
|
||||
if not wallet.connected:
|
||||
print('container not connected')
|
||||
return redirect(url_for('wallet.loading'))
|
||||
|
||||
address = wallet.get_address()
|
||||
|
@ -127,18 +128,13 @@ def create():
|
|||
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,
|
||||
'volume': docker.volume_exists(user_vol),
|
||||
'restoring': restoring,
|
||||
'restore_container': restore_container
|
||||
'restoring': docker.container_exists(restore_container)
|
||||
}
|
||||
return jsonify(data)
|
||||
|
||||
|
|
|
@ -4,6 +4,39 @@
|
|||
<script src="/static/js/main.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' %}
|
||||
<script type="text/javascript" src="/static/js/zxing.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
|
|
@ -10,11 +10,7 @@
|
|||
<section class="section2">
|
||||
<div class="container">
|
||||
<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>
|
||||
{% 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>
|
||||
<img src="/static/img/loading-cat.gif" width=300>
|
||||
<span class="dashboard-buttons">
|
||||
|
@ -26,34 +22,6 @@
|
|||
</div>
|
||||
</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 'scripts.html' %}
|
||||
|
|
Loading…
Reference in a new issue