Browse Source

pass both invoice and description to show_transaction

master
ThomasV 6 years ago
parent
commit
5c1340b7bd
  1. 22
      electrum/gui/qt/main_window.py
  2. 9
      electrum/gui/qt/transaction_dialog.py

22
electrum/gui/qt/main_window.py

@ -920,9 +920,9 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
d = address_dialog.AddressDialog(self, addr) d = address_dialog.AddressDialog(self, addr)
d.exec_() d.exec_()
def show_transaction(self, tx, tx_desc = None): def show_transaction(self, tx, *, invoice=None, tx_desc=None):
'''tx_desc is set only for txs created in the Send tab''' '''tx_desc is set only for txs created in the Send tab'''
show_transaction(tx, self, tx_desc) show_transaction(tx, self, invoice=invoice, desc=tx_desc)
def create_receive_tab(self): def create_receive_tab(self):
# A 4-column grid layout. All the stretch is in the last column. # A 4-column grid layout. All the stretch is in the last column.
@ -1739,7 +1739,6 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
invoice = self.read_invoice() invoice = self.read_invoice()
if not invoice: if not invoice:
return return
if not preview:
self.wallet.save_invoice(invoice) self.wallet.save_invoice(invoice)
self.invoice_list.update() self.invoice_list.update()
self.do_pay_invoice(invoice, preview) self.do_pay_invoice(invoice, preview)
@ -1791,7 +1790,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
return return
if preview: if preview:
self.show_transaction(tx, message) self.show_transaction(tx, invoice=invoice)
return return
if not self.network: if not self.network:
@ -1829,9 +1828,9 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
if success: if success:
self.do_clear() self.do_clear()
if not tx.is_complete(): if not tx.is_complete():
self.show_transaction(tx) self.show_transaction(tx, invoice=invoice)
else: else:
self.broadcast_transaction(tx, message) self.broadcast_transaction(tx, invoice=invoice)
self.sign_tx_with_password(tx, sign_done, password) self.sign_tx_with_password(tx, sign_done, password)
@protected @protected
@ -1856,7 +1855,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
msg = _('Signing transaction...') msg = _('Signing transaction...')
WaitingDialog(self, msg, task, on_success, on_failure) WaitingDialog(self, msg, task, on_success, on_failure)
def broadcast_transaction(self, tx, invoice=None): def broadcast_transaction(self, tx, *, invoice=None, tx_desc=None):
def broadcast_thread(): def broadcast_thread():
# non-GUI thread # non-GUI thread
@ -1871,10 +1870,11 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
except BestEffortRequestFailed as e: except BestEffortRequestFailed as e:
return False, repr(e) return False, repr(e)
# success # success
if invoice:
key = invoice['id']
txid = tx.txid() txid = tx.txid()
self.wallet.set_paid(key, txid) if tx_desc:
self.wallet.set_label(txid, tx_desc)
if invoice:
self.wallet.set_paid(invoice['id'], txid)
self.wallet.set_label(txid, invoice['message']) self.wallet.set_label(txid, invoice['message'])
if pr: if pr:
self.payment_request = None self.payment_request = None
@ -3255,7 +3255,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
return return
if is_final: if is_final:
new_tx.set_rbf(False) new_tx.set_rbf(False)
self.show_transaction(new_tx, tx_label) self.show_transaction(new_tx, tx_desc=tx_label)
def save_transaction_into_wallet(self, tx): def save_transaction_into_wallet(self, tx):
win = self.top_level_window() win = self.top_level_window()

9
electrum/gui/qt/transaction_dialog.py

@ -60,9 +60,9 @@ _logger = get_logger(__name__)
dialogs = [] # Otherwise python randomly garbage collects the dialogs... dialogs = [] # Otherwise python randomly garbage collects the dialogs...
def show_transaction(tx, parent, desc=None, prompt_if_unsaved=False): def show_transaction(tx, parent, *, invoice=None, desc=None, prompt_if_unsaved=False):
try: try:
d = TxDialog(tx, parent, desc, prompt_if_unsaved) d = TxDialog(tx, parent, invoice, desc, prompt_if_unsaved)
except SerializationError as e: except SerializationError as e:
_logger.exception('unable to deserialize the transaction') _logger.exception('unable to deserialize the transaction')
parent.show_critical(_("Electrum was unable to deserialize the transaction:") + "\n" + str(e)) parent.show_critical(_("Electrum was unable to deserialize the transaction:") + "\n" + str(e))
@ -73,7 +73,7 @@ def show_transaction(tx, parent, desc=None, prompt_if_unsaved=False):
class TxDialog(QDialog, MessageBoxMixin): class TxDialog(QDialog, MessageBoxMixin):
def __init__(self, tx: Transaction, parent: 'ElectrumWindow', desc, prompt_if_unsaved): def __init__(self, tx: Transaction, parent: 'ElectrumWindow', invoice, desc, prompt_if_unsaved):
'''Transactions in the wallet will show their description. '''Transactions in the wallet will show their description.
Pass desc to give a description for txs not yet in the wallet. Pass desc to give a description for txs not yet in the wallet.
''' '''
@ -92,6 +92,7 @@ class TxDialog(QDialog, MessageBoxMixin):
self.prompt_if_unsaved = prompt_if_unsaved self.prompt_if_unsaved = prompt_if_unsaved
self.saved = False self.saved = False
self.desc = desc self.desc = desc
self.invoice = invoice
# if the wallet can populate the inputs with more info, do it now. # if the wallet can populate the inputs with more info, do it now.
# as a result, e.g. we might learn an imported address tx is segwit, # as a result, e.g. we might learn an imported address tx is segwit,
@ -161,7 +162,7 @@ class TxDialog(QDialog, MessageBoxMixin):
def do_broadcast(self): def do_broadcast(self):
self.main_window.push_top_level_window(self) self.main_window.push_top_level_window(self)
try: try:
self.main_window.broadcast_transaction(self.tx, self.desc) self.main_window.broadcast_transaction(self.tx, invoice=self.invoice, tx_desc=self.desc)
finally: finally:
self.main_window.pop_top_level_window(self) self.main_window.pop_top_level_window(self)
self.saved = True self.saved = True

Loading…
Cancel
Save