mirror of
https://github.com/basicswap/basicswap.git
synced 2024-11-16 15:58:17 +00:00
ui: Show offer amount swapped.
This commit is contained in:
parent
3ed6eca95f
commit
cddc4daf70
5 changed files with 29 additions and 14 deletions
|
@ -245,6 +245,7 @@ class BasicSwap(BaseApp):
|
|||
self.network_pubkey = self.settings['network_pubkey']
|
||||
self.network_addr = pubkeyToAddress(chainparams[Coins.PART][self.chain]['pubkey_address'], bytes.fromhex(self.network_pubkey))
|
||||
|
||||
self.db_echo = self.settings.get('db_echo', False)
|
||||
self.sqlite_file = os.path.join(self.data_dir, 'db{}.sqlite'.format('' if self.chain == 'mainnet' else ('_' + self.chain)))
|
||||
db_exists = os.path.exists(self.sqlite_file)
|
||||
|
||||
|
@ -257,7 +258,8 @@ class BasicSwap(BaseApp):
|
|||
close_all_sessions()
|
||||
Base.metadata.create_all(self.engine)
|
||||
self.engine.dispose()
|
||||
self.engine = sa.create_engine('sqlite:///' + self.sqlite_file)
|
||||
|
||||
self.engine = sa.create_engine('sqlite:///' + self.sqlite_file, echo=self.db_echo)
|
||||
self.session_factory = sessionmaker(bind=self.engine, expire_on_commit=False)
|
||||
|
||||
session = scoped_session(self.session_factory)
|
||||
|
@ -5392,10 +5394,13 @@ class BasicSwap(BaseApp):
|
|||
now = int(time.time())
|
||||
session = scoped_session(self.session_factory)
|
||||
|
||||
subquery = session.query(sa.func.sum(Bid.amount).label('completed_bid_amount')).filter(sa.and_(Bid.offer_id == Offer.offer_id, Bid.state == BidStates.SWAP_COMPLETED)).correlate(Offer).scalar_subquery()
|
||||
q = session.query(Offer, subquery)
|
||||
|
||||
if sent:
|
||||
q = session.query(Offer).filter(Offer.was_sent == True) # noqa: E712
|
||||
q = q.filter(Offer.was_sent == True) # noqa: E712
|
||||
else:
|
||||
q = session.query(Offer).filter(sa.and_(Offer.expire_at > now, Offer.active_ind == 1))
|
||||
q = q.filter(sa.and_(Offer.expire_at > now, Offer.active_ind == 1))
|
||||
|
||||
filter_offer_id = filters.get('offer_id', None)
|
||||
if filter_offer_id is not None:
|
||||
|
@ -5424,11 +5429,11 @@ class BasicSwap(BaseApp):
|
|||
for row in q:
|
||||
# Show offers for enabled coins only
|
||||
try:
|
||||
ci_from = self.ci(row.coin_from)
|
||||
ci_to = self.ci(row.coin_to)
|
||||
ci_from = self.ci(row[0].coin_from)
|
||||
ci_to = self.ci(row[0].coin_to)
|
||||
except Exception as e:
|
||||
continue
|
||||
rv.append(row)
|
||||
rv.append((row[0], 0 if row[1] is None else row[1]))
|
||||
return rv
|
||||
finally:
|
||||
session.close()
|
||||
|
|
|
@ -129,7 +129,8 @@ def js_offers(self, url_split, post_string, is_json, sent=False):
|
|||
|
||||
offers = self.server.swap_client.listOffers(sent, filters)
|
||||
rv = []
|
||||
for o in offers:
|
||||
for row in offers:
|
||||
o, _ = row
|
||||
ci_from = self.server.swap_client.ci(o.coin_from)
|
||||
ci_to = self.server.swap_client.ci(o.coin_to)
|
||||
rv.append({
|
||||
|
|
|
@ -20,8 +20,9 @@
|
|||
<tr><td>Amount From</td><td>{{ data.amt_from }} {{ data.tla_from }}</td></tr>
|
||||
<tr><td>Amount To</td><td>{{ data.amt_to }} {{ data.tla_to }}</td></tr>
|
||||
<tr><td>Rate</td><td>{{ data.rate }}</td></tr>
|
||||
<tr><td>Amount Variable</td><td>{{ data.amount_negotiable }}</td></tr>
|
||||
<tr><td>Rate Variable</td><td>{{ data.rate_negotiable }}</td></tr>
|
||||
<tr><td title="Total coin-from value of completed bids, that this node is involved in">Amount Swapped</td><td>{{ data.amt_swapped }} {{ data.tla_from }}</td></tr>
|
||||
<tr><td title="If bids can be sent with a different amount">Amount Variable</td><td>{{ data.amount_negotiable }}</td></tr>
|
||||
<tr><td title="If bids can be sent with a different amount">Rate Variable</td><td>{{ data.rate_negotiable }}</td></tr>
|
||||
<tr><td>Script Lock Type</td><td>{{ data.lock_type }}</td></tr>
|
||||
<tr><td>Script Lock Value</td><td>{{ data.lock_value }} {{ data.lock_value_hr }}</td></tr>
|
||||
{% if data.addr_to == "Public" %}
|
||||
|
|
|
@ -51,9 +51,9 @@
|
|||
|
||||
|
||||
<table>
|
||||
<tr><th>At</th><th>From</th><th>Recipient</th><th>Offer ID</th><th>Coin From</th><th>Coin To</th><th>Amount From</th><th>Amount To</th><th>Rate</th></tr>
|
||||
<tr><th>At</th><th>From</th><th>Recipient</th><th>Offer ID</th><th>Coin From</th><th>Coin To</th><th>Amount From</th><th>Amount To</th><th>Rate</th><th>Amount From Swapped</th></tr>
|
||||
{% for o in offers %}
|
||||
<tr><td>{{ o[0] }}</td><td class="monospace">{{ o[8]|truncate(12, True) }}{% if o[9]==true %} <b>Sent</b>{% endif %}</td><td class="monospace">{{ o[7] }}</td><td><a class="monospace" href=/offer/{{ o[1] }}>{{ o[1] }}</a></td><td>{{ o[2] }}</td><td>{{ o[3] }}</td><td>{{ o[4] }}</td><td>{{ o[5] }}</td><td>{{ o[6] }}</td></tr>
|
||||
<tr><td>{{ o[0] }}</td><td class="monospace">{{ o[8]|truncate(12, True) }}{% if o[9]==true %} <b>Sent</b>{% endif %}</td><td class="monospace">{{ o[7] }}</td><td><a class="monospace" href=/offer/{{ o[1] }}>{{ o[1] }}</a></td><td>{{ o[2] }}</td><td>{{ o[3] }}</td><td>{{ o[4] }}</td><td>{{ o[5] }}</td><td>{{ o[6] }}</td><td>{{ o[10] }}</td></tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
|
|
|
@ -461,6 +461,12 @@ def page_offer(self, url_split, post_string):
|
|||
pass # None found
|
||||
|
||||
bids = swap_client.listBids(offer_id=offer_id)
|
||||
formatted_bids = []
|
||||
amt_swapped = 0
|
||||
for b in bids:
|
||||
amt_swapped += b[4]
|
||||
formatted_bids.append((b[2].hex(), ci_from.format_amount(b[4]), strBidState(b[5]), ci_to.format_amount(b[10]), b[11]))
|
||||
data['amt_swapped'] = ci_from.format_amount(amt_swapped)
|
||||
|
||||
template = server.env.get_template('offer.html')
|
||||
return bytes(template.render(
|
||||
|
@ -470,7 +476,7 @@ def page_offer(self, url_split, post_string):
|
|||
sent_bid_id=sent_bid_id,
|
||||
messages=messages,
|
||||
data=data,
|
||||
bids=[(b[2].hex(), ci_from.format_amount(b[4]), strBidState(b[5]), ci_to.format_amount(b[10]), b[11]) for b in bids],
|
||||
bids=formatted_bids,
|
||||
addrs=None if show_bid_form is None else swap_client.listSmsgAddresses('bid'),
|
||||
form_id=os.urandom(8).hex(),
|
||||
), 'UTF-8')
|
||||
|
@ -517,7 +523,8 @@ def page_offers(self, url_split, post_string, sent=False):
|
|||
offers = swap_client.listOffers(sent, filters)
|
||||
|
||||
formatted_offers = []
|
||||
for o in offers:
|
||||
for row in offers:
|
||||
o, completed_amount = row
|
||||
ci_from = swap_client.ci(Coins(o.coin_from))
|
||||
ci_to = swap_client.ci(Coins(o.coin_to))
|
||||
formatted_offers.append((
|
||||
|
@ -529,7 +536,8 @@ def page_offers(self, url_split, post_string, sent=False):
|
|||
ci_to.format_amount(o.rate),
|
||||
'Public' if o.addr_to == swap_client.network_addr else o.addr_to,
|
||||
o.addr_from,
|
||||
o.was_sent))
|
||||
o.was_sent,
|
||||
ci_from.format_amount(completed_amount)))
|
||||
|
||||
template = server.env.get_template('offers.html')
|
||||
return bytes(template.render(
|
||||
|
|
Loading…
Reference in a new issue