ui: smarter ClickUI prompts only once

This also fixes #331 by moving the PIN matrix from trezorctl into the UI
class
pull/25/head
matejcik 6 years ago
parent ecf62ac43c
commit 1f2db3666b

@ -137,7 +137,7 @@ def cli(ctx, path, verbose, is_json):
if path is not None:
click.echo("Using path: {}".format(path))
sys.exit(1)
return TrezorClient(transport=device, ui=ui.ClickUI)
return TrezorClient(transport=device, ui=ui.ClickUI())
ctx.obj = get_device
@ -231,7 +231,6 @@ def get_features(connect):
@click.option("-r", "--remove", is_flag=True)
@click.pass_obj
def change_pin(connect, remove):
click.echo(ui.PIN_MATRIX_DESCRIPTION)
return device.change_pin(connect(), remove)

@ -56,12 +56,18 @@ def prompt(*args, **kwargs):
class ClickUI:
@staticmethod
def button_request(code):
echo("Please confirm action on your Trezor device")
@staticmethod
def get_pin(code=None):
def __init__(self, always_prompt=False):
self.pinmatrix_shown = False
self.prompt_shown = False
self.always_prompt = always_prompt
def button_request(self, code):
if not self.prompt_shown:
echo("Please confirm action on your Trezor device")
if not self.always_prompt:
self.prompt_shown = True
def get_pin(self, code=None):
if code == PIN_CURRENT:
desc = "current PIN"
elif code == PIN_NEW:
@ -70,7 +76,11 @@ class ClickUI:
desc = "new PIN again"
else:
desc = "PIN"
if not self.pinmatrix_shown:
echo(PIN_MATRIX_DESCRIPTION)
if not self.always_prompt:
self.pinmatrix_shown = True
while True:
try:
@ -82,8 +92,7 @@ class ClickUI:
else:
return pin
@staticmethod
def get_passphrase():
def get_passphrase(self):
if os.getenv("PASSPHRASE") is not None:
echo("Passphrase required. Using PASSPHRASE environment variable.")
return os.getenv("PASSPHRASE")

Loading…
Cancel
Save