Skip to content

Commit

Permalink
All QR Codes not allow brightness change
Browse files Browse the repository at this point in the history
  • Loading branch information
tadeubas committed Aug 24, 2023
1 parent 08c0931 commit 19f7d2a
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 24 deletions.
20 changes: 6 additions & 14 deletions src/krux/pages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()
Expand Down Expand Up @@ -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
"""
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/krux/pages/addresses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/krux/pages/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions src/krux/pages/keypads.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 !#$%&'()*"
Expand Down
2 changes: 1 addition & 1 deletion src/krux/pages/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions tests/pages/test_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 = [
Expand Down

0 comments on commit 19f7d2a

Please sign in to comment.