mirror of
https://github.com/basicswap/basicswap.git
synced 2024-11-16 15:58:17 +00:00
ui: Add swap type.
This commit is contained in:
parent
fb5e8ff8b1
commit
2a3d89b112
9 changed files with 223 additions and 33 deletions
|
@ -1,3 +1,3 @@
|
|||
name = "basicswap"
|
||||
|
||||
__version__ = "0.11.55"
|
||||
__version__ = "0.11.56"
|
||||
|
|
|
@ -458,3 +458,19 @@ def isActiveBidState(state):
|
|||
if state == BidStates.XMR_SWAP_FAILED:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def strSwapType(swap_type):
|
||||
if swap_type == SwapTypes.SELLER_FIRST:
|
||||
return 'seller_first'
|
||||
if swap_type == SwapTypes.XMR_SWAP:
|
||||
return 'xmr_swap'
|
||||
return None
|
||||
|
||||
|
||||
def strSwapDesc(swap_type):
|
||||
if swap_type == SwapTypes.SELLER_FIRST:
|
||||
return 'Secret Hash'
|
||||
if swap_type == SwapTypes.XMR_SWAP:
|
||||
return 'Adaptor Sig'
|
||||
return None
|
||||
|
|
|
@ -174,6 +174,7 @@ def js_offers(self, url_split, post_string, is_json, sent=False):
|
|||
ci_from = swap_client.ci(o.coin_from)
|
||||
ci_to = swap_client.ci(o.coin_to)
|
||||
rv.append({
|
||||
'swap_type': o.swap_type,
|
||||
'addr_from': o.addr_from,
|
||||
'addr_to': o.addr_to,
|
||||
'offer_id': o.offer_id.hex(),
|
||||
|
|
|
@ -106,6 +106,10 @@
|
|||
<td class="py-4 px-6 bold">Offer State</td>
|
||||
<td>{{ data.state }}</td>
|
||||
</tr>
|
||||
<tr class="bg-white border-t hover:bg-gray-50">
|
||||
<td class="py-4 px-6 bold">Swap Type</td>
|
||||
<td>{{ data.swap_type }}</td>
|
||||
</tr>
|
||||
<tr class="bg-white border-t hover:bg-gray-50">
|
||||
<td class="py-4 px-6 bold">{% if data.sent %}You Send{% else %}You Get{% endif %}</td>
|
||||
<td><span class="inline-flex align-middle items-center justify-center w-9 h-10 bg-white-50 rounded">
|
||||
|
|
|
@ -161,6 +161,38 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="py-6 border-b border-coolGray-100">
|
||||
<div class="w-full md:w-10/12">
|
||||
<div class="flex flex-wrap -m-3">
|
||||
<div class="w-full md:w-1/3 p-3">
|
||||
<p class="text-sm text-coolGray-800 font-semibold">Swap Type</p>
|
||||
</div>
|
||||
<div class="w-full md:flex-1 p-3">
|
||||
<div class="relative">
|
||||
<svg class="absolute right-4 top-1/2 transform -translate-y-1/2" width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M11.3333 6.1133C11.2084 5.98913 11.0395 5.91943 10.8633 5.91943C10.6872 5.91943 10.5182 5.98913 10.3933 6.1133L8.00001 8.47329L5.64001 6.1133C5.5151 5.98913 5.34613 5.91943 5.17001 5.91943C4.99388 5.91943 4.82491 5.98913 4.70001 6.1133C4.63752 6.17527 4.58792 6.249 4.55408 6.33024C4.52023 6.41148 4.50281 6.49862 4.50281 6.58663C4.50281 6.67464 4.52023 6.76177 4.55408 6.84301C4.58792 6.92425 4.63752 6.99799 4.70001 7.05996L7.52667 9.88663C7.58865 9.94911 7.66238 9.99871 7.74362 10.0326C7.82486 10.0664 7.912 10.0838 8.00001 10.0838C8.08801 10.0838 8.17515 10.0664 8.25639 10.0326C8.33763 9.99871 8.41136 9.94911 8.47334 9.88663L11.3333 7.05996C11.3958 6.99799 11.4454 6.92425 11.4793 6.84301C11.5131 6.76177 11.5305 6.67464 11.5305 6.58663C11.5305 6.49862 11.5131 6.41148 11.4793 6.33024C11.4454 6.249 11.3958 6.17527 11.3333 6.1133Z" fill="#8896AB"> </path>
|
||||
</svg>
|
||||
<div class="flex absolute inset-y-0 left-0 items-center pl-3 pointer-events-none">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="20" width="20" viewBox="0 0 24 24">
|
||||
<g stroke-linecap="round" stroke-width="2" fill="none" stroke="#3b82f6" stroke-linejoin="round">
|
||||
<path data-cap="butt" d="M11.992,11.737,14.2,13.4A2,2,0,0,1,15,15v1H7V15a2,2,0,0,1,.8-1.6l2.208-1.663" stroke="#3b82f6"></path>
|
||||
<rect x="9" y="7" width="4" height="5" rx="2" ry="2" stroke="#3b82f6"></rect>
|
||||
<path d="M2,1H18a2,2,0,0,1,2,2V21a2,2,0,0,1-2,2H2Z"></path>
|
||||
<line x1="23" y1="5" x2="23" y2="9" stroke="#3b82f6"></line>
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
<select class="pl-10 appearance-none pr-10 bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5" name="swap_type" id="swap_type" disabled>
|
||||
{% for a in swap_types %}
|
||||
<option{% if data.swap_type==a[0] %} selected{% endif %} value="{{ a[0] }}">{{ a[1] }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="py-6 border-b border-coolGray-100">
|
||||
<div class="w-full md:w-10/12">
|
||||
<div class="flex flex-wrap -m-3">
|
||||
|
@ -598,6 +630,7 @@
|
|||
<input type="hidden" name="formid" value="{{ form_id }}">
|
||||
<input type="hidden" name="addr_to" value="{{ data.addr_to }}">
|
||||
<input type="hidden" name="addr_from" value="{{ data.addr_from }}">
|
||||
<input type="hidden" name="swap_type" value="{{ data.swap_type }}">
|
||||
<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 }}">
|
||||
|
|
|
@ -80,7 +80,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<form method="post" autocomplete="off">
|
||||
<form method="post" autocomplete="off" id='form'>
|
||||
<div class="py-6 border-b border-t border-coolGray-100">
|
||||
<div class="w-full md:w-10/12">
|
||||
<div class="flex flex-wrap -m-3">
|
||||
|
@ -146,6 +146,39 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="py-6 border-b border-coolGray-100">
|
||||
<div class="w-full md:w-10/12">
|
||||
<div class="flex flex-wrap -m-3">
|
||||
<div class="w-full md:w-1/3 p-3">
|
||||
<p class="text-sm text-coolGray-800 font-semibold">Swap Type</p>
|
||||
</div>
|
||||
<div class="w-full md:flex-1 p-3">
|
||||
<div class="relative">
|
||||
<svg class="absolute right-4 top-1/2 transform -translate-y-1/2" width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M11.3333 6.1133C11.2084 5.98913 11.0395 5.91943 10.8633 5.91943C10.6872 5.91943 10.5182 5.98913 10.3933 6.1133L8.00001 8.47329L5.64001 6.1133C5.5151 5.98913 5.34613 5.91943 5.17001 5.91943C4.99388 5.91943 4.82491 5.98913 4.70001 6.1133C4.63752 6.17527 4.58792 6.249 4.55408 6.33024C4.52023 6.41148 4.50281 6.49862 4.50281 6.58663C4.50281 6.67464 4.52023 6.76177 4.55408 6.84301C4.58792 6.92425 4.63752 6.99799 4.70001 7.05996L7.52667 9.88663C7.58865 9.94911 7.66238 9.99871 7.74362 10.0326C7.82486 10.0664 7.912 10.0838 8.00001 10.0838C8.08801 10.0838 8.17515 10.0664 8.25639 10.0326C8.33763 9.99871 8.41136 9.94911 8.47334 9.88663L11.3333 7.05996C11.3958 6.99799 11.4454 6.92425 11.4793 6.84301C11.5131 6.76177 11.5305 6.67464 11.5305 6.58663C11.5305 6.49862 11.5131 6.41148 11.4793 6.33024C11.4454 6.249 11.3958 6.17527 11.3333 6.1133Z" fill="#8896AB"> </path>
|
||||
</svg>
|
||||
<div class="flex absolute inset-y-0 left-0 items-center pl-3 pointer-events-none">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="20" width="20" viewBox="0 0 24 24">
|
||||
<g stroke-linecap="round" stroke-width="2" fill="none" stroke="#3b82f6" stroke-linejoin="round">
|
||||
<path data-cap="butt" d="M11.992,11.737,14.2,13.4A2,2,0,0,1,15,15v1H7V15a2,2,0,0,1,.8-1.6l2.208-1.663" stroke="#3b82f6"></path>
|
||||
<rect x="9" y="7" width="4" height="5" rx="2" ry="2" stroke="#3b82f6"></rect>
|
||||
<path d="M2,1H18a2,2,0,0,1,2,2V21a2,2,0,0,1-2,2H2Z"></path>
|
||||
<line x1="23" y1="5" x2="23" y2="9" stroke="#3b82f6"></line>
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
<select class="pl-10 appearance-none pr-10 bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5" name="swap_type" id="swap_type">
|
||||
{% for a in swap_types %}
|
||||
<option{% if data.swap_type==a[0] %} selected{% endif %} value="{{ a[0] }}">{{ a[1] }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="py-6 border-b border-coolGray-100">
|
||||
<div class="w-full md:w-10/12">
|
||||
<div class="flex flex-wrap -m-3">
|
||||
|
@ -267,6 +300,10 @@
|
|||
</svg>
|
||||
</div>
|
||||
<input class="pl-10 appearance-none pr-10 bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5" type="text" id="rate" name="rate" value="{{ data.rate }}" onchange="set_rate('rate');"> </div>
|
||||
<div class="form-check form-check-inline">
|
||||
<input class="form-check-input h-4 w-4 border border-gray-300 rounded-sm bg-gray-50 checked:bg-blue-600 checked:border-blue-600 focus:outline-none transition duration-200 mt-1 align-top bg-no-repeat bg-center bg-contain float-left mr-2 cursor-pointer" type="checkbox" id="rate_lock" name="rate_lock" value="rl" checked=checked>
|
||||
<label class="cursor-help form-check-label inline-block text-gray-800" for="inlineCheckbox1">Lock Rate</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -280,10 +317,6 @@
|
|||
<p class="text-sm text-coolGray-800 font-semibold">Options</p>
|
||||
</div>
|
||||
<div class="w-full md:flex-1 p-3">
|
||||
<div class="form-check form-check-inline">
|
||||
<input class="form-check-input h-4 w-4 border border-gray-300 rounded-sm bg-gray-50 checked:bg-blue-600 checked:border-blue-600 focus:outline-none transition duration-200 mt-1 align-top bg-no-repeat bg-center bg-contain float-left mr-2 cursor-pointer" type="checkbox" id="rate_lock" name="rate_lock" value="rl" checked=checked>
|
||||
<label class="cursor-help form-check-label inline-block text-gray-800" for="inlineCheckbox1">Lock Rate</label>
|
||||
</div>
|
||||
<div class="form-check form-check-inline">
|
||||
<input class="form-check-input h-4 w-4 border border-gray-300 rounded-sm bg-gray-50 checked:bg-blue-600 checked:border-blue-600 focus:outline-none transition duration-200 mt-1 align-top bg-no-repeat bg-center bg-contain float-left mr-2 cursor-pointer" type="checkbox" id="amt_var" name="amt_var" value="av" {% if data.amt_var==true %} checked="checked" {% endif %}>
|
||||
<label class="form-check-label inline-block text-gray-800" for="inlineCheckbox2">Amount Variable</label>
|
||||
|
@ -438,6 +471,41 @@
|
|||
xhr_rates_table.send();
|
||||
}
|
||||
|
||||
function set_swap_type_enabled(coin_from, coin_to, swap_type) {
|
||||
let make_hidden = false;
|
||||
if (coin_to == '6' /* XMR */ || coin_to == '8' /* PART_ANON */) {
|
||||
swap_type.disabled = true;
|
||||
swap_type.value = 'xmr_swap';
|
||||
make_hidden = true;
|
||||
} else
|
||||
if (coin_from == '11' /* PIVX */ || coin_from == '12' /* DASH */ || coin_from == '13' /* FIRO */) {
|
||||
swap_type.disabled = true;
|
||||
swap_type.value = 'seller_first';
|
||||
make_hidden = true;
|
||||
} else {
|
||||
swap_type.disabled = false;
|
||||
}
|
||||
let swap_type_hidden = document.getElementById('swap_type_hidden');
|
||||
console.log('make_hidden', make_hidden);
|
||||
console.log('swap_type_hidden', swap_type_hidden);
|
||||
console.log('swap_type.value', swap_type.value);
|
||||
if (make_hidden) {
|
||||
if (!swap_type_hidden) {
|
||||
console.log('createElement');
|
||||
swap_type_hidden = document.createElement('input');
|
||||
swap_type_hidden.setAttribute('id', 'swap_type_hidden');
|
||||
swap_type_hidden.setAttribute('type', 'hidden');
|
||||
swap_type_hidden.setAttribute('name', 'swap_type');
|
||||
document.getElementById('form').appendChild(swap_type_hidden)
|
||||
}
|
||||
swap_type_hidden.setAttribute('value', swap_type.value);
|
||||
} else
|
||||
if (swap_type_hidden) {
|
||||
console.log('remove element');
|
||||
swap_type_hidden.parentNode.removeChild(swap_type_hidden);
|
||||
}
|
||||
}
|
||||
|
||||
function set_rate(value_changed) {
|
||||
const coin_from = document.getElementById('coin_from').value;
|
||||
const coin_to = document.getElementById('coin_to').value;
|
||||
|
@ -445,6 +513,10 @@
|
|||
const amt_to = document.getElementById('amt_to').value;
|
||||
const rate = document.getElementById('rate').value;
|
||||
const lock_rate = rate == '' ? false : document.getElementById('rate_lock').checked;
|
||||
|
||||
const swap_type = document.getElementById('swap_type');
|
||||
set_swap_type_enabled(coin_from, coin_to, swap_type);
|
||||
|
||||
if (coin_from == '-1' || coin_to == '-1') {
|
||||
return;
|
||||
}
|
||||
|
@ -454,15 +526,13 @@
|
|||
return;
|
||||
}
|
||||
params += '&rate=' + rate + '&amt_from=' + amt_from;
|
||||
}
|
||||
else
|
||||
} else
|
||||
if (lock_rate && value_changed == 'amt_to') {
|
||||
if (amt_to == '' || rate == '') {
|
||||
return;
|
||||
}
|
||||
params += '&amt_to=' + amt_to + '&rate=' + rate;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (amt_from == '' || amt_to == '') {
|
||||
return;
|
||||
}
|
||||
|
@ -472,6 +542,13 @@
|
|||
xhr_rate.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
||||
xhr_rate.send(params);
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
const coin_from = document.getElementById('coin_from').value;
|
||||
const coin_to = document.getElementById('coin_to').value;
|
||||
const swap_type = document.getElementById('swap_type');
|
||||
set_swap_type_enabled(coin_from, coin_to, swap_type);
|
||||
});
|
||||
</script>
|
||||
<script src="static/js/new_offer.js"></script>
|
||||
</div>
|
||||
|
|
|
@ -122,6 +122,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="py-6 border-b border-coolGray-100">
|
||||
<div class="w-full md:w-10/12">
|
||||
<div class="flex flex-wrap -m-3">
|
||||
|
@ -152,6 +153,39 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="py-6 border-b border-coolGray-100">
|
||||
<div class="w-full md:w-10/12">
|
||||
<div class="flex flex-wrap -m-3">
|
||||
<div class="w-full md:w-1/3 p-3">
|
||||
<p class="text-sm text-coolGray-800 font-semibold">Swap Type</p>
|
||||
</div>
|
||||
<div class="w-full md:flex-1 p-3">
|
||||
<div class="relative">
|
||||
<svg class="absolute right-4 top-1/2 transform -translate-y-1/2" width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M11.3333 6.1133C11.2084 5.98913 11.0395 5.91943 10.8633 5.91943C10.6872 5.91943 10.5182 5.98913 10.3933 6.1133L8.00001 8.47329L5.64001 6.1133C5.5151 5.98913 5.34613 5.91943 5.17001 5.91943C4.99388 5.91943 4.82491 5.98913 4.70001 6.1133C4.63752 6.17527 4.58792 6.249 4.55408 6.33024C4.52023 6.41148 4.50281 6.49862 4.50281 6.58663C4.50281 6.67464 4.52023 6.76177 4.55408 6.84301C4.58792 6.92425 4.63752 6.99799 4.70001 7.05996L7.52667 9.88663C7.58865 9.94911 7.66238 9.99871 7.74362 10.0326C7.82486 10.0664 7.912 10.0838 8.00001 10.0838C8.08801 10.0838 8.17515 10.0664 8.25639 10.0326C8.33763 9.99871 8.41136 9.94911 8.47334 9.88663L11.3333 7.05996C11.3958 6.99799 11.4454 6.92425 11.4793 6.84301C11.5131 6.76177 11.5305 6.67464 11.5305 6.58663C11.5305 6.49862 11.5131 6.41148 11.4793 6.33024C11.4454 6.249 11.3958 6.17527 11.3333 6.1133Z" fill="#8896AB"> </path>
|
||||
</svg>
|
||||
<div class="flex absolute inset-y-0 left-0 items-center pl-3 pointer-events-none">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="20" width="20" viewBox="0 0 24 24">
|
||||
<g stroke-linecap="round" stroke-width="2" fill="none" stroke="#3b82f6" stroke-linejoin="round">
|
||||
<path data-cap="butt" d="M11.992,11.737,14.2,13.4A2,2,0,0,1,15,15v1H7V15a2,2,0,0,1,.8-1.6l2.208-1.663" stroke="#3b82f6"></path>
|
||||
<rect x="9" y="7" width="4" height="5" rx="2" ry="2" stroke="#3b82f6"></rect>
|
||||
<path d="M2,1H18a2,2,0,0,1,2,2V21a2,2,0,0,1-2,2H2Z"></path>
|
||||
<line x1="23" y1="5" x2="23" y2="9" stroke="#3b82f6"></line>
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
<select class="pl-10 appearance-none pr-10 bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5" name="swap_type" id="swap_type" disabled>
|
||||
{% for a in swap_types %}
|
||||
<option{% if data.swap_type==a[0] %} selected{% endif %} value="{{ a[0] }}">{{ a[1] }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="py-6 border-b border-coolGray-100">
|
||||
<div class="w-full md:w-10/12">
|
||||
<div class="flex flex-wrap -m-3">
|
||||
|
@ -516,6 +550,7 @@
|
|||
<input type="hidden" name="formid" value="{{ form_id }}">
|
||||
<input type="hidden" name="addr_to" value="{{ data.addr_to }}">
|
||||
<input type="hidden" name="addr_from" value="{{ data.addr_from }}">
|
||||
<input type="hidden" name="swap_type" value="{{ data.swap_type }}">
|
||||
<input type="hidden" name="coin_from" value="{{ data.coin_from }}">
|
||||
<input type="hidden" name="coin_to" value="{{ data.coin_to }}"> {% if data.amt_var==true %}
|
||||
<input type="hidden" name="amt_var" value="true"> {% endif %} {% if data.rate_var==true %}
|
||||
|
|
|
@ -374,6 +374,7 @@
|
|||
<th scope="col" class="py-3 px-6"> Network </th>
|
||||
<th scope="col" class="py-3 px-6"> Recipient </th>
|
||||
<!--<th scope="col" class="py-3 px-6">ID</th>-->
|
||||
<th scope="col" class="py-3">Swap Type</th>
|
||||
<th scope="col" class="py-3"> You Get</th>
|
||||
<th scope="col" class="py-3"></th>
|
||||
<th scope="col" class="py-3"> You Send</th>
|
||||
|
@ -402,6 +403,7 @@
|
|||
<!--Todo: Add link back -->
|
||||
<td class="py-4 px-6">{{ o[7] }} {% if o[12]==2 %}(Revoked){% elif o[11]==true %}(Not Active){% else %}(Active){% endif %}</td>
|
||||
<td class="py-4 px-6 text-xs monospace"><a href="/identity/{{ o[8] }}{% if o[9]==true %}{% endif %}">{{ o[8] }}</a></td>
|
||||
<td class="py-4 text-xs">{{ o[13] }}</td>
|
||||
<td class="py-4"><span class="inline-flex align-middle items-center justify-center w-9 h-10 bg-white-50 rounded">
|
||||
{% if o[9]==true %}
|
||||
<img class="h-7" src="/static/images/coins/{{ o[3]|replace(" ", "-") }}.png" alt=""></span> {{ o[3] }}</td>
|
||||
|
|
|
@ -32,6 +32,8 @@ from basicswap.basicswap_util import (
|
|||
DebugTypes,
|
||||
getLockName,
|
||||
strBidState,
|
||||
strSwapDesc,
|
||||
strSwapType,
|
||||
TxLockTypes,
|
||||
strOfferState,
|
||||
)
|
||||
|
@ -55,6 +57,15 @@ def decode_offer_id(v):
|
|||
raise ValueError('Bad offer ID')
|
||||
|
||||
|
||||
def swap_type_from_string(str_swap_type: str) -> SwapTypes:
|
||||
if str_swap_type == 'seller_first':
|
||||
return SwapTypes.SELLER_FIRST
|
||||
elif str_swap_type == 'xmr_swap':
|
||||
return SwapTypes.XMR_SWAP
|
||||
else:
|
||||
raise ValueError('Unknown swap type')
|
||||
|
||||
|
||||
def parseOfferFormData(swap_client, form_data, page_data, options={}):
|
||||
errors = []
|
||||
parsed_data = {}
|
||||
|
@ -91,11 +102,6 @@ def parseOfferFormData(swap_client, form_data, page_data, options={}):
|
|||
except Exception:
|
||||
errors.append('Unknown Coin To')
|
||||
|
||||
if parsed_data['coin_to'] in (Coins.XMR, Coins.PART_ANON):
|
||||
page_data['swap_style'] = 'xmr'
|
||||
else:
|
||||
page_data['swap_style'] = 'atomic'
|
||||
|
||||
try:
|
||||
page_data['amt_from'] = get_data_entry(form_data, 'amt_from')
|
||||
parsed_data['amt_from'] = inputAmount(page_data['amt_from'], ci_from)
|
||||
|
@ -132,6 +138,29 @@ def parseOfferFormData(swap_client, form_data, page_data, options={}):
|
|||
page_data['rate_var'] = True if have_data_entry(form_data, 'rate_var') else False
|
||||
parsed_data['rate_var'] = page_data['rate_var']
|
||||
|
||||
page_data['automation_strat_id'] = int(get_data_entry_or(form_data, 'automation_strat_id', -1))
|
||||
parsed_data['automation_strat_id'] = page_data['automation_strat_id']
|
||||
swap_type = -1
|
||||
if have_data_entry(form_data, 'swap_type'):
|
||||
page_data['swap_type'] = get_data_entry(form_data, 'swap_type')
|
||||
parsed_data['swap_type'] = page_data['swap_type']
|
||||
swap_type = swap_type_from_string(parsed_data['swap_type'])
|
||||
if have_data_entry(form_data, 'subfee'):
|
||||
parsed_data['subfee'] = True
|
||||
|
||||
if parsed_data['coin_to'] in (Coins.XMR, Coins.PART_ANON) or swap_type == SwapTypes.XMR_SWAP:
|
||||
page_data['swap_style'] = 'xmr'
|
||||
parsed_data['swap_type'] = strSwapType(SwapTypes.XMR_SWAP)
|
||||
else:
|
||||
page_data['swap_style'] = 'atomic'
|
||||
parsed_data['swap_type'] = strSwapType(SwapTypes.SELLER_FIRST)
|
||||
|
||||
if 'swap_type' in parsed_data:
|
||||
try:
|
||||
swap_client.validateSwapType(coin_from, coin_to, swap_type)
|
||||
except Exception as e:
|
||||
errors.append(f'Invalid Swap type {e}')
|
||||
|
||||
if have_data_entry(form_data, 'step1'):
|
||||
if len(errors) == 0 and have_data_entry(form_data, 'continue'):
|
||||
page_data['step2'] = True
|
||||
|
@ -175,13 +204,6 @@ def parseOfferFormData(swap_client, form_data, page_data, options={}):
|
|||
elif have_data_entry(form_data, 'valid_for_seconds'):
|
||||
parsed_data['valid_for_seconds'] = int(get_data_entry(form_data, 'valid_for_seconds'))
|
||||
|
||||
page_data['automation_strat_id'] = int(get_data_entry_or(form_data, 'automation_strat_id', -1))
|
||||
parsed_data['automation_strat_id'] = page_data['automation_strat_id']
|
||||
if have_data_entry(form_data, 'swap_type'):
|
||||
parsed_data['swap_type'] = get_data_entry(form_data, 'swap_type')
|
||||
if have_data_entry(form_data, 'subfee'):
|
||||
parsed_data['subfee'] = True
|
||||
|
||||
try:
|
||||
if len(errors) == 0 and page_data['swap_style'] == 'xmr':
|
||||
if have_data_entry(form_data, 'fee_rate_from'):
|
||||
|
@ -220,12 +242,7 @@ def postNewOfferFromParsed(swap_client, parsed_data):
|
|||
|
||||
if 'swap_type' in parsed_data:
|
||||
str_swap_type = parsed_data['swap_type'].lower()
|
||||
if str_swap_type == 'seller_first':
|
||||
swap_type = SwapTypes.SELLER_FIRST
|
||||
elif str_swap_type == 'xmr_swap':
|
||||
swap_type = SwapTypes.XMR_SWAP
|
||||
else:
|
||||
raise ValueError('Unknown swap type')
|
||||
swap_type = swap_type_from_string(str_swap_type)
|
||||
elif parsed_data['coin_to'] in (Coins.XMR, Coins.PART_ANON):
|
||||
swap_type = SwapTypes.XMR_SWAP
|
||||
|
||||
|
@ -319,6 +336,7 @@ def offer_to_post_string(self, swap_client, offer_id):
|
|||
'rate': ci_to.format_amount(offer.rate),
|
||||
'amt_to': ci_to.format_amount((offer.amount_from * offer.rate) // ci_from.COIN()),
|
||||
'validhrs': offer.time_valid // (60 * 60),
|
||||
'swap_type': strSwapType(offer.swap_type),
|
||||
}
|
||||
|
||||
if offer.amount_negotiable:
|
||||
|
@ -359,6 +377,7 @@ def page_newoffer(self, url_split, post_string):
|
|||
'debug_ui': swap_client.debug_ui,
|
||||
'automation_strat_id': -1,
|
||||
'amt_bid_min': format_amount(1000, 8),
|
||||
'swap_type': strSwapType(SwapTypes.SELLER_FIRST),
|
||||
}
|
||||
|
||||
post_data = parse.parse_qs(post_string)
|
||||
|
@ -416,6 +435,7 @@ def page_newoffer(self, url_split, post_string):
|
|||
'data': page_data,
|
||||
'automation_strategies': automation_strategies,
|
||||
'summary': summary,
|
||||
'swap_types': [(strSwapType(x), strSwapDesc(x)) for x in SwapTypes if strSwapType(x)],
|
||||
})
|
||||
|
||||
|
||||
|
@ -532,7 +552,8 @@ def page_offer(self, url_split, post_string):
|
|||
'debug_ui': swap_client.debug_ui,
|
||||
'automation_strat_id': -1,
|
||||
'is_expired': offer.expire_at <= now,
|
||||
'active_ind': offer.active_ind
|
||||
'active_ind': offer.active_ind,
|
||||
'swap_type': strSwapDesc(offer.swap_type)
|
||||
}
|
||||
data.update(extend_data)
|
||||
|
||||
|
@ -660,7 +681,8 @@ def page_offers(self, url_split, post_string, sent=False):
|
|||
o.was_sent,
|
||||
ci_from.format_amount(completed_amount),
|
||||
is_expired,
|
||||
o.active_ind))
|
||||
o.active_ind,
|
||||
strSwapDesc(o.swap_type)))
|
||||
|
||||
coins_from, coins_to = listAvailableCoins(swap_client, split_from=True)
|
||||
|
||||
|
|
Loading…
Reference in a new issue