Browse Source

kivy: pass message to password_dialog (follow-up d9172ade71)

hard-fail-on-bad-server-string
ThomasV 5 years ago
parent
commit
098af02789
  1. 27
      electrum/gui/kivy/main_window.py
  2. 9
      electrum/gui/kivy/uix/dialogs/password_dialog.py

27
electrum/gui/kivy/main_window.py

@ -1112,10 +1112,15 @@ class ElectrumWindow(App):
def on_fee(self, event, *arg): def on_fee(self, event, *arg):
self.fee_status = self.electrum_config.get_fee_status() self.fee_status = self.electrum_config.get_fee_status()
def protected(self, f, args): def protected(self, msg, f, args):
if self.electrum_config.get('pin_code'): if self.electrum_config.get('pin_code'):
on_success = lambda pw: f(*(args + (self.password,))) on_success = lambda pw: f(*(args + (self.password,)))
self.password_dialog(check_password=self.check_pin_code, on_success=on_success, on_failure=lambda: None, is_password=False) self.password_dialog(
message = msg,
check_password=self.check_pin_code,
on_success=on_success,
on_failure=lambda: None,
is_password=False)
else: else:
f(*(args + (self.password,))) f(*(args + (self.password,)))
@ -1177,7 +1182,7 @@ class ElectrumWindow(App):
self.load_wallet_by_name(new_path) self.load_wallet_by_name(new_path)
def show_seed(self, label): def show_seed(self, label):
self.protected(self._show_seed, (label,)) self.protected(_("Enter PIN code to display your seed"), self._show_seed, (label,))
def _show_seed(self, label, password): def _show_seed(self, label, password):
if self.wallet.has_password() and password is None: if self.wallet.has_password() and password is None:
@ -1196,31 +1201,23 @@ class ElectrumWindow(App):
if pin != self.electrum_config.get('pin_code'): if pin != self.electrum_config.get('pin_code'):
raise InvalidPassword raise InvalidPassword
def password_dialog(self, *, check_password: Callable = None, def password_dialog(self, **kwargs):
on_success: Callable = None, on_failure: Callable = None,
is_password=True):
if self._password_dialog is None: if self._password_dialog is None:
self._password_dialog = PasswordDialog() self._password_dialog = PasswordDialog()
self._password_dialog.init( self._password_dialog.init(self, **kwargs)
self, check_password = check_password,
on_success=on_success, on_failure=on_failure,
is_password=is_password)
self._password_dialog.open() self._password_dialog.open()
def change_password(self, cb): def change_password(self, cb):
if self._password_dialog is None:
self._password_dialog = PasswordDialog()
def on_success(old_password, new_password): def on_success(old_password, new_password):
self.wallet.update_password(old_password, new_password) self.wallet.update_password(old_password, new_password)
self.password = new_password self.password = new_password
self.show_info(_("Your password was updated")) self.show_info(_("Your password was updated"))
on_failure = lambda: self.show_error(_("Password not updated")) on_failure = lambda: self.show_error(_("Password not updated"))
self._password_dialog.init( self.password_dialog(
self, check_password = self.wallet.check_password, check_password = self.wallet.check_password,
on_success=on_success, on_failure=on_failure, on_success=on_success, on_failure=on_failure,
is_change=True, is_password=True, is_change=True, is_password=True,
has_password=self.wallet.has_password()) has_password=self.wallet.has_password())
self._password_dialog.open()
def change_pin_code(self, cb): def change_pin_code(self, cb):
if self._password_dialog is None: if self._password_dialog is None:

9
electrum/gui/kivy/uix/dialogs/password_dialog.py

@ -115,11 +115,12 @@ class PasswordDialog(Factory.Popup):
check_password = None, check_password = None,
on_success: Callable = None, on_failure: Callable = None, on_success: Callable = None, on_failure: Callable = None,
is_change: bool = False, is_change: bool = False,
is_password: bool = False, is_password: bool = True,
has_password: bool = False): has_password: bool = False,
message: str = ''):
self.app = app self.app = app
self.pw_check = check_password self.pw_check = check_password
self.message = '' self.message = message
self.on_success = on_success self.on_success = on_success
self.on_failure = on_failure self.on_failure = on_failure
self.success = False self.success = False
@ -134,7 +135,7 @@ class PasswordDialog(Factory.Popup):
def update_screen(self): def update_screen(self):
self.ids.kb.password = '' self.ids.kb.password = ''
self.ids.textinput_generic_password.text = '' self.ids.textinput_generic_password.text = ''
if self.level == 0: if self.level == 0 and self.message == '':
self.message = _('Enter your password') if self.is_generic else _('Enter your PIN') self.message = _('Enter your password') if self.is_generic else _('Enter your PIN')
elif self.level == 1: elif self.level == 1:
self.message = _('Enter new password') if self.is_generic else _('Enter new PIN') self.message = _('Enter new password') if self.is_generic else _('Enter new PIN')

Loading…
Cancel
Save