From 241bf9ddd1aca6e3944463fbdc3bd84881b82bba Mon Sep 17 00:00:00 2001 From: ThomasV Date: Wed, 24 Mar 2021 15:34:53 +0100 Subject: [PATCH] kivy: if password is unified, allow user to reset pin code --- electrum/gui/kivy/main_window.py | 42 +++++++++++++++++++---- electrum/gui/kivy/uix/dialogs/settings.py | 2 +- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/electrum/gui/kivy/main_window.py b/electrum/gui/kivy/main_window.py index f1e2fc858..57c824361 100644 --- a/electrum/gui/kivy/main_window.py +++ b/electrum/gui/kivy/main_window.py @@ -39,7 +39,8 @@ from kivy.clock import Clock from kivy.factory import Factory from kivy.metrics import inch from kivy.lang import Builder -from .uix.dialogs.password_dialog import OpenWalletDialog, ChangePasswordDialog, PincodeDialog +from .uix.dialogs.password_dialog import OpenWalletDialog, ChangePasswordDialog, PincodeDialog, PasswordDialog +from .uix.dialogs.choice_dialog import ChoiceDialog ## lazy imports for factory so that widgets can be used in kv #Factory.register('InstallWizard', module='electrum.gui.kivy.uix.dialogs.installwizard') @@ -143,7 +144,6 @@ class ElectrumWindow(App, Logger): self.proxy_str = (host + ':' + port) if mode else _('None') def choose_server_dialog(self, popup): - from .uix.dialogs.choice_dialog import ChoiceDialog protocol = PREFERRED_NETWORK_PROTOCOL def cb2(server_str): popup.ids.server_str.text = server_str @@ -168,7 +168,6 @@ class ElectrumWindow(App, Logger): self.network.run_from_another_thread(self.network.set_parameters(net_params)) def choose_blockchain_dialog(self, dt): - from .uix.dialogs.choice_dialog import ChoiceDialog chains = self.network.get_blockchains() def cb(name): with blockchain.blockchains_lock: blockchain_items = list(blockchain.blockchains.items()) @@ -1282,12 +1281,41 @@ class ElectrumWindow(App, Logger): d = ChangePasswordDialog(self, self.wallet, on_success, on_failure) d.open() + def pin_code_dialog(self, cb): + if self._use_single_password and self.has_pin_code(): + def on_choice(choice): + if choice == 0: + self.change_pin_code(cb) + else: + self.reset_pin_code(cb) + choices = {0:'Change PIN code', 1:'Reset PIN'} + dialog = ChoiceDialog( + _('PIN Code'), choices, 0, + on_choice, + keep_choice_order=True) + dialog.open() + else: + self.change_pin_code(cb) + + def reset_pin_code(self, cb): + on_success = lambda x: self._set_new_pin_code(None, cb) + d = PasswordDialog(self, + basename = self.wallet.basename(), + check_password = self.wallet.check_password, + on_success=on_success, + on_failure=lambda: None, + is_change=False, + has_password=self.wallet.has_password()) + d.open() + + def _set_new_pin_code(self, new_pin, cb): + self.electrum_config.set_key('pin_code', new_pin) + cb() + self.show_info(_("PIN updated") if new_pin else _('PIN disabled')) + def change_pin_code(self, cb): - def on_success(old_password, new_password): - self.electrum_config.set_key('pin_code', new_password) - cb() - self.show_info(_("PIN updated") if new_password else _('PIN disabled')) on_failure = lambda: self.show_error(_("PIN not updated")) + on_success = lambda old_pin, new_pin: self._set_new_pin_code(new_pin, cb) d = PincodeDialog( self, check_password=self.check_pin_code, diff --git a/electrum/gui/kivy/uix/dialogs/settings.py b/electrum/gui/kivy/uix/dialogs/settings.py index b2db28d2f..0ef25698a 100644 --- a/electrum/gui/kivy/uix/dialogs/settings.py +++ b/electrum/gui/kivy/uix/dialogs/settings.py @@ -133,7 +133,7 @@ class SettingsDialog(Factory.Popup): self.app.change_password(self.update) def change_pin_code(self, label, dt): - self.app.change_pin_code(self.update) + self.app.pin_code_dialog(self.update) def language_dialog(self, item, dt): if self._language_dialog is None: