From eba3fa03ee2ac70a6cf2516bf5b9aa6452547304 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Fri, 15 May 2020 19:11:31 +0200 Subject: [PATCH] kivy: confirm all actions even if there is no PIN set eh.. I've just consolidated hundreds of testnet UTXOs by accident --- electrum/gui/kivy/main_window.py | 18 +++++++++++++----- .../kivy/uix/dialogs/lightning_open_channel.py | 2 +- electrum/gui/kivy/uix/dialogs/question.py | 14 ++++++++++---- electrum/gui/kivy/uix/dialogs/tx_dialog.py | 2 +- electrum/gui/kivy/uix/screens.py | 1 - 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/electrum/gui/kivy/main_window.py b/electrum/gui/kivy/main_window.py index 1f8348227..5e40a5cd4 100644 --- a/electrum/gui/kivy/main_window.py +++ b/electrum/gui/kivy/main_window.py @@ -1153,14 +1153,21 @@ class ElectrumWindow(App): def protected(self, msg, f, args): if self.electrum_config.get('pin_code'): - on_success = lambda pw: f(*(args + (self.password,))) + msg += "\n" + _("Enter your PIN code to proceed") + on_success = lambda pw: f(*args, self.password) self.pincode_dialog( message = msg, check_password=self.check_pin_code, on_success=on_success, on_failure=lambda: None) else: - f(*(args + (self.password,))) + d = Question( + msg, + lambda b: f(*args, self.password) if b else None, + yes_str=_("OK"), + no_str=_("Cancel"), + title=_("Confirm action")) + d.open() def toggle_lightning(self): if self.wallet.has_lightning(): @@ -1202,7 +1209,8 @@ class ElectrumWindow(App): def _delete_wallet(self, b): if b: basename = self.wallet.basename() - self.protected(_("Enter your PIN code to confirm deletion of {}").format(basename), self.__delete_wallet, ()) + self.protected(_("Are you sure you want to delete wallet {}?").format(basename), + self.__delete_wallet, ()) def __delete_wallet(self, pw): wallet_path = self.get_wallet_path() @@ -1220,7 +1228,7 @@ class ElectrumWindow(App): self.load_wallet_by_name(new_path) def show_seed(self, label): - self.protected(_("Enter PIN code to display your seed"), self._show_seed, (label,)) + self.protected(_("Display your seed?"), self._show_seed, (label,)) def _show_seed(self, label, password): if self.wallet.has_password() and password is None: @@ -1316,7 +1324,7 @@ class ElectrumWindow(App): except InvalidPassword: self.show_error("Invalid PIN") return - self.protected(_("Enter your PIN code in order to decrypt your private key"), show_private_key, (addr, pk_label)) + self.protected(_("Decrypt your private key?"), show_private_key, (addr, pk_label)) def import_channel_backup(self, encrypted): d = Question(_('Import Channel Backup?'), lambda b: self._import_channel_backup(b, encrypted)) diff --git a/electrum/gui/kivy/uix/dialogs/lightning_open_channel.py b/electrum/gui/kivy/uix/dialogs/lightning_open_channel.py index ac22c96e4..b5f3c90cb 100644 --- a/electrum/gui/kivy/uix/dialogs/lightning_open_channel.py +++ b/electrum/gui/kivy/uix/dialogs/lightning_open_channel.py @@ -146,7 +146,7 @@ class LightningOpenChannelDialog(Factory.Popup): if self.ipport: conn_str += '@' + self.ipport.strip() amount = self.app.get_amount(self.amount) - self.app.protected('Enter PIN to create a new channel', self.do_open_channel, (conn_str, amount)) + self.app.protected('Create a new channel?', self.do_open_channel, (conn_str, amount)) self.dismiss() def do_open_channel(self, conn_str, amount, password): diff --git a/electrum/gui/kivy/uix/dialogs/question.py b/electrum/gui/kivy/uix/dialogs/question.py index 4b5e085fa..e5525084a 100644 --- a/electrum/gui/kivy/uix/dialogs/question.py +++ b/electrum/gui/kivy/uix/dialogs/question.py @@ -13,6 +13,8 @@ Builder.load_string(''' id: popup title: '' message: '' + yes_str: '' + no_str: '' size_hint: 0.8, 0.5 pos_hint: {'top':0.9} BoxLayout: @@ -27,14 +29,14 @@ Builder.load_string(''' orientation: 'horizontal' size_hint: 1, 0.2 Button: - text: _('No') + text: root.no_str size_hint: 0.5, None height: '48dp' on_release: root.callback(False) popup.dismiss() Button: - text: _('Yes') + text: root.yes_str size_hint: 0.5, None height: '48dp' on_release: @@ -46,8 +48,12 @@ Builder.load_string(''' class Question(Factory.Popup): - def __init__(self, msg, callback): + def __init__(self, msg, callback, *, + yes_str: str = None, no_str: str = None, + title: str = None): Factory.Popup.__init__(self) - self.title = _('Question') + self.yes_str = yes_str or _('Yes') + self.no_str = no_str or _('No') + self.title = title or _('Question') self.message = msg self.callback = callback diff --git a/electrum/gui/kivy/uix/dialogs/tx_dialog.py b/electrum/gui/kivy/uix/dialogs/tx_dialog.py index 227772bf8..09cb8a11f 100644 --- a/electrum/gui/kivy/uix/dialogs/tx_dialog.py +++ b/electrum/gui/kivy/uix/dialogs/tx_dialog.py @@ -253,7 +253,7 @@ class TxDialog(Factory.Popup): self.do_sign() def do_sign(self): - self.app.protected(_("Enter your PIN code in order to sign this transaction"), self._do_sign, ()) + self.app.protected(_("Sign this transaction?"), self._do_sign, ()) def _do_sign(self, password): self.status_str = _('Signing') + '...' diff --git a/electrum/gui/kivy/uix/screens.py b/electrum/gui/kivy/uix/screens.py index 3da88ccac..c3e5df605 100644 --- a/electrum/gui/kivy/uix/screens.py +++ b/electrum/gui/kivy/uix/screens.py @@ -374,7 +374,6 @@ class SendScreen(CScreen): feerate_warning = simple_config.FEERATE_WARNING_HIGH_FEE if fee > feerate_warning * tx.estimated_size() / 1000: msg.append(_('Warning') + ': ' + _("The fee for this transaction seems unusually high.")) - msg.append(_("Enter your PIN code to proceed")) self.app.protected('\n'.join(msg), self.send_tx, (tx,)) def send_tx(self, tx, password):