ui: Identity labels

This commit is contained in:
tecnovert 2021-12-06 01:06:34 +02:00
parent 1e01851152
commit 4b7b16145f
No known key found for this signature in database
GPG key ID: 8ED6D8750C4E3F93
10 changed files with 85 additions and 12 deletions

View file

@ -1849,6 +1849,21 @@ class BasicSwap(BaseApp):
session.remove()
self.mxDB.release()
def updateIdentity(self, address, label):
self.mxDB.acquire()
try:
session = scoped_session(self.session_factory)
identity = session.query(KnownIdentity).filter_by(address=address).first()
if identity is None:
identity = KnownIdentity(address=address)
identity.label = label
session.add(identity)
session.commit()
finally:
session.close()
session.remove()
self.mxDB.release()
def list_bid_events(self, bid_id, session):
query_str = 'SELECT created_at, event_type, event_msg FROM eventlog ' + \
'WHERE active_ind = 1 AND linked_type = {} AND linked_id = x\'{}\' '.format(TableTypes.BID, bid_id.hex())
@ -5482,9 +5497,9 @@ class BasicSwap(BaseApp):
try:
session = scoped_session(self.session_factory)
rv = []
q = session.execute('SELECT addr FROM smsgaddresses WHERE use_type = {} AND active_ind = 1 ORDER BY addr_id DESC'.format(use_type))
q = session.execute('SELECT sa.addr, ki.label FROM smsgaddresses AS sa LEFT JOIN knownidentities AS ki ON sa.addr = ki.address WHERE sa.use_type = {} AND sa.active_ind = 1 ORDER BY sa.addr_id DESC'.format(use_type))
for row in q:
rv.append(row[0])
rv.append((row[0], row[1]))
return rv
finally:
session.close()
@ -5553,6 +5568,20 @@ class BasicSwap(BaseApp):
return
self.swaps_in_progress[bid.bid_id] = (bid, swap_in_progress[1])
def getAddressLabel(self, addresses):
self.mxDB.acquire()
try:
session = scoped_session(self.session_factory)
rv = []
for a in addresses:
v = session.query(KnownIdentity).filter_by(address=a).first()
rv.append('' if not v else v.label)
return rv
finally:
session.close()
session.remove()
self.mxDB.release()
def add_connection(self, host, port, peer_pubkey):
self.log.info('add_connection %s %d %s', host, port, peer_pubkey.hex())
self._network.add_connection(host, port, peer_pubkey)

View file

