From 605b511b43aedd9cae7e6185fcebf266af2463de Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Fri, 31 Jan 2025 18:03:21 +0100 Subject: [PATCH] qt,qml: move get_text_not_enough_funds_mentioning_frozen and get_frozen_balance_str to backend wallet Note: the qt gui used to include FX in get_frozen_balance_str, but that is not replicated now. --- electrum/gui/qml/components/InvoiceDialog.qml | 4 ++-- .../gui/qml/components/OpenChannelDialog.qml | 2 +- electrum/gui/qml/qewallet.py | 18 +++--------------- electrum/gui/qt/send_tab.py | 17 ++--------------- electrum/wallet.py | 13 +++++++++++++ 5 files changed, 21 insertions(+), 33 deletions(-) diff --git a/electrum/gui/qml/components/InvoiceDialog.qml b/electrum/gui/qml/components/InvoiceDialog.qml index 4b79497ce..df23a92c2 100644 --- a/electrum/gui/qml/components/InvoiceDialog.qml +++ b/electrum/gui/qml/components/InvoiceDialog.qml @@ -230,9 +230,9 @@ ElDialog { Connections { target: invoice.amountOverride function onSatsIntChanged() { - console.log('amuontOverride satsIntChanged, sats=' + invoice.amountOverride.satsInt) + console.log('amountOverride satsIntChanged, sats=' + invoice.amountOverride.satsInt) if (amountMax.checked) // amountOverride updated by max amount estimate - amountBtc.text = Config.formatSats(invoice.amountOverride.satsInt) + amountBtc.text = Config.formatSatsForEditing(invoice.amountOverride.satsInt) } } } diff --git a/electrum/gui/qml/components/OpenChannelDialog.qml b/electrum/gui/qml/components/OpenChannelDialog.qml index 393bc6948..facff3d6e 100644 --- a/electrum/gui/qml/components/OpenChannelDialog.qml +++ b/electrum/gui/qml/components/OpenChannelDialog.qml @@ -183,7 +183,7 @@ ElDialog { target: channelopener.amount function onSatsIntChanged() { if (is_max.checked) // amount updated by max amount estimate - amountBtc.text = Config.formatSats(channelopener.amount.satsInt) + amountBtc.text = Config.formatSatsForEditing(channelopener.amount.satsInt) } } } diff --git a/electrum/gui/qml/qewallet.py b/electrum/gui/qml/qewallet.py index 6b2da34f3..5442b1e9f 100644 --- a/electrum/gui/qml/qewallet.py +++ b/electrum/gui/qml/qewallet.py @@ -819,20 +819,8 @@ class QEWallet(AuthMixin, QObject, QtEventListener): sig = self.wallet.sign_message(address, message, self.password) return base64.b64encode(sig).decode('ascii') - def get_text_not_enough_funds_mentioning_frozen(self) -> str: - text = _('Not enough funds') - frozen_str = self.get_frozen_balance_str() - if frozen_str: - text += " ({} {})".format(frozen_str, _('are frozen')) - return text - - def get_frozen_balance_str(self) -> Optional[str]: - frozen_bal = sum(self.wallet.get_frozen_balance()) - if not frozen_bal: - return None - return self.wallet.config.format_amount_and_units(frozen_bal) - - def determine_max(self, *, mktx: Callable[[int], PartialTransaction]) -> Tuple[int, str]: + def determine_max(self, *, mktx: Callable[[Optional[int]], PartialTransaction]) -> Tuple[Optional[int], Optional[str]]: + # TODO: merge with SendTab.spend_max() and move to backend wallet amount = message = None try: try: @@ -844,6 +832,6 @@ class QEWallet(AuthMixin, QObject, QtEventListener): amount = tx.output_value() except NotEnoughFunds as e: self._logger.debug(str(e)) - message = self.get_text_not_enough_funds_mentioning_frozen() + message = self.wallet.get_text_not_enough_funds_mentioning_frozen() return amount, message diff --git a/electrum/gui/qt/send_tab.py b/electrum/gui/qt/send_tab.py index edfe3d63d..402dd729b 100644 --- a/electrum/gui/qt/send_tab.py +++ b/electrum/gui/qt/send_tab.py @@ -267,7 +267,7 @@ class SendTab(QWidget, MessageBoxMixin, Logger): tx = make_tx(0) except NotEnoughFunds as e: self.max_button.setChecked(False) - text = self.get_text_not_enough_funds_mentioning_frozen() + text = self.wallet.get_text_not_enough_funds_mentioning_frozen() self.show_error(text) return @@ -283,7 +283,7 @@ class SendTab(QWidget, MessageBoxMixin, Logger): if x_fee_amount: twofactor_fee_str = self.format_amount_and_units(x_fee_amount) msg += "\n" + _("2fa fee: {} (for the next batch of transactions)").format(twofactor_fee_str) - frozen_bal = self.get_frozen_balance_str() + frozen_bal = self.wallet.get_frozen_balance_str() if frozen_bal: msg += "\n" + _("Some coins are frozen: {} (can be unfrozen in the Addresses or in the Coins tab)").format(frozen_bal) QToolTip.showText(self.max_button.mapToGlobal(QPoint(0, 0)), msg) @@ -353,19 +353,6 @@ class SendTab(QWidget, MessageBoxMixin, Logger): callback=sign_done, external_keypairs=external_keypairs) - def get_text_not_enough_funds_mentioning_frozen(self) -> str: - text = _("Not enough funds") - frozen_str = self.get_frozen_balance_str() - if frozen_str: - text += " ({} {})".format(frozen_str, _("are frozen")) - return text - - def get_frozen_balance_str(self) -> Optional[str]: - frozen_bal = sum(self.wallet.get_frozen_balance()) - if not frozen_bal: - return None - return self.format_amount_and_units(frozen_bal) - def do_clear(self): self.logger.debug('do_clear') self.lock_fields(lock_recipient=False, lock_amount=False, lock_max=True, lock_description=False) diff --git a/electrum/wallet.py b/electrum/wallet.py index 2af3a0e25..6cdc84c4e 100644 --- a/electrum/wallet.py +++ b/electrum/wallet.py @@ -3356,6 +3356,19 @@ class Abstract_Wallet(ABC, Logger, EventListener): def get_unlocked_password(self): return self._password_in_memory + def get_text_not_enough_funds_mentioning_frozen(self) -> str: + text = _('Not enough funds') + frozen_str = self.get_frozen_balance_str() + if frozen_str: + text += ' ' + _('({} are frozen)').format(frozen_str) + return text + + def get_frozen_balance_str(self) -> Optional[str]: + frozen_bal = sum(self.get_frozen_balance()) + if not frozen_bal: + return None + return self.config.format_amount_and_units(frozen_bal) + class Simple_Wallet(Abstract_Wallet): # wallet with a single keystore