gui: Add another step to creating an offer.

This commit is contained in:
tecnovert 2020-12-17 15:52:39 +02:00
parent b3c00efe16
commit c348621c96
No known key found for this signature in database
GPG key ID: 8ED6D8750C4E3F93
5 changed files with 128 additions and 57 deletions

View file

@ -299,11 +299,10 @@ class HttpHandler(BaseHTTPRequestHandler):
form_id=os.urandom(8).hex(),
), 'UTF-8')
def parseOfferFormData(self, form_data):
def parseOfferFormData(self, form_data, page_data):
swap_client = self.server.swap_client
errors = []
page_data = {}
parsed_data = {}
if b'addr_from' in form_data:
@ -325,26 +324,11 @@ class HttpHandler(BaseHTTPRequestHandler):
parsed_data['coin_to'] = coin_to
if coin_to == Coins.XMR:
page_data['swap_style'] = 'xmr'
else:
page_data['swap_style'] = 'atomic'
except Exception:
errors.append('Unknown Coin To')
page_data['fee_from_conf'] = int(form_data[b'fee_from_conf'][0])
page_data['fee_from_extra'] = int(form_data[b'fee_from_extra'][0])
parsed_data['fee_from_conf'] = page_data['fee_from_conf']
parsed_data['fee_from_extra'] = page_data['fee_from_extra']
page_data['fee_to_conf'] = int(form_data[b'fee_to_conf'][0])
page_data['fee_to_extra'] = int(form_data[b'fee_to_extra'][0])
parsed_data['fee_to_conf'] = page_data['fee_to_conf']
parsed_data['fee_to_extra'] = page_data['fee_to_extra']
if b'check_offer' in form_data:
page_data['check_offer'] = True
if b'submit_offer' in form_data:
page_data['submit_offer'] = True
try:
page_data['amt_from'] = form_data[b'amt_from'][0].decode('utf-8')
parsed_data['amt_from'] = inputAmount(page_data['amt_from'], ci_from)
@ -361,13 +345,42 @@ class HttpHandler(BaseHTTPRequestHandler):
if 'amt_to' in parsed_data and 'amt_from' in parsed_data:
parsed_data['rate'] = int((parsed_data['amt_to'] / parsed_data['amt_from']) * ci_from.COIN())
page_data['lockhrs'] = int(form_data[b'lockhrs'][0])
parsed_data['lock_seconds'] = page_data['lockhrs'] * 60 * 60
if b'step1' in form_data:
if len(errors) == 0 and b'continue' in form_data:
page_data['step2'] = True
return parsed_data, errors
page_data['step2'] = True
if b'fee_from_conf' in form_data:
page_data['fee_from_conf'] = int(form_data[b'fee_from_conf'][0])
parsed_data['fee_from_conf'] = page_data['fee_from_conf']
if b'fee_from_extra' in form_data:
page_data['fee_from_extra'] = int(form_data[b'fee_from_extra'][0])
parsed_data['fee_from_extra'] = page_data['fee_from_extra']
if b'fee_to_conf' in form_data:
page_data['fee_to_conf'] = int(form_data[b'fee_to_conf'][0])
parsed_data['fee_to_conf'] = page_data['fee_to_conf']
if b'fee_to_extra' in form_data:
page_data['fee_to_extra'] = int(form_data[b'fee_to_extra'][0])
parsed_data['fee_to_extra'] = page_data['fee_to_extra']
if b'check_offer' in form_data:
page_data['check_offer'] = True
if b'submit_offer' in form_data:
page_data['submit_offer'] = True
if b'lockhrs' in form_data:
page_data['lockhrs'] = int(form_data[b'lockhrs'][0])
parsed_data['lock_seconds'] = page_data['lockhrs'] * 60 * 60
page_data['autoaccept'] = True if b'autoaccept' in form_data else False
parsed_data['autoaccept'] = page_data['autoaccept']
if len(errors) == 0:
if len(errors) == 0 and page_data['swap_style'] == 'xmr':
if b'fee_rate_from' in form_data:
page_data['from_fee_override'] = form_data[b'fee_rate_from'][0].decode('utf-8')
parsed_data['from_fee_override'] = page_data['from_fee_override']
@ -378,18 +391,18 @@ class HttpHandler(BaseHTTPRequestHandler):
page_data['from_fee_override'] = ci_from.format_amount(ci_from.make_int(from_fee_override, r=1))
parsed_data['from_fee_override'] = page_data['from_fee_override']
if b'fee_rate_to' in form_data:
page_data['to_fee_override'] = form_data[b'fee_rate_to'][0].decode('utf-8')
parsed_data['to_fee_override'] = page_data['to_fee_override']
else:
to_fee_override, page_data['to_fee_src'] = swap_client.getFeeRateForCoin(parsed_data['coin_to'], page_data['fee_to_conf'])
if page_data['fee_to_extra'] > 0:
to_fee_override += to_fee_override * (float(page_data['fee_to_extra']) / 100.0)
if coin_to == Coins.XMR:
if b'fee_rate_to' in form_data:
page_data['to_fee_override'] = form_data[b'fee_rate_to'][0].decode('utf-8')
parsed_data['to_fee_override'] = page_data['to_fee_override']
else:
to_fee_override, page_data['to_fee_src'] = swap_client.getFeeRateForCoin(parsed_data['coin_to'], page_data['fee_to_conf'])
if page_data['fee_to_extra'] > 0:
to_fee_override += to_fee_override * (float(page_data['fee_to_extra']) / 100.0)
page_data['to_fee_override'] = ci_to.format_amount(ci_to.make_int(to_fee_override, r=1))
parsed_data['to_fee_override'] = page_data['to_fee_override']
page_data['to_fee_override'] = ci_to.format_amount(ci_to.make_int(to_fee_override, r=1))
parsed_data['to_fee_override'] = page_data['to_fee_override']
return page_data, parsed_data, errors
return parsed_data, errors
def postNewOfferFromParsed(self, parsed_data):
swap_client = self.server.swap_client
@ -434,19 +447,26 @@ class HttpHandler(BaseHTTPRequestHandler):
return offer_id
def postNewOffer(self, form_data):
page_data, parsed_data = self.parseOfferFormData(form_data)
page_data = {}
parsed_data = self.parseOfferFormData(form_data, page_data)
return self.postNewOfferFromParsed(parsed_data)
def page_newoffer(self, url_split, post_string):
swap_client = self.server.swap_client
messages = []
page_data = {}
page_data = {
# Set defaults
'fee_from_conf': 2,
'fee_to_conf': 2,
'lockhrs': 32,
'autoaccept': True
}
form_data = self.checkForm(post_string, 'newoffer', messages)
if form_data:
try:
page_data, parsed_data, errors = self.parseOfferFormData(form_data)
parsed_data, errors = self.parseOfferFormData(form_data, page_data)
for e in errors:
messages.append('Error: {}'.format(str(e)))
except Exception as e:
@ -460,17 +480,12 @@ class HttpHandler(BaseHTTPRequestHandler):
except Exception as e:
messages.append('Error: {}'.format(str(e)))
if not page_data:
# Set defaults
page_data['fee_from_conf'] = 2
page_data['fee_to_conf'] = 2
page_data['lockhrs'] = 32
page_data['autoaccept'] = True
if len(messages) == 0 and 'check_offer' in page_data:
template = env.get_template('offer_confirm.html')
elif 'step2' in page_data:
template = env.get_template('offer_new_2.html')
else:
template = env.get_template('offer_new.html')
template = env.get_template('offer_new_1.html')
return bytes(template.render(
title=self.server.title,
@ -536,7 +551,6 @@ class HttpHandler(BaseHTTPRequestHandler):
}
if xmr_offer:
int_fee_rate_now, fee_source = ci_from.get_fee_rate()
data['xmr_type'] = True
data['a_fee_rate'] = ci_from.format_amount(xmr_offer.a_fee_rate)

View file

@ -42,6 +42,7 @@
<form method="post">
{% if data.show_bid_form %}
<br/><h4>New Bid</h4>
<p>You will send {{ data.amt_to }} {{ data.tla_to }} and receive {{ data.amt_from }} {{ data.tla_from }}</p>
<table>
<tr><td>Send From Address</td><td>
<select name="addr_from">
@ -52,14 +53,14 @@
</select>
</td></tr>
<tr><td><input type="submit" name="sendbid" value="Send Bid"></td></tr>
<tr><td><input type="submit" name="sendbid" value="Send Bid"><input type="submit" name="cancel" value="Cancel"></td></tr>
</table>
{% else %}
<input type="submit" name="newbid" value="New Bid">
{% endif %}
{% if data.sent == 'True' and data.was_revoked != true %}
<input name="revoke_offer" type="submit" value="Revoke Offer" onclick="confirmPopup()">
{% endif %}
{% endif %}
<input type="hidden" name="formid" value="{{ form_id }}">
</form>

View file

@ -22,6 +22,7 @@
{% endfor %}
</select>
</td><td>Amount From</td><td><input type="text" name="amt_from" value="{{ data.amt_from }}" readonly></td><td>The amount you will send.</td></tr>
{% if data.swap_style == 'xmr' %}
</td><td>Fee Rate From</td><td><input name="fee_rate_from" value="{{ data.from_fee_override }}" readonly></td><td>Fee Rate Source</td><td>{{ data.from_fee_src }}</td></tr>
</td><td>Fee From Confirm Target</td><td><input type="number" name="fee_from_conf" min="1" max="32" value="{{ data.fee_from_conf }}" readonly></td></tr>
</td><td>Fee From Extra Fee</td><td>
@ -31,6 +32,7 @@
<option value="50"{% if data.fee_from_extra==50 %} selected{% endif %}>50%</option>
<option value="100"{% if data.fee_from_extra==100 %} selected{% endif %}>100%</option>
</select></td></tr>
{% endif %}
<tr><td>Coin To</td><td>
<select name="coin_to_" disabled><option value="-1">-- Select Coin --</option>
@ -39,7 +41,8 @@
{% endfor %}
</select>
</td><td>Amount To</td><td><input type="text" name="amt_to" value="{{ data.amt_to }}" readonly></td><td>The amount you will receive.</td></tr>
</td><td>Fee Rate From</td><td><input name="fee_rate_to" value="{{ data.to_fee_override }}" readonly></td><td>Fee Rate Source</td><td>{{ data.to_fee_src }}</td></tr>
{% if data.swap_style == 'xmr' and coin_to != '6' %}
</td><td>Fee Rate To</td><td><input name="fee_rate_to" value="{{ data.to_fee_override }}" readonly></td><td>Fee Rate Source</td><td>{{ data.to_fee_src }}</td></tr>
</td><td>Fee To Confirm Target</td><td><input type="number" name="fee_to_conf" min="1" max="32" value="{{ data.fee_to_conf }}" readonly></td></tr>
</td><td>Fee To Extra Fee</td><td>
<select name="fee_to_extra_" disabled>
@ -48,19 +51,23 @@
<option value="50"{% if data.fee_to_extra==50 %} selected{% endif %}>50%</option>
<option value="100"{% if data.fee_to_extra==100 %} selected{% endif %}>100%</option>
</select></td></tr>
{% endif %}
<tr><td>Contract locked (hrs)</td><td><input type="number" name="lockhrs" min="1" max="64" value="{{ data.lockhrs }}" readonly></td>{% if data.swap_style != 'xmr' %}<td colspan=2>Participate txn will be locked for half the time.</td>{% endif %}</tr>
<tr><td>Auto Accept Bids</td><td colspan=3><input type="checkbox" name="autoaccept" value="aa" {% if data.autoaccept==true %} checked{% endif %} readonly></td></tr>
<tr><td>Auto Accept Bids</td><td colspan=3><input type="checkbox" name="autoaccept_" value="aa" {% if data.autoaccept==true %} checked="true"{% endif %} disabled></td></tr>
</table>
<input name="submit_offer" type="submit" value="Confirm Offer">
<input type="submit" value="Back">
<input name="step2" type="submit" value="Back">
<input type="hidden" name="formid" value="{{ form_id }}">
<input type="hidden" name="addr_from" value="{{ data.addr_from }}">
<input type="hidden" name="coin_from" value="{{ data.coin_from }}">
<input type="hidden" name="fee_from_extra" value="{{ data.fee_from_extra }}">
<input type="hidden" name="coin_to" value="{{ data.coin_to }}">
<input type="hidden" name="fee_to_extra" value="{{ data.fee_to_extra }}">
{% if data.autoaccept==true %}
<input type="hidden" name="autoaccept" value="aa">
{% endif %}
</form>
<p><a href="/">home</a></p>

View file

@ -0,0 +1,41 @@
{% include 'header.html' %}
<h3>New Offer</h3>
{% for m in messages %}
<p>{{ m }}</p>
{% endfor %}
<form method="post">
<table>
<tr><td>Send From Address</td><td><select name="addr_from">
{% for a in addrs %}
<option{% if data.addr_from==a %} selected{% endif %} value="{{ a }}">{{ a }}</option>
{% endfor %}
<option{% if data.addr_from=="-1" %} selected{% endif %} value="-1">-- New Address --</option>
</select></td></tr>
<tr><td>Coin From</td><td>
<select name="coin_from"><option value="-1">-- Select Coin --</option>
{% for c in coins %}
<option{% if data.coin_from==c[0] %} selected{% endif %} value="{{ c[0] }}">{{ c[1] }}</option>
{% endfor %}
</select>
</td><td>Amount From</td><td><input type="text" name="amt_from" value="{{ data.amt_from }}"></td><td>The amount you will send.</td></tr>
<tr><td>Coin To</td><td>
<select name="coin_to"><option value="-1">-- Select Coin --</option>
{% for c in coins %}
<option{% if data.coin_to==c[0] %} selected{% endif %} value="{{ c[0] }}">{{ c[1] }}</option>
{% endfor %}
</select>
</td><td>Amount To</td><td><input type="text" name="amt_to" value="{{ data.amt_to }}"></td><td>The amount you will receive.</td></tr>
</table>
<input name="continue" type="submit" value="Continue">
<input type="hidden" name="formid" value="{{ form_id }}">
<input type="hidden" name="step1" value="a">
</form>
<p><a href="/">home</a></p>
</body></html>

View file

@ -8,7 +8,7 @@
<form method="post">
<table>
<tr><td>Send From Address</td><td><select name="addr_from">
<tr><td>Send From Address</td><td><select name="addr_from_" disabled>
{% for a in addrs %}
<option{% if data.addr_from==a %} selected{% endif %} value="{{ a }}">{{ a }}</option>
{% endfor %}
@ -16,12 +16,13 @@
</select></td></tr>
<tr><td>Coin From</td><td>
<select name="coin_from"><option value="-1">-- Select Coin --</option>
<select name="coin_from_" disabled><option value="-1">-- Select Coin --</option>
{% for c in coins %}
<option{% if data.coin_from==c[0] %} selected{% endif %} value="{{ c[0] }}">{{ c[1] }}</option>
{% endfor %}
</select>
</td><td>Amount From</td><td><input type="text" name="amt_from" value="{{ data.amt_from }}"></td><td>The amount you will send.</td></tr>
</td><td>Amount From</td><td><input type="text" name="amt_from" value="{{ data.amt_from }}" readonly></td><td>The amount you will send.</td></tr>
{% if data.swap_style == 'xmr' %}
</td><td>Fee From Confirm Target</td><td><input type="number" name="fee_from_conf" min="1" max="32" value="{{ data.fee_from_conf }}"></td></tr>
</td><td>Fee From Extra Fee</td><td>
<select name="fee_from_extra">
@ -30,14 +31,16 @@
<option value="50"{% if data.fee_from_extra==50 %} selected{% endif %}>50%</option>
<option value="100"{% if data.fee_from_extra==100 %} selected{% endif %}>100%</option>
</select></td></tr>
{% endif %}
<tr><td>Coin To</td><td>
<select name="coin_to"><option value="-1">-- Select Coin --</option>
<select name="coin_to_" disabled><option value="-1">-- Select Coin --</option>
{% for c in coins %}
<option{% if data.coin_to==c[0] %} selected{% endif %} value="{{ c[0] }}">{{ c[1] }}</option>
{% endfor %}
</select>
</td><td>Amount To</td><td><input type="text" name="amt_to" value="{{ data.amt_to }}"></td><td>The amount you will receive.</td></tr>
</td><td>Amount To</td><td><input type="text" name="amt_to" value="{{ data.amt_to }}" readonly></td><td>The amount you will receive.</td></tr>
{% if data.swap_style == 'xmr' and coin_to != '6' %}
</td><td>Fee To Confirm Target</td><td><input type="number" name="fee_to_conf" min="1" max="32" value="{{ data.fee_to_conf }}"></td></tr>
</td><td>Fee To Extra Fee</td><td>
<select name="fee_to_extra">
@ -46,13 +49,18 @@
<option value="50"{% if data.fee_to_extra==50 %} selected{% endif %}>50%</option>
<option value="100"{% if data.fee_to_extra==100 %} selected{% endif %}>100%</option>
</select></td></tr>
{% endif %}
<tr><td>Contract locked (hrs)</td><td><input type="number" name="lockhrs" min="1" max="64" value="{{ data.lockhrs }}"></td><td colspan=2>Participate txn will be locked for half the time.</td></tr>
<tr><td>Auto Accept Bids</td><td colspan=3><input type="checkbox" name="autoaccept" value="aa" {% if data.autoaccept==true %} checked{% endif %}></td></tr>
<tr><td>Auto Accept Bids</td><td colspan=3><input type="checkbox" name="autoaccept" value="aa" {% if data.autoaccept==true %} checked="true"{% endif %}></td></tr>
</table>
<input name="check_offer" type="submit" value="Submit">
<input name="check_offer" type="submit" value="Continue">
<input name="step1" type="submit" value="Back">
<input type="hidden" name="formid" value="{{ form_id }}">
<input type="hidden" name="addr_from" value="{{ data.addr_from }}">
<input type="hidden" name="coin_from" value="{{ data.coin_from }}">
<input type="hidden" name="coin_to" value="{{ data.coin_to }}">
</form>
<p><a href="/">home</a></p>