ui: Add sent offer status filter.

2024-05-20_merge
tecnovert 2 years ago
parent 6e5c54b447
commit ba5339d8bd
No known key found for this signature in database
GPG Key ID: 8ED6D8750C4E3F93
  1. 8
      basicswap/basicswap.py
  2. 22
      basicswap/templates/offers.html
  3. 6
      basicswap/ui/page_offers.py

@ -5697,6 +5697,14 @@ class BasicSwap(BaseApp):
if sent: if sent:
q = q.filter(Offer.was_sent == True) # noqa: E712 q = q.filter(Offer.was_sent == True) # noqa: E712
active_state = filters.get('active', 'any')
if active_state == 'active':
q = q.filter(Offer.expire_at > now, Offer.active_ind == 1)
elif active_state == 'expired':
q = q.filter(Offer.expire_at <= now)
elif active_state == 'revoked':
q = q.filter(Offer.active_ind != 1)
else: else:
q = q.filter(sa.and_(Offer.expire_at > now, Offer.active_ind == 1)) q = q.filter(sa.and_(Offer.expire_at > now, Offer.active_ind == 1))

@ -36,7 +36,7 @@
<h2 class="mb-6 text-4xl font-bold text-white tracking-tighter">{{ page_type }}</h2> <h2 class="mb-6 text-4xl font-bold text-white tracking-tighter">{{ page_type }}</h2>
<p class="font-semibold text-coolGray-200">{{ page_type_description }}</p> <p class="font-semibold text-coolGray-200">{{ page_type_description }}</p>
</div> </div>
<div class="{{ page_button }} w-full md:w-1/2 p-3 p-6 container flex flex-wrap items-center justify-end items-center mx-auto"> <div class="{{ page_button }} w-full md:w-1/2 p-3 p-6 container flex flex-wrap items-center justify-end items-center mx-auto">
<a id="refresh" href="/newoffer" class="flex flex-wrap justify-center px-5 py-4 bg-blue-500 hover:bg-blue-600 font-medium text-sm text-white border border-blue-500 rounded-md shadow-button focus:ring-0 focus:outline-none"> <a id="refresh" href="/newoffer" class="flex flex-wrap justify-center px-5 py-4 bg-blue-500 hover:bg-blue-600 font-medium text-sm text-white border border-blue-500 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="18" width="18" viewBox="0 0 24 24"> <svg class="text-gray-500 w-5 h-5 mr-2" xmlns="http://www.w3.org/2000/svg" height="18" width="18" viewBox="0 0 24 24">
<g stroke-linecap="round" stroke-width="2" fill="none" stroke="#ffffff" stroke-linejoin="round"> <g stroke-linecap="round" stroke-width="2" fill="none" stroke="#ffffff" stroke-linejoin="round">
@ -309,6 +309,26 @@
</select> </select>
</div> </div>
</div> </div>
{% if sent_offers %}
<div class="flex items-center">
<div class="w-full md:w-auto p-1.5">
<p class="text-sm font-heading bold">State:</p>
</div>
</div>
<div class="w-full md:w-auto p-1.5">
<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>
<select name="active" class="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="any" {% if filters.active=='any' %} selected{% endif %}>Any</option>
<option value="active" {% if filters.active=='active' %} selected{% endif %}>Active</option>
<option value="expired" {% if filters.active=='expired' %} selected{% endif %}>Expired</option>
<option value="revoked" {% if filters.active=='revoked' %} selected{% endif %}>Revoked</option>
</select>
</div>
</div>
{% endif %}
<div class="w-full md:w-auto p-1.5"> <div class="w-full md:w-auto p-1.5">
<div class="relative"> <div class="relative">
<button type="submit" name='clearfilters' value="Clear Filters" 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"> <button type="submit" name='clearfilters' value="Clear Filters" 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">

@ -577,6 +577,7 @@ def page_offers(self, url_split, post_string, sent=False):
'sort_by': 'created_at', 'sort_by': 'created_at',
'sort_dir': 'desc', 'sort_dir': 'desc',
'sent_from': 'any' if sent is False else 'only', 'sent_from': 'any' if sent is False else 'only',
'active': 'any',
} }
messages = [] messages = []
form_data = self.checkForm(post_string, 'offers', messages) form_data = self.checkForm(post_string, 'offers', messages)
@ -596,6 +597,10 @@ def page_offers(self, url_split, post_string, sent=False):
sent_from = get_data_entry(form_data, 'sent_from') sent_from = get_data_entry(form_data, 'sent_from')
ensure(sent_from in ['any', 'only'], 'Invalid sent filter') ensure(sent_from in ['any', 'only'], 'Invalid sent filter')
filters['sent_from'] = sent_from filters['sent_from'] = sent_from
if have_data_entry(form_data, 'active'):
active_filter = get_data_entry(form_data, 'active')
ensure(active_filter in ['any', 'active', 'expired', 'revoked'], 'Invalid active filter')
filters['active'] = active_filter
set_pagination_filters(form_data, filters) set_pagination_filters(form_data, filters)
@ -648,4 +653,5 @@ def page_offers(self, url_split, post_string, sent=False):
'filters': filters, 'filters': filters,
'offers': formatted_offers, 'offers': formatted_offers,
'summary': summary, 'summary': summary,
'sent_offers': sent,
}) })

Loading…
Cancel
Save