@ -840,6 +840,12 @@ class HttpHandler(BaseHTTPRequestHandler):
}
data.update(extend_data)
addr_from_label, addr_to_label = swap_client.getAddressLabel([offer.addr_from, offer.addr_to])
if len(addr_from_label) > 0:
data['addr_from_label'] = '(' + addr_from_label + ')'
if len(addr_to_label) > 0:
data['addr_to_label'] = '(' + addr_to_label + ')'
if swap_client.debug_ui:
data['debug_ind'] = debugind
data['debug_options'] = [(int(t), t.name) for t in DebugTypes]
@ -1011,6 +1017,9 @@ class HttpHandler(BaseHTTPRequestHandler):
if len(old_states) > 0:
old_states.sort(key=lambda x: x[0])
if len(data['addr_from_label']) > 0:
data['addr_from_label'] = '(' + data['addr_from_label'] + ')'
template = env.get_template('bid_xmr.html') if offer.swap_type == SwapTypes.XMR_SWAP else env.get_template('bid.html')
return bytes(template.render(
title=self.server.title,
@ -1162,11 +1171,24 @@ class HttpHandler(BaseHTTPRequestHandler):
page_data = {'identity_address': identity_address}
messages = []
form_data = self.checkForm(post_string, 'identity', messages)
if form_data:
if have_data_entry(form_data, 'edit'):
page_data['show_edit_form'] = True
if have_data_entry(form_data, 'apply'):
new_label = get_data_entry(form_data, 'label')
try:
swap_client.updateIdentity(identity_address, new_label)
messages.append('Updated')
except Exception as e:
messages.append('Error')\
try:
identity = swap_client.getIdentity(identity_address)
if identity is None:
raise ValueError('Unknown address')
page_data['label'] = identity.label
page_data['num_sent_bids_successful'] = identity.num_sent_bids_successful
page_data['num_recv_bids_successful'] = identity.num_recv_bids_successful
page_data['num_sent_bids_rejected'] = identity.num_sent_bids_rejected

View file

@ -21,7 +21,7 @@
<tr><td>ITX State</td><td>{{ data.itx_state }}</td></tr>
<tr><td>PTX State</td><td>{{ data.ptx_state }}</td></tr>
<tr><td>Offer</td><td><a class="monospace" href="/offer/{{ data.offer_id }}">{{ data.offer_id }}</a></td></tr>
<tr><td>Address From</td><td><a class="monospace" href="/identity/{{ data.addr_from }}">{{ data.addr_from }}</a></td></tr>
<tr><td>Address From</td><td><a class="monospace" href="/identity/{{ data.addr_from }}">{{ data.addr_from }}</a> {{ data.addr_from_label }}</td></tr>
<tr><td>Proof of Funds</td><td>{{ data.proof_address }}</td></tr>
<tr><td>Created At</td><td>{{ data.created_at }}</td></tr>
<tr><td>Expired At</td><td>{{ data.expired_at }}</td></tr>

View file

@ -21,7 +21,7 @@
<tr><td>Bid State</td><td>{{ data.bid_state }}</td></tr>
<tr><td>State Description </td><td>{{ data.state_description }}</td></tr>
<tr><td>Offer</td><td><a class="monospace" href="/offer/{{ data.offer_id }}">{{ data.offer_id }}</a></td></tr>
<tr><td>Address From</td><td><a class="monospace" href="/identity/{{ data.addr_from }}">{{ data.addr_from }}</a></td></tr>
<tr><td>Address From</td><td><a class="monospace" href="/identity/{{ data.addr_from }}">{{ data.addr_from }}</a> {{ data.addr_from_label }}</td></tr>
<tr><td>Created At</td><td>{{ data.created_at }}</td></tr>
<tr><td>Expired At</td><td>{{ data.expired_at }}</td></tr>
<tr><td>Sent</td><td>{{ data.was_sent }}</td></tr>

View file

@ -9,6 +9,13 @@
<form method="post">
<table>
{% if data.show_edit_form %}
<tr><td>Label</td><td><input type="text" id="label" name="label" value="{{ data.label }}"></td></tr>
{% else %}
<tr><td>Label</td><td>{{ data.label }}</td></tr>
{% endif %}
<tr><td>Successful Sent Bids</td><td>{{ data.num_sent_bids_successful }}</td></tr>
<tr><td>Successful Received Bids</td><td>{{ data.num_recv_bids_successful }}</td></tr>
<tr><td>Rejected Sent Bids</td><td>{{ data.num_sent_bids_rejected }}</td></tr>
@ -16,6 +23,14 @@
<tr><td>Failed Sent Bids</td><td>{{ data.num_sent_bids_failed }}</td></tr>
<tr><td>Failed Received Bids</td><td>{{ data.num_recv_bids_failed }}</td></tr>
</table>
{% if data.show_edit_form %}
<input type="submit" name="apply" value="Apply">
<input type="submit" name="cancel" value="Cancel">
{% else %}
<input type="submit" name="edit" value="Edit">
{% endif %}
<input type="hidden" name="formid" value="{{ form_id }}">
</form>

View file

@ -24,8 +24,12 @@
<tr><td>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 }}</td></tr>
{% if data.addr_to == "Public" %}
<tr><td>Address To</td><td>{{ data.addr_to }}</td></tr>
<tr><td>Address From</td><td><a class="monospace" href="/identity/{{ data.addr_from }}">{{ data.addr_from }}</a></td></tr>
{% else %}
<tr><td>Address To</td><td><a class="monospace" href="/identity/{{ data.addr_to }}">{{ data.addr_to }}</a> {{ data.addr_to_label }}</td></tr>
{% endif %}
<tr><td>Address From</td><td><a class="monospace" href="/identity/{{ data.addr_from }}">{{ data.addr_from }}</a> {{ data.addr_from_label }}</td></tr>
<tr><td>Created At</td><td>{{ data.created_at | formatts }}</td></tr>
<tr><td>Expired At</td><td>{{ data.expired_at | formatts }}</td></tr>
<tr><td>Sent</td><td>{{ data.sent }}</td></tr>
@ -55,7 +59,7 @@
<tr><td>Send From Address</td><td>
<select name="addr_from">
{% for a in addrs %}
<option value="{{ a }}" {% if data.nb_addr_from==a %} selected{% endif %}>{{ a }}</option>
<option value="{{ a[0] }}" {% if data.nb_addr_from==a[0] %} selected{% endif %}>{{ a[0] }} {{ a[1] }}</option>
{% endfor %}
<option value="-1" {% if data.nb_addr_from=="-1" %} selected{% endif %}>-- New Address --</option>
</select>

