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"
__version__ = "0.11.61"
__version__ = "0.11.62"

View file

@ -963,18 +963,16 @@ class BasicSwap(BaseApp):
if session is None:
self.closeSession(use_session)
def getStringKV(self, str_key: str) -> Optional[str]:
self.mxDB.acquire()
def getStringKV(self, str_key: str, session=None) -> Optional[str]:
try:
session = scoped_session(self.session_factory)
v = session.query(DBKVString).filter_by(key=str_key).first()
use_session = self.openSession(session)
v = use_session.query(DBKVString).filter_by(key=str_key).first()
if not v:
return None
return v.value
finally:
session.close()
session.remove()
self.mxDB.release()
if session is None:
self.closeSession(use_session, commit=False)
def clearStringKV(self, str_key: str, str_val: str) -> None:
with self.mxDB:
@ -5793,31 +5791,37 @@ class BasicSwap(BaseApp):
now: int = self.getTime()
q_str = '''SELECT
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 AND b.state = {} AND b.expire_at > {} AND o.expire_at > {} THEN 1 ELSE NULL END) AS count_available
FROM bids b
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()
bids_sent = q[0]
bids_received = q[1]
bids_available = q[2]
bids_sent_active = q[1]
bids_received = q[2]
bids_available = q[3]
q_str = '''SELECT
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
FROM offers WHERE active_ind = 1'''.format(now)
COUNT(CASE WHEN was_sent THEN 1 ELSE NULL END) AS count_sent,
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()
num_offers = q[0]
num_sent_offers = q[1]
num_sent_active_offers = q[2]
rv = {
'network': self.chain,
'num_swapping': len(self.swaps_in_progress),
'num_network_offers': num_offers,
'num_sent_offers': num_sent_offers,
'num_sent_active_offers': num_sent_active_offers,
'num_recv_bids': bids_received,
'num_sent_bids': bids_sent,
'num_sent_active_bids': bids_sent_active,
'num_available_bids': bids_available,
'num_watched_outputs': num_watched_outputs,
}
@ -6591,3 +6595,30 @@ class BasicSwap(BaseApp):
return rv_array
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=" 8,16 11,19 8,22 " stroke="#6b7280"></polyline>
</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>
<div class="flex-shrink-0 w-px h-10 bg-gray-200 dark:bg-gray-400 mr-10"></div>
<li>
@ -477,7 +477,7 @@
<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>
</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>
<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>
<polyline points="17 7 12 2 7 7" stroke="#6b7280"></polyline>
</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>
</ul>
</div>

View file

@ -85,7 +85,7 @@
<style>
.active-container {
position: relative;
border-radius: 5px;
border-radius: 5px;
}
.active-container::before {
@ -390,7 +390,7 @@ const coinOptions = {
lineColor: 'rgba(77, 132, 240, 1)',
backgroundColor: 'rgba(77, 132, 240, 0.1)'
}
};
};
function updateChart(coinSymbol) {
coin = coinSymbol;
const api_key = '{{chart_api_key}}';
@ -721,7 +721,7 @@ const chart = new Chart(ctx, {
<div class="py-3 px-6 bg-coolGray-200 dark:bg-gray-600">
<span class="text-xs text-gray-600 dark:text-gray-300 font-semibold">Rate</span>
</div>
</th>
</th>
<!--<th>Amount From Swapped</th>-->
<th class="p-0">
<div class="py-3 px-6 bg-coolGray-200 dark:bg-gray-600 rounded-tr-xl">
@ -733,7 +733,7 @@ const chart = new Chart(ctx, {
<tbody>
{% for o in offers %}
<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">
<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>
@ -771,7 +771,7 @@ const chart = new Chart(ctx, {
<td class="py-3 px-6 text-xs">
<div class="coinname-value" data-coinname="{{ o[2] }}">{{ o[4]|truncate(8,true,'',0) }}</div>
<div class="usd-value"></div>
</td>
</td>
{% endif %}
<td class="py-4 px-6 text-xs">
<span class="inline-flex align-middle items-center justify-center w-9 h-10 rounded"> {% if o[9]==true %} <img class="h-7" src="/static/images/coins/{{ o[2]|replace(" ", "-") }}.png" alt="">
@ -788,7 +788,7 @@ const chart = new Chart(ctx, {
<td class="py-3 px-6 text-xs">
<div class="coinname-value" data-coinname="{{ o[3] }}">{{ o[5]|truncate(8,true,'',0) }}</div>
<div class="usd-value"></div>
</td>
</td>
{% endif %}
<td class="py-3 px-6 text-xs">
<div class="coinname-value" data-coinname="{{ o[3] }}">{{ o[6]|truncate(8,true,'',0) }}</div>
@ -911,7 +911,7 @@ const coinNameToSymbol = {
});
document.getElementById('ltc-container').addEventListener('click', () => {
updateChart('LTC');
});
});
</script>
</body>
</html>

View file

@ -407,7 +407,7 @@
<div class="px-6">
<div class="flex flex-wrap justify-end">
<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">
<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>
@ -422,7 +422,7 @@
</svg>Clear</button>
</div>
<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">
<g stroke-linecap="round" stroke-width="2" fill="none" stroke="#ffffff" stroke-linejoin="round">
<rect x="2" y="2" width="7" height="7"></rect>
@ -591,4 +591,4 @@
{% include 'footer.html' %}
</div>
</body>
</html>
</html>

View file

@ -37,17 +37,26 @@ def page_automation_strategies(self, url_split, post_string):
messages = []
form_data = self.checkForm(post_string, 'automationstrategies', messages)
if form_data and not have_data_entry(form_data, 'clearfilters'):
if have_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')
filters['sort_by'] = sort_by
if have_data_entry(form_data, 'sort_dir'):
sort_dir = get_data_entry(form_data, 'sort_dir')
ensure(sort_dir in ['asc', 'desc'], 'Invalid sort dir')
filters['sort_dir'] = sort_dir
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'):
sort_by = get_data_entry(form_data, 'sort_by')
ensure(sort_by in ['created_at', 'rate'], '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')
ensure(sort_dir in ['asc', 'desc'], 'Invalid 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 = []
for s in swap_client.listAutomationStrategies(filters):

View file

@ -137,30 +137,40 @@ def page_bids(self, url_split, post_string, sent=False, available=False, receive
filters['bid_state_ind'] = BidStates.BID_RECEIVED
filters['with_expired'] = False
filter_prefix = 'page_bids_sent' if sent else 'page_bids_available' if available else 'page_bids_received'
messages = []
form_data = self.checkForm(post_string, 'bids', messages)
if form_data and not have_data_entry(form_data, 'clearfilters'):
if have_data_entry(form_data, 'sort_by'):
sort_by = get_data_entry(form_data, 'sort_by')
ensure(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')
ensure(sort_dir in ['asc', 'desc'], 'Invalid sort dir')
filters['sort_dir'] = sort_dir
if have_data_entry(form_data, 'state'):
state_ind = int(get_data_entry(form_data, 'state'))
if state_ind != -1:
try:
state = BidStates(state_ind)
except Exception:
raise ValueError('Invalid state')
filters['bid_state_ind'] = state_ind
if have_data_entry(form_data, 'with_expired'):
with_expired = toBool(get_data_entry(form_data, 'with_expired'))
filters['with_expired'] = with_expired
if form_data:
if have_data_entry(form_data, 'clearfilters'):
swap_client.clearFilters(filter_prefix)
else:
if have_data_entry(form_data, 'sort_by'):
sort_by = get_data_entry(form_data, 'sort_by')
ensure(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')
ensure(sort_dir in ['asc', 'desc'], 'Invalid sort dir')
filters['sort_dir'] = sort_dir
if have_data_entry(form_data, 'state'):
state_ind = int(get_data_entry(form_data, 'state'))
if state_ind != -1:
try:
state = BidStates(state_ind)
except Exception:
raise ValueError('Invalid state')
filters['bid_state_ind'] = state_ind
if have_data_entry(form_data, 'with_expired'):
with_expired = toBool(get_data_entry(form_data, '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)

View file

@ -653,30 +653,41 @@ def page_offers(self, url_split, post_string, sent=False):
'sent_from': 'any' if sent is False else 'only',
'active': 'any',
}
filter_prefix = 'page_offers_sent' if sent else 'page_offers'
messages = []
form_data = self.checkForm(post_string, 'offers', messages)
if form_data and not have_data_entry(form_data, 'clearfilters'):
filters['coin_from'] = setCoinFilter(form_data, 'coin_from')
filters['coin_to'] = setCoinFilter(form_data, 'coin_to')
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_to'] = setCoinFilter(form_data, 'coin_to')
if have_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')
filters['sort_by'] = sort_by
if have_data_entry(form_data, 'sort_dir'):
sort_dir = get_data_entry(form_data, 'sort_dir')
ensure(sort_dir in ['asc', 'desc'], 'Invalid sort dir')
filters['sort_dir'] = sort_dir
if have_data_entry(form_data, 'sent_from'):
sent_from = get_data_entry(form_data, 'sent_from')
ensure(sent_from in ['any', 'only'], 'Invalid sent filter')
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', 'archived'], 'Invalid active filter')
filters['active'] = active_filter
if have_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')
filters['sort_by'] = sort_by
if have_data_entry(form_data, 'sort_dir'):
sort_dir = get_data_entry(form_data, 'sort_dir')
ensure(sort_dir in ['asc', 'desc'], 'Invalid sort dir')
filters['sort_dir'] = sort_dir
if have_data_entry(form_data, 'sent_from'):
sent_from = get_data_entry(form_data, 'sent_from')
ensure(sent_from in ['any', 'only'], 'Invalid sent filter')
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', 'archived'], 'Invalid 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':
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)
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'):
sort_by = get_data_entry(form_data, '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'))
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:
smsgaddresses = swap_client.listAllSMSGAddresses(filters)

View file

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