mirror of
https://github.com/basicswap/basicswap.git
synced 2024-11-17 00:07:56 +00:00
ui: Fix xmr svg path, edit offer automation strategy.
This commit is contained in:
parent
09cc523ac3
commit
06065958b7
7 changed files with 117 additions and 15 deletions
|
@ -1587,6 +1587,33 @@ class BasicSwap(BaseApp):
|
|||
finally:
|
||||
self.closeSession(session)
|
||||
|
||||
def editOffer(self, offer_id, data) -> None:
|
||||
self.log.info('Editing offer %s', offer_id.hex())
|
||||
session = self.openSession()
|
||||
try:
|
||||
offer = session.query(Offer).filter_by(offer_id=offer_id).first()
|
||||
if 'automation_strat_id' in data:
|
||||
new_automation_strat_id = data['automation_strat_id']
|
||||
link = session.query(AutomationLink).filter_by(linked_type=Concepts.OFFER, linked_id=offer.offer_id).first()
|
||||
if not link:
|
||||
if new_automation_strat_id > 0:
|
||||
link = AutomationLink(
|
||||
active_ind=1,
|
||||
linked_type=Concepts.OFFER,
|
||||
linked_id=offer_id,
|
||||
strategy_id=new_automation_strat_id,
|
||||
created_at=int(time.time()))
|
||||
session.add(link)
|
||||
else:
|
||||
if new_automation_strat_id < 1:
|
||||
link.active_ind = 0
|
||||
else:
|
||||
link.strategy_id = new_automation_strat_id
|
||||
link.active_ind = 1
|
||||
session.add(link)
|
||||
finally:
|
||||
self.closeSession(session)
|
||||
|
||||
def grindForEd25519Key(self, coin_type, evkey, key_path_base) -> bytes:
|
||||
ci = self.ci(coin_type)
|
||||
nonce = 1
|
||||
|
|
|
@ -411,7 +411,7 @@
|
|||
<div class="container mx-auto">
|
||||
<div class="overflow-x-auto items-center justify-center relative border sm:rounded-lg p-10">
|
||||
<div class="flex items-center justify-center min-h-screen">
|
||||
<div class="flex items-center justify-between text-white"> <img class="h-full py-2 pr-4 ml-8" src="/static/sequence_diagrams/bidder.alt.xu.min.svg"> </div>
|
||||
<div class="flex items-center justify-between text-white"> <img class="h-full py-2 pr-4 ml-8" src="/static/sequence_diagrams/xmr.bidder.alt.xu.min.svg"> </div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
@ -427,7 +427,7 @@
|
|||
<div class="container mx-auto">
|
||||
<div class="overflow-x-auto items-center justify-center relative border sm:rounded-lg p-10">
|
||||
<div class="flex items-center justify-center min-h-screen">
|
||||
<div class="flex items-center justify-between text-white"> <img class="h-full py-2 pr-4 ml-8" src="/static/sequence_diagrams/offerer.alt.xu.min.svg"> </div>
|
||||
<div class="flex items-center justify-between text-white"> <img class="h-full py-2 pr-4 ml-8" src="/static/sequence_diagrams/xmr.offerer.alt.xu.min.svg"> </div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
|
|
@ -256,7 +256,45 @@
|
|||
</div>
|
||||
</div>
|
||||
<form method="post">
|
||||
{% if data.show_bid_form %}
|
||||
{% if data.show_edit_form %}
|
||||
<section class="bg-white p-6">
|
||||
<div class="flex flex-wrap items-center">
|
||||
<div class="w-full">
|
||||
<h4 class="font-semibold text-black text-2xl">Edit Offer</h4> </div>
|
||||
</div>
|
||||
</section>
|
||||
<div class="container px-0 mx-auto">
|
||||
<div class="overflow-x-auto relative border sm:rounded-lg">
|
||||
<table class="w-full text-sm text-left text-gray-500 outline-none border-gray-300">
|
||||
<tr>
|
||||
<td class="pr-2 bold">Auto Accept Strategy:</td>
|
||||
<td>
|
||||
<select name="automation_strat_id" 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">
|
||||
<option value="-1" {% if data.automation_strat_id==-1 %} selected{% endif %}>None</option>
|
||||
{% for a in data.automation_strategies %}
|
||||
<option value="{{ a[0] }}" {% if data.automation_strat_id==a[0] %} selected{% endif %}>{{ a[1] }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="p-6 pt-10 bg-white bg-opacity-60 rounded-b-md">
|
||||
<div class="w-full md:w-0/12">
|
||||
<div class="flex flex-wrap justify-end -m-1.5">
|
||||
<div class="w-full md:w-auto p-1.5 ml-2">
|
||||
<button name="edit_offer_cancel" value="Cancel" type="submit" class="flex flex-wrap justify-center w-full px-4 py-2.5 font-medium text-sm text-red-500 hover:text-red-600 border border-red-400 hover:border-red-500 bg-white rounded-md shadow-button focus:ring-0 focus:outline-none">
|
||||
<svg class="text-gray-500 w-5 h-5 mr-2" xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewBox="0 0 24 24"><g stroke-linecap="round" stroke-width="2" fill="none" stroke="#ef5844" stroke-linejoin="round" ><line x1="16" y1="8" x2="8" y2="16" stroke="#ef5844"></line> <line x1="16" y1="16" x2="8" y2="8" stroke="#ef5844"></line> <circle cx="12" cy="12" r="11"></circle></g></svg> Cancel </button>
|
||||
</div>
|
||||
<div class="w-full md:w-auto p-1.5">
|
||||
<button name="edit_offer_submit" value="Submit" type="submit" class="flex flex-wrap justify-center w-full px-4 py-2.5 font-medium text-sm text-coolGray-500 hover:text-coolGray-600 border border-coolGray-200 hover:border-coolGray-300 bg-white rounded-md shadow-button focus:ring-0 focus:outline-none">
|
||||
<svg class="text-gray-500 w-5 h-5 mr-2" xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewBox="0 0 24 24"><g stroke-linecap="round" stroke-width="2" fill="none" stroke="#556987" stroke-linejoin="round" ><line x1="2" y1="23" x2="22" y2="23" stroke="#556987"></line> <line data-cap="butt" x1="13" y1="5" x2="17" y2="9"></line> <polygon points="8 18 3 19 4 14 16 2 20 6 8 18"></polygon></g></svg> Submit Edit </button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% elif data.show_bid_form %}
|
||||
<section class="bg-white p-6">
|
||||
<div class="flex flex-wrap items-center">
|
||||
<div class="w-full">
|
||||
|
@ -400,6 +438,9 @@
|
|||
<button name="revoke_offer" value="Revoke Offer" type="submit" onclick="return confirmPopup();" class="flex flex-wrap justify-center w-full px-4 py-2.5 font-medium text-sm text-red-500 hover:text-red-600 border border-red-400 hover:border-red-500 bg-white rounded-md shadow-button focus:ring-0 focus:outline-none"><svg class="text-gray-500 w-5 h-5 mr-2" xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewBox="0 0 24 24"><g stroke-linecap="round" stroke-width="2" fill="none" stroke="#ef5844" stroke-linejoin="round" ><line x1="16" y1="8" x2="8" y2="16" stroke="#ef5844"></line> <line x1="16" y1="16" x2="8" y2="8" stroke="#ef5844"></line> <circle cx="12" cy="12" r="11"></circle></g></svg> Revoke Offer </button>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="w-full md:w-auto p-1.5">
|
||||
<button name="edit_offer" value="Edit Offer" type="submit" class="flex flex-wrap justify-center w-full px-4 py-2.5 font-medium text-sm text-red-500 hover:text-red-600 border border-red-400 hover:border-red-500 bg-white rounded-md shadow-button focus:ring-0 focus:outline-none">Edit Offer</button>
|
||||
</div>
|
||||
<!-- todo
|
||||
{% if data.active_ind == 1 %}
|
||||
<div class="w-full md:w-auto p-1.5">
|
||||
|
|
|
@ -429,9 +429,7 @@ def page_newoffer(self, url_split, post_string):
|
|||
|
||||
coins_from, coins_to = listAvailableCoins(swap_client, split_from=True)
|
||||
|
||||
automation_filters = {}
|
||||
automation_filters['sort_by'] = 'label'
|
||||
automation_filters['type_ind'] = Concepts.OFFER
|
||||
automation_filters = {'type_ind': Concepts.OFFER, 'sort_by': 'label'}
|
||||
automation_strategies = swap_client.listAutomationStrategies(automation_filters)
|
||||
|
||||
return self.render_template(template, {
|
||||
|
@ -467,6 +465,7 @@ def page_offer(self, url_split, post_string):
|
|||
messages.append('Debug mode active.')
|
||||
sent_bid_id = None
|
||||
show_bid_form = None
|
||||
show_edit_form = None
|
||||
form_data = self.checkForm(post_string, 'offer', err_messages)
|
||||
|
||||
ci_from = swap_client.ci(Coins(offer.coin_from))
|
||||
|
@ -496,6 +495,14 @@ def page_offer(self, url_split, post_string):
|
|||
self.send_header('Location', '/newoffer?offer_from=' + offer_id.hex())
|
||||
self.end_headers()
|
||||
return bytes()
|
||||
elif b'edit_offer' in form_data:
|
||||
show_edit_form = True
|
||||
automation_filters = {'type_ind': Concepts.OFFER, 'sort_by': 'label'}
|
||||
extend_data['automation_strategies'] = swap_client.listAutomationStrategies(automation_filters)
|
||||
elif b'edit_offer_submit' in form_data:
|
||||
change_data = {}
|
||||
change_data['automation_strat_id'] = int(get_data_entry_or(form_data, 'automation_strat_id', -1))
|
||||
swap_client.editOffer(offer_id, change_data)
|
||||
elif b'newbid' in form_data:
|
||||
show_bid_form = True
|
||||
elif b'sendbid' in form_data:
|
||||
|
@ -554,6 +561,7 @@ def page_offer(self, url_split, post_string):
|
|||
'sent': offer.was_sent,
|
||||
'was_revoked': 'True' if offer.active_ind == 2 else 'False',
|
||||
'show_bid_form': show_bid_form,
|
||||
'show_edit_form': show_edit_form,
|
||||
'amount_negotiable': offer.amount_negotiable,
|
||||
'rate_negotiable': offer.rate_negotiable,
|
||||
'bid_amount': bid_amount,
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
- ui: Fix pagination clearing filters
|
||||
- Added restrict_unknown_seed_wallets option.
|
||||
- Set to false to disable unknown seed warnings.
|
||||
- ui: Can edit offer automation strategy.
|
||||
|
||||
|
||||
0.0.54
|
||||
|
|
|
@ -378,17 +378,29 @@ def main():
|
|||
offer_id = offer['offer_id']
|
||||
offer_amount = float(offer['amount_from'])
|
||||
offer_rate = float(offer['rate'])
|
||||
bid_amount = offer_amount
|
||||
bid_amount = bid_template['amount']
|
||||
|
||||
min_swap_amount = bid_template.get('min_swap_amount', 0.01) # TODO: Make default vary per coin
|
||||
can_adjust_amount: bool = offer['amount_negotiable'] and bid_template.get('amount_variable', True)
|
||||
if can_adjust_amount is False and offer_amount > bid_template['amount']:
|
||||
can_adjust_offer_amount: bool = offer['amount_negotiable']
|
||||
can_adjust_bid_amount: bool = bid_template.get('amount_variable', True)
|
||||
can_adjust_amount: bool = can_adjust_offer_amount and can_adjust_bid_amount
|
||||
|
||||
if offer_amount < min_swap_amount:
|
||||
if args.debug:
|
||||
print(f'Offer amount below min swap amount bid {offer_id}')
|
||||
continue
|
||||
|
||||
if can_adjust_offer_amount is False and offer_amount > bid_amount:
|
||||
if args.debug:
|
||||
print(f'Bid amount too low for offer {offer_id}')
|
||||
continue
|
||||
if (can_adjust_amount is False and offer_amount < bid_template['amount']) or offer_amount < min_swap_amount:
|
||||
|
||||
if bid_amount > offer_amount:
|
||||
if can_adjust_bid_amount:
|
||||
bid_amount = offer_amount
|
||||
else:
|
||||
if args.debug:
|
||||
print(f'Offer amount too low for bid {offer_id}')
|
||||
print(f'Bid amount too high for offer {offer_id}')
|
||||
continue
|
||||
|
||||
if offer_rate > bid_template['maxrate']:
|
||||
|
|
|
@ -373,6 +373,19 @@ class Test(unittest.TestCase):
|
|||
}
|
||||
}
|
||||
|
||||
logging.info('Check max bid value')
|
||||
result = subprocess.run(self.node1_args, stdout=subprocess.PIPE)
|
||||
rv_stdout = result.stdout.decode().split('\n')
|
||||
possible_bids = get_possible_bids(rv_stdout)
|
||||
assert (len(possible_bids) == 1)
|
||||
assert (float(possible_bids[0]['amount_from']) == 10.0)
|
||||
|
||||
logging.info('Raise node1 bid0 value')
|
||||
node1_test1_config['bids'][0]['amount'] = 50
|
||||
with open(self.node1_configfile, 'w') as fp:
|
||||
json.dump(node1_test1_config, fp, indent=4)
|
||||
delete_file(self.node1_statefile)
|
||||
|
||||
# Check max_coin_from_balance (bids increase coin_from)
|
||||
result = subprocess.run(self.node1_args, stdout=subprocess.PIPE)
|
||||
rv_stdout = result.stdout.decode().split('\n')
|
||||
|
@ -570,7 +583,7 @@ class Test(unittest.TestCase):
|
|||
result = subprocess.run(self.node1_args, stdout=subprocess.PIPE)
|
||||
rv_stdout = result.stdout.decode().split('\n')
|
||||
assert (len(get_created_bids(rv_stdout)) == 0)
|
||||
assert (count_lines_with(rv_stdout, 'Offer amount too low for bid') == 3)
|
||||
assert (count_lines_with(rv_stdout, 'Bid amount too high for offer') == 3)
|
||||
|
||||
node1_test1_config['bids'][0]['amount_variable'] = True
|
||||
with open(self.node1_configfile, 'w') as fp:
|
||||
|
|
Loading…
Reference in a new issue