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 @@