mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-31 09:21:39 +00:00
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:
parent
05c496edd1
commit
0c0a6b2145
4 changed files with 29 additions and 20 deletions
|
@ -28,7 +28,7 @@ import copy
|
|||
import datetime
|
||||
import traceback
|
||||
import time
|
||||
from typing import TYPE_CHECKING, Callable, Optional
|
||||
from typing import TYPE_CHECKING, Callable, Optional, List
|
||||
from functools import partial
|
||||
from decimal import Decimal
|
||||
|
||||
|
@ -110,6 +110,8 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
|
|||
self.setMinimumWidth(950)
|
||||
self.set_title()
|
||||
|
||||
self.psbt_only_widgets = [] # type: List[QWidget]
|
||||
|
||||
vbox = QVBoxLayout()
|
||||
self.setLayout(vbox)
|
||||
|
||||
|
@ -155,9 +157,9 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
|
|||
self.export_actions_menu = export_actions_menu = QMenu()
|
||||
self.add_export_actions_to_menu(export_actions_menu)
|
||||
export_actions_menu.addSeparator()
|
||||
#if isinstance(tx, PartialTransaction):
|
||||
export_for_coinjoin_submenu = export_actions_menu.addMenu(_("For CoinJoin; strip privates"))
|
||||
self.add_export_actions_to_menu(export_for_coinjoin_submenu, gettx=self._gettx_for_coinjoin)
|
||||
export_submenu = export_actions_menu.addMenu(_("For CoinJoin; strip privates"))
|
||||
self.add_export_actions_to_menu(export_submenu, gettx=self._gettx_for_coinjoin)
|
||||
self.psbt_only_widgets.append(export_submenu)
|
||||
|
||||
self.export_actions_button = QToolButton()
|
||||
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.setMenu(partial_tx_actions_menu)
|
||||
self.partial_tx_actions_button.setPopupMode(QToolButton.InstantPopup)
|
||||
self.psbt_only_widgets.append(self.partial_tx_actions_button)
|
||||
|
||||
# Action buttons
|
||||
self.buttons = []
|
||||
#if isinstance(tx, PartialTransaction):
|
||||
self.buttons.append(self.partial_tx_actions_button)
|
||||
self.buttons += [self.sign_button, self.broadcast_button, self.cancel_button]
|
||||
self.buttons = [self.partial_tx_actions_button, self.sign_button, self.broadcast_button, self.cancel_button]
|
||||
# Transaction sharing buttons
|
||||
self.sharing_buttons = [self.finalize_button, self.export_actions_button, self.save_button]
|
||||
run_hook('transaction_dialog', self)
|
||||
|
@ -389,7 +389,7 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
|
|||
size = self.tx.estimated_size()
|
||||
self.broadcast_button.setEnabled(tx_details.can_broadcast)
|
||||
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.tx_hash_e.setText(tx_details.txid or _('Unknown'))
|
||||
if desc is None:
|
||||
|
@ -441,6 +441,14 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
|
|||
self.amount_label.setText(amount_str)
|
||||
self.fee_label.setText(fee_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)
|
||||
|
||||
def update_io(self):
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue