ui: Add persistent filters, show only active bid and offer counts.

Add titles for offer clock states.
This commit is contained in:
tecnovert 2023-05-10 17:50:40 +02:00
parent 1093eaed3b
commit 2b2b98505b
No known key found for this signature in database
GPG key ID: 8ED6D8750C4E3F93
10 changed files with 153 additions and 78 deletions

View file

@ -1,3 +1,3 @@
name = "basicswap" name = "basicswap"
__version__ = "0.11.61" __version__ = "0.11.62"

View file

@ -963,18 +963,16 @@ class BasicSwap(BaseApp):
if session is None: if session is None:
self.closeSession(use_session) self.closeSession(use_session)
def getStringKV(self, str_key: str) -> Optional[str]: def getStringKV(self, str_key: str, session=None) -> Optional[str]:
self.mxDB.acquire()
try: try:
session = scoped_session(self.session_factory) use_session = self.openSession(session)
v = session.query(DBKVString).filter_by(key=str_key).first() v = use_session.query(DBKVString).filter_by(key=str_key).first()
if not v: if not v:
return None return None
return v.value return v.value
finally: finally:
session.close() if session is None:
session.remove() self.closeSession(use_session, commit=False)
self.mxDB.release()
def clearStringKV(self, str_key: str, str_val: str) -> None: def clearStringKV(self, str_key: str, str_val: str) -> None:
with self.mxDB: with self.mxDB:
@ -5793,31 +5791,37 @@ class BasicSwap(BaseApp):
now: int = self.getTime() now: int = self.getTime()
q_str = '''SELECT q_str = '''SELECT
COUNT(CASE WHEN b.was_sent THEN 1 ELSE NULL END) AS count_sent, COUNT(CASE WHEN b.was_sent THEN 1 ELSE NULL END) AS count_sent,
COUNT(CASE WHEN b.was_sent AND b.state = {} AND b.expire_at > {} AND o.expire_at > {} THEN 1 ELSE NULL END) AS count_sent_active,
COUNT(CASE WHEN b.was_received THEN 1 ELSE NULL END) AS count_received, COUNT(CASE WHEN b.was_received THEN 1 ELSE NULL END) AS count_received,
COUNT(CASE WHEN b.was_received AND b.state = {} AND b.expire_at > {} AND o.expire_at > {} THEN 1 ELSE NULL END) AS count_available COUNT(CASE WHEN b.was_received AND b.state = {} AND b.expire_at > {} AND o.expire_at > {} THEN 1 ELSE NULL END) AS count_available
FROM bids b FROM bids b
JOIN offers o ON b.offer_id = o.offer_id JOIN offers o ON b.offer_id = o.offer_id
WHERE b.active_ind = 1'''.format(BidStates.BID_RECEIVED, now, now) WHERE b.active_ind = 1'''.format(BidStates.BID_RECEIVED, now, now, BidStates.BID_RECEIVED, now, now)
q = self.engine.execute(q_str).first() q = self.engine.execute(q_str).first()
bids_sent = q[0] bids_sent = q[0]
bids_received = q[1] bids_sent_active = q[1]
bids_available = q[2] bids_received = q[2]
bids_available = q[3]
q_str = '''SELECT q_str = '''SELECT
COUNT(CASE WHEN expire_at > {} THEN 1 ELSE NULL END) AS count_active, COUNT(CASE WHEN expire_at > {} THEN 1 ELSE NULL END) AS count_active,
COUNT(CASE WHEN was_sent THEN 1 ELSE NULL END) AS count_sent COUNT(CASE WHEN was_sent THEN 1 ELSE NULL END) AS count_sent,
FROM offers WHERE active_ind = 1'''.format(now) COUNT(CASE WHEN was_sent AND expire_at > {} THEN 1 ELSE NULL END) AS count_sent_active
FROM offers WHERE active_ind = 1'''.format(now, now)
q = self.engine.execute(q_str).first() q = self.engine.execute(q_str).first()
num_offers = q[0] num_offers = q[0]
num_sent_offers = q[1] num_sent_offers = q[1]
num_sent_active_offers = q[2]
rv = { rv = {
'network': self.chain, 'network': self.chain,
'num_swapping': len(self.swaps_in_progress), 'num_swapping': len(self.swaps_in_progress),
'num_network_offers': num_offers, 'num_network_offers': num_offers,
'num_sent_offers': num_sent_offers, 'num_sent_offers': num_sent_offers,
'num_sent_active_offers': num_sent_active_offers,
'num_recv_bids': bids_received, 'num_recv_bids': bids_received,
'num_sent_bids': bids_sent, 'num_sent_bids': bids_sent,
'num_sent_active_bids': bids_sent_active,
'num_available_bids': bids_available, 'num_available_bids': bids_available,
'num_watched_outputs': num_watched_outputs, 'num_watched_outputs': num_watched_outputs,
} }
@ -6591,3 +6595,30 @@ class BasicSwap(BaseApp):
return rv_array return rv_array
return rv return rv
def setFilters(self, prefix, filters):
try:
session = self.openSession()
key_str = 'saved_filters_' + prefix
value_str = json.dumps(filters)
self.setStringKV(key_str, value_str, session)
finally:
self.closeSession(session)
def getFilters(self, prefix):
try:
session = self.openSession()
key_str = 'saved_filters_' + prefix
value_str = self.getStringKV(key_str, session)
return None if not value_str else json.loads(value_str)
finally:
self.closeSession(session, commit=False)
def clearFilters(self, prefix):
try:
session = self.openSession()
key_str = 'saved_filters_' + prefix
query_str = 'DELETE FROM kv_string WHERE key = :key_str'
session.execute(query_str, {'key_str': key_str})
finally:
self.closeSession(session)

