From 3e4c3f10cf78c78548836bb408395e69d63c2022 Mon Sep 17 00:00:00 2001 From: tecnovert Date: Tue, 4 Jun 2024 13:45:52 +0200 Subject: [PATCH] scripts: Set offer min_bid_amount from offer template min_swap_amount value. --- basicswap/js_server.py | 1 + basicswap/ui/page_offers.py | 2 +- scripts/createoffers.py | 4 +++- tests/basicswap/extended/test_scripts.py | 10 +++++++--- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/basicswap/js_server.py b/basicswap/js_server.py index 0b51de1..05a4626 100644 --- a/basicswap/js_server.py +++ b/basicswap/js_server.py @@ -228,6 +228,7 @@ def js_offers(self, url_split, post_string, is_json, sent=False) -> bytes: 'amount_from': ci_from.format_amount(o.amount_from), 'amount_to': ci_to.format_amount((o.amount_from * o.rate) // ci_from.COIN()), 'rate': ci_to.format_amount(o.rate), + 'min_bid_amount': ci_from.format_amount(o.min_bid_amount), } if with_extra_info: offer_data['amount_negotiable'] = o.amount_negotiable diff --git a/basicswap/ui/page_offers.py b/basicswap/ui/page_offers.py index e1e10d4..51b7102 100644 --- a/basicswap/ui/page_offers.py +++ b/basicswap/ui/page_offers.py @@ -115,7 +115,7 @@ def parseOfferFormData(swap_client, form_data, page_data, options={}): errors.append('Amount From') try: - if 'amt_bid_min' not in page_data: + if have_data_entry(form_data, 'amt_bid_min') is False: if options.get('add_min_bid_amt', False) is True: parsed_data['amt_bid_min'] = ci_from.chainparams_network()['min_amount'] else: diff --git a/scripts/createoffers.py b/scripts/createoffers.py index a6d6da0..5f7e531 100755 --- a/scripts/createoffers.py +++ b/scripts/createoffers.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2023 tecnovert +# Copyright (c) 2023-2024 tecnovert # Distributed under the MIT software license, see the accompanying # file LICENSE or http://www.opensource.org/licenses/mit-license.php. @@ -323,6 +323,8 @@ def main(): 'swap_type': offer_template.get('swap_type', 'adaptor_sig'), 'lockhrs': '24', 'automation_strat_id': 1} + if 'min_swap_amount' in offer_template: + offer_data['amt_bid_min'] = offer_template['min_swap_amount'] if args.debug: print('offer data {}'.format(offer_data)) new_offer = read_json_api('offers/new', offer_data) diff --git a/tests/basicswap/extended/test_scripts.py b/tests/basicswap/extended/test_scripts.py index 2837f09..8aad9fe 100644 --- a/tests/basicswap/extended/test_scripts.py +++ b/tests/basicswap/extended/test_scripts.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright (c) 2023 tecnovert +# Copyright (c) 2023-2024 tecnovert # Distributed under the MIT software license, see the accompanying # file LICENSE or http://www.opensource.org/licenses/mit-license.php. @@ -304,7 +304,8 @@ class Test(unittest.TestCase): 'amount_variable': True, 'address': -1, 'min_coin_from_amt': 20, - 'max_coin_to_amt': -1 + 'max_coin_to_amt': -1, + 'min_swap_amount': 0.11, }, { 'name': 'offer example 1_2', @@ -316,7 +317,8 @@ class Test(unittest.TestCase): 'amount_variable': True, 'address': -1, 'min_coin_from_amt': 21, - 'max_coin_to_amt': -1 + 'max_coin_to_amt': -1, + 'min_swap_amount': 0.12, } ], } @@ -330,6 +332,8 @@ class Test(unittest.TestCase): offers = read_json_api(UI_PORT, 'offers') assert (len(offers) == 1) + offer_min_bid_amount = float(offers[0]['min_bid_amount']) + assert (offer_min_bid_amount == 0.11 or offer_min_bid_amount == 0.12) logging.info('Test that an offer is not created while delaying') result = subprocess.run(self.node0_args, stdout=subprocess.PIPE)