qt tx dialog: small clean-up in constructors
This commit is contained in:
@@ -23,14 +23,14 @@
|
|||||||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
# SOFTWARE.
|
# SOFTWARE.
|
||||||
|
|
||||||
from typing import TYPE_CHECKING, Optional
|
from typing import TYPE_CHECKING, Optional, Union
|
||||||
|
|
||||||
from PyQt5.QtWidgets import QVBoxLayout, QLabel, QGridLayout, QPushButton, QLineEdit
|
from PyQt5.QtWidgets import QVBoxLayout, QLabel, QGridLayout, QPushButton, QLineEdit
|
||||||
|
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
from electrum.util import NotEnoughFunds, NoDynamicFeeEstimates
|
from electrum.util import NotEnoughFunds, NoDynamicFeeEstimates
|
||||||
from electrum.plugin import run_hook
|
from electrum.plugin import run_hook
|
||||||
from electrum.transaction import Transaction
|
from electrum.transaction import Transaction, PartialTransaction
|
||||||
from electrum.simple_config import FEERATE_WARNING_HIGH_FEE
|
from electrum.simple_config import FEERATE_WARNING_HIGH_FEE
|
||||||
from electrum.wallet import InternalAddressCorruption
|
from electrum.wallet import InternalAddressCorruption
|
||||||
|
|
||||||
@@ -45,11 +45,12 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
class TxEditor:
|
class TxEditor:
|
||||||
|
|
||||||
def __init__(self, window: 'ElectrumWindow', make_tx, output_value, is_sweep):
|
def __init__(self, *, window: 'ElectrumWindow', make_tx,
|
||||||
|
output_value: Union[int, str] = None, is_sweep: bool):
|
||||||
self.main_window = window
|
self.main_window = window
|
||||||
self.make_tx = make_tx
|
self.make_tx = make_tx
|
||||||
self.output_value = output_value
|
self.output_value = output_value
|
||||||
self.tx = None # type: Optional[Transaction]
|
self.tx = None # type: Optional[PartialTransaction]
|
||||||
self.config = window.config
|
self.config = window.config
|
||||||
self.wallet = window.wallet
|
self.wallet = window.wallet
|
||||||
self.not_enough_funds = False
|
self.not_enough_funds = False
|
||||||
@@ -115,9 +116,9 @@ class TxEditor:
|
|||||||
class ConfirmTxDialog(TxEditor, WindowModalDialog):
|
class ConfirmTxDialog(TxEditor, WindowModalDialog):
|
||||||
# set fee and return password (after pw check)
|
# set fee and return password (after pw check)
|
||||||
|
|
||||||
def __init__(self, window: 'ElectrumWindow', make_tx, output_value, is_sweep):
|
def __init__(self, *, window: 'ElectrumWindow', make_tx, output_value: Union[int, str], is_sweep: bool):
|
||||||
|
|
||||||
TxEditor.__init__(self, window, make_tx, output_value, is_sweep)
|
TxEditor.__init__(self, window=window, make_tx=make_tx, output_value=output_value, is_sweep=is_sweep)
|
||||||
WindowModalDialog.__init__(self, window, _("Confirm Transaction"))
|
WindowModalDialog.__init__(self, window, _("Confirm Transaction"))
|
||||||
vbox = QVBoxLayout()
|
vbox = QVBoxLayout()
|
||||||
self.setLayout(vbox)
|
self.setLayout(vbox)
|
||||||
|
|||||||
@@ -1478,7 +1478,9 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
|||||||
def get_manually_selected_coins(self) -> Sequence[PartialTxInput]:
|
def get_manually_selected_coins(self) -> Sequence[PartialTxInput]:
|
||||||
return self.utxo_list.get_spend_list()
|
return self.utxo_list.get_spend_list()
|
||||||
|
|
||||||
def pay_onchain_dialog(self, inputs, outputs, invoice=None, external_keypairs=None):
|
def pay_onchain_dialog(self, inputs: Sequence[PartialTxInput],
|
||||||
|
outputs: List[PartialTxOutput], *,
|
||||||
|
invoice=None, external_keypairs=None) -> None:
|
||||||
# trustedcoin requires this
|
# trustedcoin requires this
|
||||||
if run_hook('abort_send', self):
|
if run_hook('abort_send', self):
|
||||||
return
|
return
|
||||||
@@ -1493,11 +1495,13 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
|||||||
self.show_error(_("More than one output set to spend max"))
|
self.show_error(_("More than one output set to spend max"))
|
||||||
return
|
return
|
||||||
if self.config.get('advanced_preview'):
|
if self.config.get('advanced_preview'):
|
||||||
self.preview_tx_dialog(make_tx, outputs, external_keypairs=external_keypairs, invoice=invoice)
|
self.preview_tx_dialog(make_tx=make_tx,
|
||||||
|
external_keypairs=external_keypairs,
|
||||||
|
invoice=invoice)
|
||||||
return
|
return
|
||||||
|
|
||||||
output_value = '!' if '!' in output_values else sum(output_values)
|
output_value = '!' if '!' in output_values else sum(output_values)
|
||||||
d = ConfirmTxDialog(self, make_tx, output_value, is_sweep)
|
d = ConfirmTxDialog(window=self, make_tx=make_tx, output_value=output_value, is_sweep=is_sweep)
|
||||||
d.update_tx()
|
d.update_tx()
|
||||||
if d.not_enough_funds:
|
if d.not_enough_funds:
|
||||||
self.show_message(_('Not Enough Funds'))
|
self.show_message(_('Not Enough Funds'))
|
||||||
@@ -1509,15 +1513,19 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
|||||||
def sign_done(success):
|
def sign_done(success):
|
||||||
if success:
|
if success:
|
||||||
self.broadcast_or_show(tx, invoice=invoice)
|
self.broadcast_or_show(tx, invoice=invoice)
|
||||||
self.sign_tx_with_password(tx, sign_done, password, external_keypairs)
|
self.sign_tx_with_password(tx, callback=sign_done, password=password,
|
||||||
|
external_keypairs=external_keypairs)
|
||||||
else:
|
else:
|
||||||
self.preview_tx_dialog(make_tx, outputs, external_keypairs=external_keypairs, invoice=invoice)
|
self.preview_tx_dialog(make_tx=make_tx,
|
||||||
|
external_keypairs=external_keypairs,
|
||||||
|
invoice=invoice)
|
||||||
|
|
||||||
def preview_tx_dialog(self, make_tx, outputs, external_keypairs=None, invoice=None):
|
def preview_tx_dialog(self, *, make_tx, external_keypairs=None, invoice=None):
|
||||||
d = PreviewTxDialog(make_tx, outputs, external_keypairs, window=self, invoice=invoice)
|
d = PreviewTxDialog(make_tx=make_tx, external_keypairs=external_keypairs,
|
||||||
|
window=self, invoice=invoice)
|
||||||
d.show()
|
d.show()
|
||||||
|
|
||||||
def broadcast_or_show(self, tx, invoice=None):
|
def broadcast_or_show(self, tx, *, invoice=None):
|
||||||
if not self.network:
|
if not self.network:
|
||||||
self.show_error(_("You can't broadcast a transaction without a live network connection."))
|
self.show_error(_("You can't broadcast a transaction without a live network connection."))
|
||||||
self.show_transaction(tx, invoice=invoice)
|
self.show_transaction(tx, invoice=invoice)
|
||||||
@@ -1527,10 +1535,10 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
|||||||
self.broadcast_transaction(tx, invoice=invoice)
|
self.broadcast_transaction(tx, invoice=invoice)
|
||||||
|
|
||||||
@protected
|
@protected
|
||||||
def sign_tx(self, tx, callback, external_keypairs, password):
|
def sign_tx(self, tx, *, callback, external_keypairs, password):
|
||||||
self.sign_tx_with_password(tx, callback, password, external_keypairs=external_keypairs)
|
self.sign_tx_with_password(tx, callback=callback, password=password, external_keypairs=external_keypairs)
|
||||||
|
|
||||||
def sign_tx_with_password(self, tx: PartialTransaction, callback, password, external_keypairs=None):
|
def sign_tx_with_password(self, tx: PartialTransaction, *, callback, password, external_keypairs=None):
|
||||||
'''Sign the transaction in a separate thread. When done, calls
|
'''Sign the transaction in a separate thread. When done, calls
|
||||||
the callback with a success code of True or False.
|
the callback with a success code of True or False.
|
||||||
'''
|
'''
|
||||||
@@ -1606,7 +1614,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
|||||||
# we need to know the fee before we broadcast, because the txid is required
|
# we need to know the fee before we broadcast, because the txid is required
|
||||||
# however, the user must not be allowed to broadcast early
|
# however, the user must not be allowed to broadcast early
|
||||||
make_tx = self.mktx_for_open_channel(funding_sat)
|
make_tx = self.mktx_for_open_channel(funding_sat)
|
||||||
d = ConfirmTxDialog(self, make_tx, funding_sat, False)
|
d = ConfirmTxDialog(window=self, make_tx=make_tx, output_value=funding_sat, is_sweep=False)
|
||||||
cancelled, is_send, password, funding_tx = d.run()
|
cancelled, is_send, password, funding_tx = d.run()
|
||||||
if not is_send:
|
if not is_send:
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -291,7 +291,7 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
|
|||||||
|
|
||||||
self.sign_button.setDisabled(True)
|
self.sign_button.setDisabled(True)
|
||||||
self.main_window.push_top_level_window(self)
|
self.main_window.push_top_level_window(self)
|
||||||
self.main_window.sign_tx(self.tx, sign_done, self.external_keypairs)
|
self.main_window.sign_tx(self.tx, callback=sign_done, external_keypairs=self.external_keypairs)
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
self.main_window.push_top_level_window(self)
|
self.main_window.push_top_level_window(self)
|
||||||
@@ -601,9 +601,10 @@ class TxDialog(BaseTxDialog):
|
|||||||
|
|
||||||
class PreviewTxDialog(BaseTxDialog, TxEditor):
|
class PreviewTxDialog(BaseTxDialog, TxEditor):
|
||||||
|
|
||||||
def __init__(self, make_tx, outputs, external_keypairs, *, window: 'ElectrumWindow', invoice):
|
def __init__(self, *, make_tx, external_keypairs, window: 'ElectrumWindow', invoice):
|
||||||
TxEditor.__init__(self, window, make_tx, outputs, is_sweep=bool(external_keypairs))
|
TxEditor.__init__(self, window=window, make_tx=make_tx, is_sweep=bool(external_keypairs))
|
||||||
BaseTxDialog.__init__(self, parent=window, invoice=invoice, desc='', prompt_if_unsaved=False, finalized=False, external_keypairs=external_keypairs)
|
BaseTxDialog.__init__(self, parent=window, invoice=invoice, desc='', prompt_if_unsaved=False,
|
||||||
|
finalized=False, external_keypairs=external_keypairs)
|
||||||
self.update_tx()
|
self.update_tx()
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user