TxDialog: fix hooks. only show psbt widgets when applicable.
users of 'transaction_dialog' were assuming that dialog.tx is already set
This commit is contained in:
@@ -78,15 +78,15 @@ class Plugin(ColdcardPlugin, QtPluginBase):
|
||||
|
||||
def gettx_for_coldcard_export() -> 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.add_info_from_wallet(dia.wallet, include_xpubs_and_full_paths=True)
|
||||
return tx
|
||||
|
||||
# add a new "export" option
|
||||
if isinstance(dia.tx, PartialTransaction):
|
||||
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)
|
||||
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.psbt_only_widgets.append(export_submenu)
|
||||
|
||||
def show_settings_dialog(self, window, keystore):
|
||||
# When they click on the icon for CC we come here.
|
||||
|
||||
@@ -149,25 +149,26 @@ class Plugin(BasePlugin):
|
||||
d.cosigner_send_button = b = QPushButton(_("Send to cosigner"))
|
||||
b.clicked.connect(lambda: self.do_send(d.tx))
|
||||
d.buttons.insert(0, b)
|
||||
self.transaction_dialog_update(d)
|
||||
b.setVisible(False)
|
||||
|
||||
@hook
|
||||
def transaction_dialog_update(self, d: 'TxDialog'):
|
||||
if d.tx.is_complete() or d.wallet.can_sign(d.tx):
|
||||
d.cosigner_send_button.hide()
|
||||
d.cosigner_send_button.setVisible(False)
|
||||
return
|
||||
for window, xpub, K, _hash in self.cosigner_list:
|
||||
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
|
||||
else:
|
||||
d.cosigner_send_button.hide()
|
||||
d.cosigner_send_button.setVisible(False)
|
||||
|
||||
def cosigner_can_sign(self, tx: Transaction, cosigner_xpub: str) -> bool:
|
||||
if not isinstance(tx, PartialTransaction):
|
||||
return False
|
||||
if tx.is_complete():
|
||||
return False
|
||||
# TODO this is broken currently as it assumes tx.xpubs
|
||||
return cosigner_xpub in {bip32node.to_xpub() for bip32node in tx.xpubs}
|
||||
|
||||
def do_send(self, tx: Union[Transaction, PartialTransaction]):
|
||||
|
||||
@@ -47,8 +47,8 @@ class Plugin(BasePlugin):
|
||||
def transaction_dialog(self, d: 'TxDialog'):
|
||||
d.verify_button = QPushButton(self.button_label)
|
||||
d.verify_button.clicked.connect(lambda: self.do_verify(d))
|
||||
d.verify_button.setVisible(False)
|
||||
d.buttons.insert(0, d.verify_button)
|
||||
self.transaction_dialog_update(d)
|
||||
|
||||
def get_my_addr(self, d: 'TxDialog'):
|
||||
"""Returns the address for given tx which can be used to request
|
||||
@@ -61,9 +61,9 @@ class Plugin(BasePlugin):
|
||||
@hook
|
||||
def transaction_dialog_update(self, d: 'TxDialog'):
|
||||
if d.tx.is_complete() and self.get_my_addr(d):
|
||||
d.verify_button.show()
|
||||
d.verify_button.setVisible(True)
|
||||
else:
|
||||
d.verify_button.hide()
|
||||
d.verify_button.setVisible(False)
|
||||
|
||||
def do_verify(self, d: 'TxDialog'):
|
||||
tx = d.tx
|
||||
|
||||
Reference in New Issue
Block a user