Browse Source

TxDialog: fix hooks. only show psbt widgets when applicable.

users of 'transaction_dialog' were assuming that dialog.tx is already set
master
SomberNight 6 years ago
parent
commit
0c0a6b2145
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 26
      electrum/gui/qt/transaction_dialog.py
  2. 8
      electrum/plugins/coldcard/qt.py
  3. 9
      electrum/plugins/cosigner_pool/qt.py
  4. 6
      electrum/plugins/greenaddress_instant/qt.py

26
electrum/gui/qt/transaction_dialog.py

@ -28,7 +28,7 @@ import copy
import datetime import datetime
import traceback import traceback
import time import time
from typing import TYPE_CHECKING, Callable, Optional from typing import TYPE_CHECKING, Callable, Optional, List
from functools import partial from functools import partial
from decimal import Decimal from decimal import Decimal
@ -110,6 +110,8 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
self.setMinimumWidth(950) self.setMinimumWidth(950)
self.set_title() self.set_title()
self.psbt_only_widgets = [] # type: List[QWidget]
vbox = QVBoxLayout() vbox = QVBoxLayout()
self.setLayout(vbox) self.setLayout(vbox)
@ -155,9 +157,9 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
self.export_actions_menu = export_actions_menu = QMenu() self.export_actions_menu = export_actions_menu = QMenu()
self.add_export_actions_to_menu(export_actions_menu) self.add_export_actions_to_menu(export_actions_menu)
export_actions_menu.addSeparator() export_actions_menu.addSeparator()
#if isinstance(tx, PartialTransaction): export_submenu = export_actions_menu.addMenu(_("For CoinJoin; strip privates"))
export_for_coinjoin_submenu = export_actions_menu.addMenu(_("For CoinJoin; strip privates")) self.add_export_actions_to_menu(export_submenu, gettx=self._gettx_for_coinjoin)
self.add_export_actions_to_menu(export_for_coinjoin_submenu, gettx=self._gettx_for_coinjoin) self.psbt_only_widgets.append(export_submenu)
self.export_actions_button = QToolButton() self.export_actions_button = QToolButton()
self.export_actions_button.setText(_("Export")) self.export_actions_button.setText(_("Export"))
@ -178,12 +180,10 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
self.partial_tx_actions_button.setText(_("Combine")) self.partial_tx_actions_button.setText(_("Combine"))
self.partial_tx_actions_button.setMenu(partial_tx_actions_menu) self.partial_tx_actions_button.setMenu(partial_tx_actions_menu)
self.partial_tx_actions_button.setPopupMode(QToolButton.InstantPopup) self.partial_tx_actions_button.setPopupMode(QToolButton.InstantPopup)
self.psbt_only_widgets.append(self.partial_tx_actions_button)
# Action buttons # Action buttons
self.buttons = [] self.buttons = [self.partial_tx_actions_button, self.sign_button, self.broadcast_button, self.cancel_button]
#if isinstance(tx, PartialTransaction):
self.buttons.append(self.partial_tx_actions_button)
self.buttons += [self.sign_button, self.broadcast_button, self.cancel_button]
# Transaction sharing buttons # Transaction sharing buttons
self.sharing_buttons = [self.finalize_button, self.export_actions_button, self.save_button] self.sharing_buttons = [self.finalize_button, self.export_actions_button, self.save_button]
run_hook('transaction_dialog', self) run_hook('transaction_dialog', self)
@ -389,7 +389,7 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
size = self.tx.estimated_size() size = self.tx.estimated_size()
self.broadcast_button.setEnabled(tx_details.can_broadcast) self.broadcast_button.setEnabled(tx_details.can_broadcast)
can_sign = not self.tx.is_complete() and \ can_sign = not self.tx.is_complete() and \
(self.wallet.can_sign(self.tx) or bool(self.main_window.tx_external_keypairs)) (self.wallet.can_sign(self.tx) or bool(self.external_keypairs))
self.sign_button.setEnabled(can_sign) self.sign_button.setEnabled(can_sign)
self.tx_hash_e.setText(tx_details.txid or _('Unknown')) self.tx_hash_e.setText(tx_details.txid or _('Unknown'))
if desc is None: if desc is None:
@ -441,6 +441,14 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
self.amount_label.setText(amount_str) self.amount_label.setText(amount_str)
self.fee_label.setText(fee_str) self.fee_label.setText(fee_str)
self.size_label.setText(size_str) self.size_label.setText(size_str)
show_psbt_only_widgets = self.finalized and isinstance(self.tx, PartialTransaction)
for widget in self.psbt_only_widgets:
if isinstance(widget, QMenu):
widget.menuAction().setVisible(show_psbt_only_widgets)
else:
widget.setVisible(show_psbt_only_widgets)
run_hook('transaction_dialog_update', self) run_hook('transaction_dialog_update', self)
def update_io(self): def update_io(self):

8
electrum/plugins/coldcard/qt.py

