html: wallets template.
This commit is contained in:
parent
27929d41ec
commit
551381f076
@ -113,11 +113,12 @@ class HttpHandler(BaseHTTPRequestHandler):
|
|||||||
content = html_content_start(self.server.title, self.server.title) \
|
content = html_content_start(self.server.title, self.server.title) \
|
||||||
+ '<h3>Wallets</h3>'
|
+ '<h3>Wallets</h3>'
|
||||||
|
|
||||||
|
messages = []
|
||||||
if post_string != '':
|
if post_string != '':
|
||||||
form_data = urllib.parse.parse_qs(post_string)
|
form_data = urllib.parse.parse_qs(post_string)
|
||||||
form_id = form_data[b'formid'][0].decode('utf-8')
|
form_id = form_data[b'formid'][0].decode('utf-8')
|
||||||
if self.server.last_form_id.get('wallets', None) == form_id:
|
if self.server.last_form_id.get('wallets', None) == form_id:
|
||||||
content += '<p>Prevented double submit for form {}.</p>'.format(form_id)
|
messages.append('Prevented double submit for form {}.'.format(form_id))
|
||||||
else:
|
else:
|
||||||
self.server.last_form_id['wallets'] = form_id
|
self.server.last_form_id['wallets'] = form_id
|
||||||
|
|
||||||
@ -133,33 +134,38 @@ class HttpHandler(BaseHTTPRequestHandler):
|
|||||||
subfee = True if bytes('subfee_' + cid, 'utf-8') in form_data else False
|
subfee = True if bytes('subfee_' + cid, 'utf-8') in form_data else False
|
||||||
txid = swap_client.withdrawCoin(c, value, address, subfee)
|
txid = swap_client.withdrawCoin(c, value, address, subfee)
|
||||||
ticker = swap_client.getTicker(c)
|
ticker = swap_client.getTicker(c)
|
||||||
content += '<p>Withdrew {} {} to address {}<br/>In txid: {}</p>'.format(value, ticker, address, txid)
|
messages.append('Withdrew {} {} to address {}<br/>In txid: {}'.format(value, ticker, address, txid))
|
||||||
|
|
||||||
wallets = swap_client.getWalletsInfo()
|
wallets = swap_client.getWalletsInfo()
|
||||||
|
|
||||||
content += '<form method="post">'
|
wallets_formatted = []
|
||||||
for k, w in wallets.items():
|
for k, w in wallets.items():
|
||||||
cid = str(int(k))
|
|
||||||
content += '<h4>' + w['name'] + '</h4>'
|
|
||||||
|
|
||||||
if 'error' in w:
|
if 'error' in w:
|
||||||
content += '<p>Error: {}</p>'.format(w['error'])
|
wallets_formatted.append({
|
||||||
|
'cid': str(int(k)),
|
||||||
|
'error': w['error']
|
||||||
|
})
|
||||||
|
continue
|
||||||
fee_rate = swap_client.getFeeRateForCoin(k)
|
fee_rate = swap_client.getFeeRateForCoin(k)
|
||||||
tx_vsize = swap_client.getContractSpendTxVSize(k)
|
tx_vsize = swap_client.getContractSpendTxVSize(k)
|
||||||
est_fee = (fee_rate * tx_vsize) / 1000
|
est_fee = (fee_rate * tx_vsize) / 1000
|
||||||
content += '<table>' \
|
wallets_formatted.append({
|
||||||
+ '<tr><td>Balance:</td><td>' + w['balance'] + '</td></tr>' \
|
'cid': str(int(k)),
|
||||||
+ '<tr><td>Blocks:</td><td>' + str(w['blocks']) + '</td></tr>' \
|
'fee_rate': format8(fee_rate * COIN),
|
||||||
+ '<tr><td>Synced:</td><td>' + str(w['synced']) + '</td></tr>' \
|
'est_fee': format8(est_fee * COIN),
|
||||||
+ '<tr><td><input type="submit" name="newaddr_' + cid + '" value="Deposit Address"></td><td>' + str(w['deposit_address']) + '</td></tr>' \
|
'balance': w['balance'],
|
||||||
+ '<tr><td><input type="submit" name="withdraw_' + cid + '" value="Withdraw"></td><td>Amount: <input type="text" name="amt_' + cid + '"></td><td>Address: <input type="text" name="to_' + cid + '"></td><td>Subtract fee: <input type="checkbox" name="subfee_' + cid + '"></td></tr>' \
|
'blocks': w['blocks'],
|
||||||
+ '<tr><td>Fee Rate:</td><td>' + format8(fee_rate * COIN) + '</td><td>Est Fee:</td><td>' + format8(est_fee * COIN) + '</td></tr>' \
|
'synced': w['synced'],
|
||||||
+ '</table>'
|
'deposit_address': w['deposit_address'],
|
||||||
|
})
|
||||||
|
|
||||||
content += '<input type="hidden" name="formid" value="' + os.urandom(8).hex() + '"></form>'
|
template = env.get_template('wallets.html')
|
||||||
content += '<p><a href="/">home</a></p></body></html>'
|
return bytes(template.render(
|
||||||
return bytes(content, 'UTF-8')
|
title=self.server.title,
|
||||||
|
h2=self.server.title,
|
||||||
|
wallets=wallets_formatted,
|
||||||
|
form_id=os.urandom(8).hex(),
|
||||||
|
), 'UTF-8')
|
||||||
|
|
||||||
def page_newoffer(self, url_split, post_string):
|
def page_newoffer(self, url_split, post_string):
|
||||||
swap_client = self.server.swap_client
|
swap_client = self.server.swap_client
|
||||||
|
35
basicswap/templates/wallets.html
Normal file
35
basicswap/templates/wallets.html
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
{% include 'header.html' %}
|
||||||
|
|
||||||
|
<h3>Wallets</h3>
|
||||||
|
{% if refresh %}
|
||||||
|
<p>Page Refresh: {{ refresh }} seconds</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% for m in messages %}
|
||||||
|
<p>{{ m }}</p>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
<form method="post">
|
||||||
|
|
||||||
|
|
||||||
|
{% for w in wallets %}
|
||||||
|
<h4>{{ w.name }}</h4>
|
||||||
|
{% if w.error %}
|
||||||
|
<p>Error: {{ w.error }}</p>
|
||||||
|
{% else %}
|
||||||
|
<table>
|
||||||
|
<tr><td>Balance:</td><td>{{ w.balance }}</td></tr>
|
||||||
|
<tr><td>Blocks:</td><td>{{ w.blocks }}</td></tr>
|
||||||
|
<tr><td>Synced:</td><td>{{ w.synced }}</td></tr>
|
||||||
|
<tr><td><input type="submit" name="newaddr_{{ w.cid }}" value="Deposit Address"></td><td>{{ w.deposit_address }}</td></tr>
|
||||||
|
<tr><td><input type="submit" name="withdraw_{{ w.cid }}" value="Withdraw"></td><td>Amount: <input type="text" name="amt_{{ w.cid }}"></td><td>Address: <input type="text" name="to_{{ w.cid }}"></td><td>Subtract fee: <input type="checkbox" name="subfee_{{ w.cid }}"></td></tr>
|
||||||
|
<tr><td>Fee Rate:</td><td>{{ w.fee_rate }}</td><td>Est Fee:</td><td>{{ w.est_fee }}</td></tr>
|
||||||
|
</table>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
<input type="hidden" name="formid" value="{{ form_id }}">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<p><a href="/">home</a></p>
|
||||||
|
</body></html>
|
Loading…
Reference in New Issue
Block a user