diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index 97b0dc8..efb1200 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -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) diff --git a/basicswap/http_server.py b/basicswap/http_server.py index 6b7603c..d101da9 100644 --- a/basicswap/http_server.py +++ b/basicswap/http_server.py @@ -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 diff --git a/basicswap/templates/bid.html b/basicswap/templates/bid.html index ea2cd5e..c3f0c98 100644 --- a/basicswap/templates/bid.html +++ b/basicswap/templates/bid.html @@ -21,7 +21,7 @@ ITX State{{ data.itx_state }} PTX State{{ data.ptx_state }} Offer{{ data.offer_id }} -Address From{{ data.addr_from }} +Address From{{ data.addr_from }} {{ data.addr_from_label }} Proof of Funds{{ data.proof_address }} Created At{{ data.created_at }} Expired At{{ data.expired_at }} diff --git a/basicswap/templates/bid_xmr.html b/basicswap/templates/bid_xmr.html index 9e9a230..169ac6a 100644 --- a/basicswap/templates/bid_xmr.html +++ b/basicswap/templates/bid_xmr.html @@ -21,7 +21,7 @@ Bid State{{ data.bid_state }} State Description {{ data.state_description }} Offer{{ data.offer_id }} -Address From{{ data.addr_from }} +Address From{{ data.addr_from }} {{ data.addr_from_label }} Created At{{ data.created_at }} Expired At{{ data.expired_at }} Sent{{ data.was_sent }} diff --git a/basicswap/templates/identity.html b/basicswap/templates/identity.html index c0390a9..a5ee3a0 100644 --- a/basicswap/templates/identity.html +++ b/basicswap/templates/identity.html @@ -9,6 +9,13 @@
+ +{% if data.show_edit_form %} + +{% else %} + +{% endif %} + @@ -16,6 +23,14 @@
Label
Label{{ data.label }}
Successful Sent Bids{{ data.num_sent_bids_successful }}
Successful Received Bids{{ data.num_recv_bids_successful }}
Rejected Sent Bids{{ data.num_sent_bids_rejected }}
Failed Sent Bids{{ data.num_sent_bids_failed }}
Failed Received Bids{{ data.num_recv_bids_failed }}
+ +{% if data.show_edit_form %} + + +{% else %} + +{% endif %} +
diff --git a/basicswap/templates/offer.html b/basicswap/templates/offer.html index bd51bee..f85fa1d 100644 --- a/basicswap/templates/offer.html +++ b/basicswap/templates/offer.html @@ -24,8 +24,12 @@ Rate Variable{{ data.rate_negotiable }} Script Lock Type{{ data.lock_type }} Script Lock Value{{ data.lock_value }} +{% if data.addr_to == "Public" %} Address To{{ data.addr_to }} -Address From{{ data.addr_from }} +{% else %} +Address To{{ data.addr_to }} {{ data.addr_to_label }} +{% endif %} +Address From{{ data.addr_from }} {{ data.addr_from_label }} Created At{{ data.created_at | formatts }} Expired At{{ data.expired_at | formatts }} Sent{{ data.sent }} @@ -55,7 +59,7 @@ Send From Address diff --git a/basicswap/templates/offer_confirm.html b/basicswap/templates/offer_confirm.html index 26db9bf..4612d71 100644 --- a/basicswap/templates/offer_confirm.html +++ b/basicswap/templates/offer_confirm.html @@ -11,12 +11,12 @@ Send To Send From Address diff --git a/basicswap/templates/offer_new_1.html b/basicswap/templates/offer_new_1.html index 2f3e131..40e8377 100644 --- a/basicswap/templates/offer_new_1.html +++ b/basicswap/templates/offer_new_1.html @@ -11,12 +11,12 @@ Send To Send From Address diff --git a/basicswap/templates/offer_new_2.html b/basicswap/templates/offer_new_2.html index 9da3e13..54a7d21 100644 --- a/basicswap/templates/offer_new_2.html +++ b/basicswap/templates/offer_new_2.html @@ -11,12 +11,12 @@ Send To Send From Address diff --git a/basicswap/ui.py b/basicswap/ui.py index 0bfcd74..5df0ab4 100644 --- a/basicswap/ui.py +++ b/basicswap/ui.py @@ -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),