From 19f7d2adb9feda6a9d602088973980f099754e60 Mon Sep 17 00:00:00 2001 From: tadeubas Date: Thu, 24 Aug 2023 11:33:01 -0300 Subject: [PATCH] All QR Codes not allow brightness change --- src/krux/pages/__init__.py | 20 ++++++-------------- src/krux/pages/addresses.py | 2 +- src/krux/pages/home.py | 4 ++-- src/krux/pages/keypads.py | 2 -- src/krux/pages/tools.py | 2 +- tests/pages/test_home.py | 6 ++---- 6 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/krux/pages/__init__.py b/src/krux/pages/__init__.py index 6c8ba8d05..fc3ef10e9 100644 --- a/src/krux/pages/__init__.py +++ b/src/krux/pages/__init__.py @@ -50,7 +50,8 @@ QR_CODE_STEP_TIME = 100 CAMERA_INIT_TIME = 1000 -TOGGLE_BRIGHTNESS = 2 +TOGGLE_BRIGHTNESS = (BUTTON_PAGE, BUTTON_PAGE_PREV) +PROCEED = (BUTTON_ENTER, BUTTON_TOUCH) LETTERS = "abcdefghijklmnopqrstuvwxyz" UPPERCASE_LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" @@ -73,15 +74,6 @@ def __init__(self, ctx, menu): self.y_keypad_map = [] self.x_keypad_map = [] - def wait_for_proceed_qr(self, block=True, any_btn=False): - """Wrap acknowledgements which can be answared with multiple buttons""" - if any_btn: - return self.ctx.input.wait_for_button(block) is not None - btn = self.ctx.input.wait_for_button(block) - if btn == BUTTON_PAGE: - return TOGGLE_BRIGHTNESS - return btn in (BUTTON_ENTER, BUTTON_TOUCH) - def esc_prompt(self): """Prompts user for leaving""" self.ctx.display.clear() @@ -290,7 +282,7 @@ def callback(): self.ctx.display.to_portrait() return entropy_bytes - def display_qr_codes(self, data, qr_format, title="", allow_any_btn=False): + def display_qr_codes(self, data, qr_format, title=""): """Displays a QR code or an animated series of QR codes to the user, encoding them in the specified format """ @@ -328,10 +320,10 @@ def display_qr_codes(self, data, qr_format, title="", allow_any_btn=False): self.ctx.display.draw_hcentered_text(subtitle, offset_y) i = (i + 1) % num_parts # There are cases we can allow any btn to change the screen - btn = self.wait_for_proceed_qr(block=num_parts == 1, any_btn=allow_any_btn) - if btn == TOGGLE_BRIGHTNESS: + btn = self.ctx.input.wait_for_button(num_parts == 1) + if btn in TOGGLE_BRIGHTNESS: bright = not bright - elif btn is True: + elif btn in PROCEED: done = True # interval done in input.py using timers diff --git a/src/krux/pages/addresses.py b/src/krux/pages/addresses.py index 2dd38bdea..b4143381d 100644 --- a/src/krux/pages/addresses.py +++ b/src/krux/pages/addresses.py @@ -154,7 +154,7 @@ def list_address_type(self, addr_type=0): def show_address(self, addr, title="", qr_format=FORMAT_NONE): """Show addr provided as a QRCode""" - self.display_qr_codes(addr, qr_format, title, allow_any_btn=True) + self.display_qr_codes(addr, qr_format, title) if self.print_qr_prompt(): from .print_page import PrintPage diff --git a/src/krux/pages/home.py b/src/krux/pages/home.py index b1368097d..d5be79272 100644 --- a/src/krux/pages/home.py +++ b/src/krux/pages/home.py @@ -116,7 +116,7 @@ def display_standard_qr(self): """Displays regular words QR code""" title = t("Plaintext QR") data = self.ctx.wallet.key.mnemonic - self.display_qr_codes(data, FORMAT_NONE, title, allow_any_btn=True) + self.display_qr_codes(data, FORMAT_NONE, title) self.print_standard_qr(data, FORMAT_NONE, title) return MENU_CONTINUE @@ -193,7 +193,7 @@ def public_key(self): # title receives first 4 chars (ex: XPUB) title = self.ctx.wallet.key.account_pubkey_str(version)[:4].upper() xpub = self.ctx.wallet.key.key_expression(version) - self.display_qr_codes(xpub, FORMAT_NONE, title, allow_any_btn=True) + self.display_qr_codes(xpub, FORMAT_NONE, title) self.print_standard_qr(xpub, FORMAT_NONE, title) return MENU_CONTINUE diff --git a/src/krux/pages/keypads.py b/src/krux/pages/keypads.py index 15850ff8e..cab0b3fa6 100644 --- a/src/krux/pages/keypads.py +++ b/src/krux/pages/keypads.py @@ -43,8 +43,6 @@ QR_CODE_STEP_TIME = 100 CAMERA_INIT_TIME = 1000 -TOGGLE_BRIGHTNESS = 2 - LETTERS = "abcdefghijklmnopqrstuvwxyz" UPPERCASE_LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" NUM_SPECIAL_1 = "0123456789 !#$%&'()*" diff --git a/src/krux/pages/tools.py b/src/krux/pages/tools.py index 88455a84c..443694b51 100644 --- a/src/krux/pages/tools.py +++ b/src/krux/pages/tools.py @@ -147,7 +147,7 @@ def _delete_encrypted_mnemonic(self, mnemonic_id, sd_card=False): def print_test(self): """Handler for the 'Print Test QR' menu item""" title = t("Krux Printer Test QR") - self.display_qr_codes(title, FORMAT_NONE, title, allow_any_btn=True) + self.display_qr_codes(title, FORMAT_NONE, title) from .print_page import PrintPage print_page = PrintPage(self.ctx) diff --git a/tests/pages/test_home.py b/tests/pages/test_home.py index 9a9d4179e..967861459 100644 --- a/tests/pages/test_home.py +++ b/tests/pages/test_home.py @@ -261,7 +261,7 @@ def test_mnemonic_standard_qr(mocker, m5stickv, tdata): title = "Plaintext QR" home.display_qr_codes.assert_called_with( - ctx.wallet.key.mnemonic, FORMAT_NONE, title, allow_any_btn=True + ctx.wallet.key.mnemonic, FORMAT_NONE, title ) if case[1] is not None: home.print_standard_qr.assert_called_with( @@ -491,7 +491,7 @@ def test_mnemonic_st_qr_touch(mocker, amigo_tft, tdata): title = "Plaintext QR" home.display_qr_codes.assert_called_with( - ctx.wallet.key.mnemonic, FORMAT_NONE, title, allow_any_btn=True + ctx.wallet.key.mnemonic, FORMAT_NONE, title ) if case[1] is not None: home.print_standard_qr.assert_called_with( @@ -585,13 +585,11 @@ def test_public_key(mocker, m5stickv, tdata): ctx.wallet.key.key_expression(None), FORMAT_NONE, "XPUB", - allow_any_btn=True, ), mocker.call( ctx.wallet.key.key_expression(ctx.wallet.key.network[version]), FORMAT_NONE, "ZPUB", - allow_any_btn=True, ), ] print_qr_calls = [