@ -78,15 +78,15 @@ class Plugin(ColdcardPlugin, QtPluginBase):
def gettx_for_coldcard_export() -> PartialTransaction: def gettx_for_coldcard_export() -> PartialTransaction:
if not isinstance(dia.tx, PartialTransaction): if not isinstance(dia.tx, PartialTransaction):
raise Exception("Can only export partial transactions for coinjoins.") raise Exception("Can only export partial transactions for {}.".format(self.device))
tx = copy.deepcopy(dia.tx) tx = copy.deepcopy(dia.tx)
tx.add_info_from_wallet(dia.wallet, include_xpubs_and_full_paths=True) tx.add_info_from_wallet(dia.wallet, include_xpubs_and_full_paths=True)
return tx return tx
# add a new "export" option # add a new "export" option
if isinstance(dia.tx, PartialTransaction): export_submenu = dia.export_actions_menu.addMenu(_("For {}; include xpubs").format(self.device))
export_submenu = dia.export_actions_menu.addMenu(_("For {}; include xpubs").format(self.device)) dia.add_export_actions_to_menu(export_submenu, gettx=gettx_for_coldcard_export)
dia.add_export_actions_to_menu(export_submenu, gettx=gettx_for_coldcard_export) dia.psbt_only_widgets.append(export_submenu)
def show_settings_dialog(self, window, keystore): def show_settings_dialog(self, window, keystore):
# When they click on the icon for CC we come here. # When they click on the icon for CC we come here.

9
electrum/plugins/cosigner_pool/qt.py

@ -149,25 +149,26 @@ class Plugin(BasePlugin):
d.cosigner_send_button = b = QPushButton(_("Send to cosigner")) d.cosigner_send_button = b = QPushButton(_("Send to cosigner"))
b.clicked.connect(lambda: self.do_send(d.tx)) b.clicked.connect(lambda: self.do_send(d.tx))
d.buttons.insert(0, b) d.buttons.insert(0, b)
self.transaction_dialog_update(d) b.setVisible(False)
@hook @hook
def transaction_dialog_update(self, d: 'TxDialog'): def transaction_dialog_update(self, d: 'TxDialog'):
if d.tx.is_complete() or d.wallet.can_sign(d.tx): if d.tx.is_complete() or d.wallet.can_sign(d.tx):
d.cosigner_send_button.hide() d.cosigner_send_button.setVisible(False)
return return
for window, xpub, K, _hash in self.cosigner_list: for window, xpub, K, _hash in self.cosigner_list:
if window.wallet == d.wallet and self.cosigner_can_sign(d.tx, xpub): if window.wallet == d.wallet and self.cosigner_can_sign(d.tx, xpub):
d.cosigner_send_button.show() d.cosigner_send_button.setVisible(True)
break break
else: else:
d.cosigner_send_button.hide() d.cosigner_send_button.setVisible(False)
def cosigner_can_sign(self, tx: Transaction, cosigner_xpub: str) -> bool: def cosigner_can_sign(self, tx: Transaction, cosigner_xpub: str) -> bool:
if not isinstance(tx, PartialTransaction): if not isinstance(tx, PartialTransaction):
return False return False
if tx.is_complete(): if tx.is_complete():
return False return False
# TODO this is broken currently as it assumes tx.xpubs
return cosigner_xpub in {bip32node.to_xpub() for bip32node in tx.xpubs} return cosigner_xpub in {bip32node.to_xpub() for bip32node in tx.xpubs}
def do_send(self, tx: Union[Transaction, PartialTransaction]): def do_send(self, tx: Union[Transaction, PartialTransaction]):

6
electrum/plugins/greenaddress_instant/qt.py

@ -47,8 +47,8 @@ class Plugin(BasePlugin):
def transaction_dialog(self, d: 'TxDialog'): def transaction_dialog(self, d: 'TxDialog'):
d.verify_button = QPushButton(self.button_label) d.verify_button = QPushButton(self.button_label)
d.verify_button.clicked.connect(lambda: self.do_verify(d)) d.verify_button.clicked.connect(lambda: self.do_verify(d))
d.verify_button.setVisible(False)
d.buttons.insert(0, d.verify_button) d.buttons.insert(0, d.verify_button)
self.transaction_dialog_update(d)
def get_my_addr(self, d: 'TxDialog'): def get_my_addr(self, d: 'TxDialog'):
"""Returns the address for given tx which can be used to request """Returns the address for given tx which can be used to request
@ -61,9 +61,9 @@ class Plugin(BasePlugin):
@hook @hook
def transaction_dialog_update(self, d: 'TxDialog'): def transaction_dialog_update(self, d: 'TxDialog'):
if d.tx.is_complete() and self.get_my_addr(d): if d.tx.is_complete() and self.get_my_addr(d):
d.verify_button.show() d.verify_button.setVisible(True)
else: else:
d.verify_button.hide() d.verify_button.setVisible(False)
def do_verify(self, d: 'TxDialog'): def do_verify(self, d: 'TxDialog'):
tx = d.tx tx = d.tx

Loading…
Cancel
Save