diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index ea2e5af..f7def90 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -5315,7 +5315,17 @@ class BasicSwap(BaseApp): query_str += 'AND bids.was_sent = 1 ' else: query_str += 'AND bids.was_received = 1 ' - query_str += ' ORDER BY bids.created_at DESC' + + sort_dir = filters.get('sort_dir', 'DESC').upper() + sort_by = filters.get('sort_by', 'created_at') + query_str += f' ORDER BY bids.{sort_by} {sort_dir}' + + limit = filters.get('limit', None) + if limit is not None: + query_str += f' LIMIT {limit}' + offset = filters.get('offset', None) + if offset is not None: + query_str += f' OFFSET {offset}' q = session.execute(query_str) for row in q: diff --git a/basicswap/http_server.py b/basicswap/http_server.py index eca218c..9685426 100644 --- a/basicswap/http_server.py +++ b/basicswap/http_server.py @@ -871,24 +871,24 @@ class HttpHandler(BaseHTTPRequestHandler): } messages = [] form_data = self.checkForm(post_string, 'offers', messages) - if form_data and b'applyfilters' in form_data: + if form_data and have_data_entry(form_data, 'applyfilters'): filters['coin_from'] = setCoinFilter(form_data, 'coin_from') filters['coin_to'] = setCoinFilter(form_data, 'coin_to') - if b'sort_by' in form_data: - sort_by = form_data[b'sort_by'][0].decode('utf-8') + if have_data_entry(form_data, 'sort_by'): + sort_by = get_data_entry(form_data, 'sort_by') assert(sort_by in ['created_at', 'rate']), 'Invalid sort by' filters['sort_by'] = sort_by - if b'sort_dir' in form_data: - sort_dir = form_data[b'sort_dir'][0].decode('utf-8') + if have_data_entry(form_data, 'sort_dir'): + sort_dir = get_data_entry(form_data, 'sort_dir') assert(sort_dir in ['asc', 'desc']), 'Invalid sort dir' filters['sort_dir'] = sort_dir - if form_data and b'pageback' in form_data: + if form_data and have_data_entry(form_data, 'pageback'): filters['page_no'] = int(form_data[b'pageno'][0]) - 1 if filters['page_no'] < 1: filters['page_no'] = 1 - elif form_data and b'pageforwards' in form_data: + elif form_data and have_data_entry(form_data, 'pageforwards'): filters['page_no'] = int(form_data[b'pageno'][0]) + 1 if filters['page_no'] > 1: @@ -921,22 +921,6 @@ class HttpHandler(BaseHTTPRequestHandler): form_id=os.urandom(8).hex(), ), 'UTF-8') - def page_advance(self, url_split, post_string): - assert(len(url_split) > 2), 'Bid ID not specified' - try: - bid_id = bytes.fromhex(url_split[2]) - assert(len(bid_id) == 28) - except Exception: - raise ValueError('Bad bid ID') - swap_client = self.server.swap_client - - template = env.get_template('advance.html') - return bytes(template.render( - title=self.server.title, - h2=self.server.title, - bid_id=bid_id.hex(), - ), 'UTF-8') - def page_bid(self, url_split, post_string): assert(len(url_split) > 2), 'Bid ID not specified' try: @@ -1025,15 +1009,47 @@ class HttpHandler(BaseHTTPRequestHandler): def page_bids(self, url_split, post_string, sent=False): swap_client = self.server.swap_client - bids = swap_client.listBids(sent=sent) + + filters = { + 'page_no': 1, + 'limit': PAGE_LIMIT, + 'sort_by': 'created_at', + 'sort_dir': 'desc', + } + messages = [] + form_data = self.checkForm(post_string, 'bids', messages) + if form_data and have_data_entry(form_data, 'applyfilters'): + if have_data_entry(form_data, 'sort_by'): + sort_by = get_data_entry(form_data, 'sort_by') + assert(sort_by in ['created_at', ]), 'Invalid sort by' + filters['sort_by'] = sort_by + if have_data_entry(form_data, 'sort_dir'): + sort_dir = get_data_entry(form_data, 'sort_dir') + assert(sort_dir in ['asc', 'desc']), 'Invalid sort dir' + filters['sort_dir'] = sort_dir + + if form_data and have_data_entry(form_data, 'pageback'): + filters['page_no'] = int(form_data[b'pageno'][0]) - 1 + if filters['page_no'] < 1: + filters['page_no'] = 1 + elif form_data and have_data_entry(form_data, 'pageforwards'): + filters['page_no'] = int(form_data[b'pageno'][0]) + 1 + + if filters['page_no'] > 1: + filters['offset'] = (filters['page_no'] - 1) * PAGE_LIMIT + + bids = swap_client.listBids(sent=sent, filters=filters) template = env.get_template('bids.html') return bytes(template.render( title=self.server.title, h2=self.server.title, page_type='Sent' if sent else 'Received', + messages=messages, + filters=filters, bids=[(format_timestamp(b[0]), b[2].hex(), b[3].hex(), strBidState(b[5]), strTxState(b[7]), strTxState(b[8]), b[11]) for b in bids], + form_id=os.urandom(8).hex(), ), 'UTF-8') def page_watched(self, url_split, post_string): @@ -1264,8 +1280,6 @@ class HttpHandler(BaseHTTPRequestHandler): return self.page_newoffer(url_split, post_string) if url_split[1] == 'sentoffers': return self.page_offers(url_split, post_string, sent=True) - if url_split[1] == 'advance': - return self.page_advance(url_split, post_string) if url_split[1] == 'bid': return self.page_bid(url_split, post_string) if url_split[1] == 'bids': diff --git a/basicswap/templates/advance.html b/basicswap/templates/advance.html deleted file mode 100644 index f246295..0000000 --- a/basicswap/templates/advance.html +++ /dev/null @@ -1,6 +0,0 @@ -{% include 'header.html' %} - -

Advance Bid {{ bid_id }}

- -

home

- diff --git a/basicswap/templates/bids.html b/basicswap/templates/bids.html index 64d96c2..392e7ab 100644 --- a/basicswap/templates/bids.html +++ b/basicswap/templates/bids.html @@ -4,6 +4,29 @@ {% if refresh %}

Page Refresh: {{ refresh }} seconds

{% endif %} +{% for m in messages %} +

{{ m }}

+{% endfor %} + +
+ + + + + + +
Sort By + + +
Page: {{ filters.page_no }}
+ + +
AtBid IDOffer IDBid FromBid StatusITX StatusPTX Status