View file

@ -11,12 +11,12 @@
<tr><td>Send To</td><td><select name="addr_to_" disabled>
<option{% if data.addr_to=="-1" %} selected{% endif %} value="-1">-- Public Network --</option>
{% for a in addrs_to %}
<option{% if data.addr_to==a %} selected{% endif %} value="{{ a }}">{{ a }}</option>
<option{% if data.addr_to==a[0] %} selected{% endif %} value="{{ a[0] }}">{{ a[0] }} {{ a[1] }}</option>
{% endfor %}
</select></td></tr>
<tr><td>Send From Address</td><td><select name="addr_from_" disabled>
{% for a in addrs %}
<option{% if data.addr_from==a %} selected{% endif %} value="{{ a }}">{{ a }}</option>
<option{% if data.addr_from==a[0] %} selected{% endif %} value="{{ a[0] }}">{{ a[0] }} {{ a[1] }}</option>
{% endfor %}
<option{% if data.addr_from=="-1" %} selected{% endif %} value="-1">-- New Address --</option>
</select></td></tr>

View file

@ -11,12 +11,12 @@
<tr><td>Send To</td><td><select name="addr_to">
<option{% if data.addr_to=="-1" %} selected{% endif %} value="-1">-- Public Network --</option>
{% for a in addrs_to %}
<option{% if data.addr_to==a %} selected{% endif %} value="{{ a }}">{{ a }}</option>
<option{% if data.addr_to==a[0] %} selected{% endif %} value="{{ a[0] }}">{{ a[0] }} {{ a[1] }}</option>
{% endfor %}
</select></td></tr>
<tr><td>Send From Address</td><td><select name="addr_from">
{% for a in addrs %}
<option{% if data.addr_from==a %} selected{% endif %} value="{{ a }}">{{ a }}</option>
<option{% if data.addr_from==a[0] %} selected{% endif %} value="{{ a[0] }}">{{ a[0] }} {{ a[1] }}</option>
{% endfor %}
<option{% if data.addr_from=="-1" %} selected{% endif %} value="-1">-- New Address --</option>
</select></td></tr>

View file

@ -11,12 +11,12 @@
<tr><td>Send To</td><td><select name="addr_to_" disabled>
<option{% if data.addr_to=="-1" %} selected{% endif %} value="-1">-- Public Network --</option>
{% for a in addrs_to %}
<option{% if data.addr_to==a %} selected{% endif %} value="{{ a }}">{{ a }}</option>
<option{% if data.addr_to==a[0] %} selected{% endif %} value="{{ a[0] }}">{{ a[0] }} {{ a[1] }}</option>
{% endfor %}
</select></td></tr>
<tr><td>Send From Address</td><td><select name="addr_from_" disabled>
{% for a in addrs %}
<option{% if data.addr_from==a %} selected{% endif %} value="{{ a }}">{{ a }}</option>
<option{% if data.addr_from==a[0] %} selected{% endif %} value="{{ a[0] }}">{{ a[0] }} {{ a[1] }}</option>
{% endfor %}
<option{% if data.addr_from=="-1" %} selected{% endif %} value="-1">-- New Address --</option>
</select></td></tr>

View file

@ -202,6 +202,8 @@ def describeBid(swap_client, bid, xmr_swap, offer, xmr_offer, bid_events, edit_b
elif bid.state == BidStates.XMR_SWAP_NOSCRIPT_TX_REDEEMED:
state_description = f'Waiting for {ticker_to} lock tx spend tx to confirm in chain'
addr_label = swap_client.getAddressLabel([bid.bid_addr, ])[0]
data = {
'coin_from': ci_from.coin_name(),
'coin_to': ci_to.coin_name(),
@ -216,6 +218,7 @@ def describeBid(swap_client, bid, xmr_swap, offer, xmr_offer, bid_events, edit_b
'ptx_state': strTxState(bid.getPTxState()),
'offer_id': bid.offer_id.hex(),
'addr_from': bid.bid_addr,
'addr_from_label': addr_label,
'addr_fund_proof': bid.proof_address,
'created_at': bid.created_at if for_api else format_timestamp(bid.created_at, with_seconds=True),
'expired_at': bid.expire_at if for_api else format_timestamp(bid.expire_at, with_seconds=True),