use built-in method to retrieve balances on op page, dont run twice

pull/1/head
lza_menace 4 years ago
parent d87180b2fb
commit c3a137bfa9

@ -52,7 +52,6 @@ def view_operation(id):
qr_uri = f'monero:{op.address}?tx_description={op.codename}' qr_uri = f'monero:{op.address}?tx_description={op.codename}'
qrcode_make(qr_uri).save(_address_qr) qrcode_make(qr_uri).save(_address_qr)
qrcode = b64encode(_address_qr.getvalue()).decode() qrcode = b64encode(_address_qr.getvalue()).decode()
balance = wallet.balances(op.account_idx)
txes = cache.get_transfers(op.account_idx) txes = cache.get_transfers(op.account_idx)
for type in txes: for type in txes:
for tx in txes[type]: for tx in txes[type]:
@ -65,7 +64,6 @@ def view_operation(id):
'view_operation.html', 'view_operation.html',
op=op, op=op,
qrcode=qrcode, qrcode=qrcode,
balance=balance,
txes=all_transfers, txes=all_transfers,
prices=op.get_pricing(), prices=op.get_pricing(),
droplet=droplet, droplet=droplet,

@ -1,4 +1,7 @@
{% set node_url = op.codename + '.node.' + config.DO_DOMAIN %} {% set node_url = op.codename + '.node.' + config.DO_DOMAIN %}
{% set balances = op.get_balances() %}
{% set balance = balances['balance'] %}
{% set unlocked = balances['unlocked'] %}
<!DOCTYPE HTML> <!DOCTYPE HTML>
<html> <html>
@ -14,11 +17,11 @@
<div class="container center"> <div class="container center">
{% if txes %} {% if txes %}
{% if (balance[0] | from_atomic_xmr) > prices['minimum_xmr'] or droplet %} {% if (balance | from_atomic_xmr) > prices['minimum_xmr'] or droplet %}
<h1>Operation is a Go!</h1> <h1>Operation is a Go!</h1>
<p>Created: {{ op.create_date }} ({{ op.create_date | humanize }})</p> <p>Created: {{ op.create_date }} ({{ op.create_date | humanize }})</p>
<p>Codename: {{ op.codename }}</p> <p>Codename: {{ op.codename }}</p>
<p>Balance: {{ balance[1] | from_atomic_xmr }} XMR ({{ (balance[0] - balance[1]) | from_atomic_xmr }} locked)</p> <p>Balance: {{ unlocked | from_atomic_xmr }} XMR ({{ (balance - unlocked) | from_atomic_xmr }} locked)</p>
{% if droplet %} {% if droplet %}
<p> <p>
Node: {{ op.get_node_url() }} - Node: {{ op.get_node_url() }} -
@ -32,16 +35,16 @@
<p>Current XMR price: ${{ prices['xmr_price'] }}</p> <p>Current XMR price: ${{ prices['xmr_price'] }}</p>
<p>Estimated flight times remaining:</p> <p>Estimated flight times remaining:</p>
<ul> <ul>
<li>* {{ ((prices['xmr_price'] * balance[0] | from_atomic_xmr) / prices['in_usd']) | round(3) }} hours - OR</li> <li>* {{ ((prices['xmr_price'] * balance | from_atomic_xmr) / prices['in_usd']) | round(3) }} hours - OR</li>
<li>* {{ ((prices['xmr_price'] * balance[0] | from_atomic_xmr) / prices['in_usd'] / 24) | round(3) }} days - OR</li> <li>* {{ ((prices['xmr_price'] * balance | from_atomic_xmr) / prices['in_usd'] / 24) | round(3) }} days - OR</li>
<li>* {{ ((prices['xmr_price'] * balance[0] | from_atomic_xmr) / prices['in_usd'] / 730) | round(3) }} months</li> <li>* {{ ((prices['xmr_price'] * balance | from_atomic_xmr) / prices['in_usd'] / 730) | round(3) }} months</li>
</ul> </ul>
{% else %} {% else %}
<h1>Operation is not ready!</h1> <h1>Operation is not ready!</h1>
<p>You haven't sent enough XMR.</p> <p>You haven't sent enough XMR.</p>
<p>Codename: {{ op.codename }}</p> <p>Codename: {{ op.codename }}</p>
<p>Balance: {{ balance[1] | from_atomic_xmr }} XMR ({{ (balance[0] - balance[1]) | from_atomic_xmr }} locked)</p> <p>Balance: {{ unlocked | from_atomic_xmr }} XMR ({{ (balance - unlocked) | from_atomic_xmr }} locked)</p>
<p>Minimum: {{ prices['minimum_xmr'] }}</p> <p>Minimum: {{ prices['minimum_xmr'] }}</p>
{% if droplet %} {% if droplet %}
<p> <p>
@ -88,7 +91,7 @@
<p class="code">{{ op.address }}</p> <p class="code">{{ op.address }}</p>
<br /> <br />
<img src="data:image/png;base64,{{ qrcode }}" width=200 class="center"> <img src="data:image/png;base64,{{ qrcode }}" width=200 class="center">
<p>Balance: {{ balance[1] | from_atomic_xmr }} XMR ({{ (balance[0] - balance[1]) | from_atomic_xmr }} locked)</p> <p>Balance: {{ unlocked | from_atomic_xmr }} XMR ({{ (balance - unlocked) | from_atomic_xmr }} locked)</p>
<br /> <br />
{% if txes %} {% if txes %}
<table class="table center"> <table class="table center">

Loading…
Cancel
Save