mirror of
https://github.com/basicswap/basicswap.git
synced 2025-02-02 03:06:30 +00:00
html: wallets template.
This commit is contained in:
parent
27929d41ec
commit
551381f076
2 changed files with 60 additions and 19 deletions
|
@ -113,11 +113,12 @@ class HttpHandler(BaseHTTPRequestHandler):
|
|||
content = html_content_start(self.server.title, self.server.title) \
|
||||
+ '<h3>Wallets</h3>'
|
||||
|
||||
messages = []
|
||||
if post_string != '':
|
||||
form_data = urllib.parse.parse_qs(post_string)
|
||||
form_id = form_data[b'formid'][0].decode('utf-8')
|
||||
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:
|
||||
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
|
||||
txid = swap_client.withdrawCoin(c, value, address, subfee)
|
||||
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()
|
||||
|
||||
content += '<form method="post">'
|
||||
wallets_formatted = []
|
||||
for k, w in wallets.items():
|
||||
cid = str(int(k))
|
||||
content += '<h4>' + w['name'] + '</h4>'
|
||||
|
||||
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)
|
||||
tx_vsize = swap_client.getContractSpendTxVSize(k)
|
||||
est_fee = (fee_rate * tx_vsize) / 1000
|
||||
content += '<table>' \
|
||||
+ '<tr><td>Balance:</td><td>' + w['balance'] + '</td></tr>' \
|
||||
+ '<tr><td>Blocks:</td><td>' + str(w['blocks']) + '</td></tr>' \
|
||||
+ '<tr><td>Synced:</td><td>' + str(w['synced']) + '</td></tr>' \
|
||||
+ '<tr><td><input type="submit" name="newaddr_' + cid + '" value="Deposit Address"></td><td>' + str(w['deposit_address']) + '</td></tr>' \
|
||||
+ '<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>' \
|
||||
+ '<tr><td>Fee Rate:</td><td>' + format8(fee_rate * COIN) + '</td><td>Est Fee:</td><td>' + format8(est_fee * COIN) + '</td></tr>' \
|
||||
+ '</table>'
|
||||
wallets_formatted.append({
|
||||
'cid': str(int(k)),
|
||||
'fee_rate': format8(fee_rate * COIN),
|
||||
'est_fee': format8(est_fee * COIN),
|
||||
'balance': w['balance'],
|
||||
'blocks': w['blocks'],
|
||||
'synced': w['synced'],
|
||||
'deposit_address': w['deposit_address'],
|
||||
})
|
||||
|
||||
content += '<input type="hidden" name="formid" value="' + os.urandom(8).hex() + '"></form>'
|
||||
content += '<p><a href="/">home</a></p></body></html>'
|
||||
return bytes(content, 'UTF-8')
|
||||
template = env.get_template('wallets.html')
|
||||
return bytes(template.render(
|
||||
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):
|
||||
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 a new issue