View file

@ -457,7 +457,7 @@
<polyline points=" 16,2 13,5 16,8 " stroke="#6b7280"></polyline> <polyline points=" 16,2 13,5 16,8 " stroke="#6b7280"></polyline>
<polyline points=" 8,16 11,19 8,22 " stroke="#6b7280"></polyline> <polyline points=" 8,16 11,19 8,22 " stroke="#6b7280"></polyline>
</g> </g>
</svg><span>Your Offers</span> <span class="inline-flex justify-center items-center text-xs font-semibold ml-3 mr-2 px-2.5 py-1 font-small text-white bg-blue-500 rounded-full">{{ summary.num_sent_offers }}</span></a> </svg><span>Your Offers</span> <span class="inline-flex justify-center items-center text-xs font-semibold ml-3 mr-2 px-2.5 py-1 font-small text-white bg-blue-500 rounded-full" title="Total {{ summary.num_sent_offers }}">{{ summary.num_sent_active_offers }}</span></a>
</li> </li>
<div class="flex-shrink-0 w-px h-10 bg-gray-200 dark:bg-gray-400 mr-10"></div> <div class="flex-shrink-0 w-px h-10 bg-gray-200 dark:bg-gray-400 mr-10"></div>
<li> <li>
@ -477,7 +477,7 @@
<line data-cap="butt" x1="12" y1="1" x2="12" y2="16" stroke="#6b7280"></line> <line data-cap="butt" x1="12" y1="1" x2="12" y2="16" stroke="#6b7280"></line>
<polyline points="7 11 12 16 17 11" stroke="#6b7280"></polyline> <polyline points="7 11 12 16 17 11" stroke="#6b7280"></polyline>
</g> </g>
</svg><span>Bids Received</span> <span class="inline-flex justify-center items-center text-xs font-semibold ml-3 mr-2 px-2.5 py-1 font-small text-white bg-blue-500 rounded-full">{{ summary.num_recv_bids }}</span></a> </svg><span>Bids Received</span> <span class="inline-flex justify-center items-center text-xs font-semibold ml-3 mr-2 px-2.5 py-1 font-small text-white bg-blue-500 rounded-full" title="Total {{ summary.num_recv_bids }}">{{ summary.num_available_bids }}</span></a>
</li> </li>
<li> <li>
<a class="flex mr-10 items-center text-sm text-gray-400 hover:text-gray-600 dark:text-gray-100 dark:hover:text-gray-100" href="/sentbids"> <a class="flex mr-10 items-center text-sm text-gray-400 hover:text-gray-600 dark:text-gray-100 dark:hover:text-gray-100" href="/sentbids">
@ -487,7 +487,7 @@
<line data-cap="butt" x1="12" y1="17" x2="12" y2="2" stroke="#6b7280"></line> <line data-cap="butt" x1="12" y1="17" x2="12" y2="2" stroke="#6b7280"></line>
<polyline points="17 7 12 2 7 7" stroke="#6b7280"></polyline> <polyline points="17 7 12 2 7 7" stroke="#6b7280"></polyline>
</g> </g>
</svg> <span>Bids Sent</span><span class="inline-flex justify-center items-center text-xs font-semibold ml-3 mr-2 px-2.5 py-1 font-small text-white bg-blue-500 rounded-full">{{ summary.num_sent_bids }}</span></a> </svg> <span>Bids Sent</span><span class="inline-flex justify-center items-center text-xs font-semibold ml-3 mr-2 px-2.5 py-1 font-small text-white bg-blue-500 rounded-full" title="Total {{ summary.num_sent_bids }}">{{ summary.num_sent_active_bids }}</span></a>
</li> </li>
</ul> </ul>
</div> </div>

View file

@ -733,7 +733,7 @@ const chart = new Chart(ctx, {
<tbody> <tbody>
{% for o in offers %} {% for o in offers %}
<tr class="opacity-100 text-gray-500 dark:text-gray-100 hover:bg-coolGray-200 dark:hover:bg-gray-600"> <tr class="opacity-100 text-gray-500 dark:text-gray-100 hover:bg-coolGray-200 dark:hover:bg-gray-600">
<td class="flex items-center py-7 px-46 dark:text-white text-gray-900 whitespace-nowrap"> <td class="flex items-center py-7 px-46 dark:text-white text-gray-900 whitespace-nowrap" title="{% if o[12]==2 %}Revoked{% elif o[11]==true %}Expired{% else %}Active{% endif %}">
<svg alt="" class="w-5 h-5 rounded-full ml-5" xmlns="http://www.w3.org/2000/svg" height="20" width="20" viewBox="0 0 24 24"> <svg alt="" class="w-5 h-5 rounded-full ml-5" 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="{% if o[12]==2 %}#AC0000{% elif o[11]==true %}#6b7280{% else %}#3B82F6{% endif %}" stroke-linejoin="round"> <g stroke-linecap="round" stroke-width="2" fill="none" stroke="{% if o[12]==2 %}#AC0000{% elif o[11]==true %}#6b7280{% else %}#3B82F6{% endif %}" stroke-linejoin="round">
<circle cx="12" cy="12" r="11"></circle> <circle cx="12" cy="12" r="11"></circle>

View file

@ -407,7 +407,7 @@
<div class="px-6"> <div class="px-6">
<div class="flex flex-wrap justify-end"> <div class="flex flex-wrap justify-end">
<div class="w-full md:w-auto p-1.5 ml-2"> <div class="w-full md:w-auto p-1.5 ml-2">
<button name='clearfilters' value="Clear Filters" class="flex flex-wrap justify-center w-full px-4 py-2.5 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"> <button name="clearfilters" value="Clear Filters" class="flex flex-wrap justify-center w-full px-4 py-2.5 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="mr-2 w-5 h-5" xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewBox="0 0 24 24"> <svg class="mr-2 w-5 h-5" 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="#ffffff" stroke-linejoin="round"> <g stroke-linecap="round" stroke-width="2" fill="none" stroke="#ffffff" stroke-linejoin="round">
<line x1="20" y1="2" x2="12.329" y2="11.506"></line> <line x1="20" y1="2" x2="12.329" y2="11.506"></line>
@ -422,7 +422,7 @@
</svg>Clear</button> </svg>Clear</button>
</div> </div>
<div class="w-full md:w-auto p-1.5 ml-2"> <div class="w-full md:w-auto p-1.5 ml-2">
<button name="" value="Submit" type="submit" class="flex flex-wrap justify-center w-full px-4 py-2.5 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"> <button name="applyfilters" value="Submit" type="submit" class="flex flex-wrap justify-center w-full px-4 py-2.5 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="mr-2 w-5 h-5" xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewBox="0 0 24 24"> <svg class="mr-2 w-5 h-5" 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="#ffffff" stroke-linejoin="round"> <g stroke-linecap="round" stroke-width="2" fill="none" stroke="#ffffff" stroke-linejoin="round">
<rect x="2" y="2" width="7" height="7"></rect> <rect x="2" y="2" width="7" height="7"></rect>

View file

@ -37,7 +37,10 @@ def page_automation_strategies(self, url_split, post_string):
messages = [] messages = []
form_data = self.checkForm(post_string, 'automationstrategies', messages) form_data = self.checkForm(post_string, 'automationstrategies', messages)
if form_data and not have_data_entry(form_data, 'clearfilters'): if form_data:
if have_data_entry(form_data, 'clearfilters'):
swap_client.clearFilters('page_automation_strategies')
else:
if have_data_entry(form_data, 'sort_by'): if have_data_entry(form_data, 'sort_by'):
sort_by = get_data_entry(form_data, 'sort_by') sort_by = get_data_entry(form_data, 'sort_by')
ensure(sort_by in ['created_at', 'rate'], 'Invalid sort by') ensure(sort_by in ['created_at', 'rate'], 'Invalid sort by')
@ -48,6 +51,12 @@ def page_automation_strategies(self, url_split, post_string):
filters['sort_dir'] = sort_dir filters['sort_dir'] = sort_dir
set_pagination_filters(form_data, filters) set_pagination_filters(form_data, filters)
if have_data_entry(form_data, 'applyfilters'):
swap_client.setFilters('page_automation_strategies', filters)
else:
saved_filters = swap_client.getFilters('page_automation_strategies')
if saved_filters:
filters.update(saved_filters)
formatted_strategies = [] formatted_strategies = []
for s in swap_client.listAutomationStrategies(filters): for s in swap_client.listAutomationStrategies(filters):

View file

@ -137,9 +137,13 @@ def page_bids(self, url_split, post_string, sent=False, available=False, receive
filters['bid_state_ind'] = BidStates.BID_RECEIVED filters['bid_state_ind'] = BidStates.BID_RECEIVED
filters['with_expired'] = False filters['with_expired'] = False
filter_prefix = 'page_bids_sent' if sent else 'page_bids_available' if available else 'page_bids_received'
messages = [] messages = []
form_data = self.checkForm(post_string, 'bids', messages) form_data = self.checkForm(post_string, 'bids', messages)
if form_data and not have_data_entry(form_data, 'clearfilters'): if form_data:
if have_data_entry(form_data, 'clearfilters'):
swap_client.clearFilters(filter_prefix)
else:
if have_data_entry(form_data, 'sort_by'): if have_data_entry(form_data, 'sort_by'):
sort_by = get_data_entry(form_data, 'sort_by') sort_by = get_data_entry(form_data, 'sort_by')
ensure(sort_by in ['created_at', ], 'Invalid sort by') ensure(sort_by in ['created_at', ], 'Invalid sort by')
@ -161,6 +165,12 @@ def page_bids(self, url_split, post_string, sent=False, available=False, receive
filters['with_expired'] = with_expired filters['with_expired'] = with_expired
set_pagination_filters(form_data, filters) set_pagination_filters(form_data, filters)
if have_data_entry(form_data, 'applyfilters'):
swap_client.setFilters(filter_prefix, filters)
else:
saved_filters = swap_client.getFilters(filter_prefix)
if saved_filters:
filters.update(saved_filters)
bids = swap_client.listBids(sent=sent, filters=filters) bids = swap_client.listBids(sent=sent, filters=filters)

View file

@ -653,9 +653,14 @@ def page_offers(self, url_split, post_string, sent=False):
'sent_from': 'any' if sent is False else 'only', 'sent_from': 'any' if sent is False else 'only',
'active': 'any', 'active': 'any',
} }
filter_prefix = 'page_offers_sent' if sent else 'page_offers'
messages = [] messages = []
form_data = self.checkForm(post_string, 'offers', messages) form_data = self.checkForm(post_string, 'offers', messages)
if form_data and not have_data_entry(form_data, 'clearfilters'): if form_data:
if have_data_entry(form_data, 'clearfilters'):
swap_client.clearFilters(filter_prefix)
else:
filters['coin_from'] = setCoinFilter(form_data, 'coin_from') filters['coin_from'] = setCoinFilter(form_data, 'coin_from')
filters['coin_to'] = setCoinFilter(form_data, 'coin_to') filters['coin_to'] = setCoinFilter(form_data, 'coin_to')
@ -677,6 +682,12 @@ def page_offers(self, url_split, post_string, sent=False):
filters['active'] = active_filter filters['active'] = active_filter
set_pagination_filters(form_data, filters) set_pagination_filters(form_data, filters)
if have_data_entry(form_data, 'applyfilters'):
swap_client.setFilters(filter_prefix, filters)
else:
saved_filters = swap_client.getFilters(filter_prefix)
if saved_filters:
filters.update(saved_filters)
if filters['sent_from'] == 'only': if filters['sent_from'] == 'only':
sent = True sent = True

View file

@ -89,7 +89,9 @@ def page_smsgaddresses(self, url_split, post_string):
new_addr = swap_client.addSMSGAddress(pubkey_hex, addressnote=addressnote) new_addr = swap_client.addSMSGAddress(pubkey_hex, addressnote=addressnote)
messages.append(f'Added address {new_addr}') messages.append(f'Added address {new_addr}')
if not have_data_entry(form_data, 'clearfilters'): if have_data_entry(form_data, 'clearfilters'):
swap_client.clearFilters('page_smsgaddresses')
else:
if have_data_entry(form_data, 'sort_by'): if have_data_entry(form_data, 'sort_by'):
sort_by = get_data_entry(form_data, 'sort_by') sort_by = get_data_entry(form_data, 'sort_by')
ensure(sort_by in ['created_at', 'rate'], 'Invalid sort by') ensure(sort_by in ['created_at', 'rate'], 'Invalid sort by')
@ -106,6 +108,12 @@ def page_smsgaddresses(self, url_split, post_string):
filters['addr_type'] = int(get_data_entry(form_data, 'filter_addr_type')) filters['addr_type'] = int(get_data_entry(form_data, 'filter_addr_type'))
set_pagination_filters(form_data, filters) set_pagination_filters(form_data, filters)
if have_data_entry(form_data, 'applyfilters'):
swap_client.setFilters('page_smsgaddresses', filters)
else:
saved_filters = swap_client.getFilters('page_smsgaddresses')
if saved_filters:
filters.update(saved_filters)
if listaddresses is True: if listaddresses is True:
smsgaddresses = swap_client.listAllSMSGAddresses(filters) smsgaddresses = swap_client.listAllSMSGAddresses(filters)

View file

@ -2,6 +2,12 @@
0.0.x 0.0.x
============== ==============
0.0.62
==============
- ui: Persistent filters
- ui: Show only active bid and offer counts
0.0.61 0.0.61
============== ==============