From 26fefd7c7e4e0abde89d8898bf7203b19e5671f1 Mon Sep 17 00:00:00 2001 From: tadeubas Date: Sun, 21 Jul 2024 15:30:28 -0300 Subject: [PATCH 1/2] Change readme badges --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 20e7a37a..6fde1aa3 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ [![created at](https://img.shields.io/github/created-at/selfcustody/krux)](https://github.com/selfcustody/krux/commit/bb8e2d63e031417111ff7cb2b8877c10e19410be) [![downloads](https://img.shields.io/github/downloads/selfcustody/krux/total)](https://github.com/selfcustody/krux/releases) [![downloads (latest release)](https://img.shields.io/github/downloads/selfcustody/krux/latest/total)](https://github.com/selfcustody/krux/releases) -[![commits (since latest release)](https://img.shields.io/github/commits-since/selfcustody/krux/latest/develop)](https://github.com/selfcustody/krux/compare/main...develop) +[![contributors](https://img.shields.io/github/contributors-anon/selfcustody/krux)](https://github.com/selfcustody/krux/graphs/contributors) +[![commit activity](https://img.shields.io/github/commit-activity/y/selfcustody/krux)](https://github.com/selfcustody/krux/commits) [![codecov](https://codecov.io/gh/selfcustody/krux/branch/main/graph/badge.svg?token=XU80PT6Q9V)](https://codecov.io/gh/selfcustody/krux) [![calver](https://img.shields.io/badge/calver-YY.0M.MICRO-22bfda.svg)](https://calver.org) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/selfcustody/krux/blob/main/LICENSE.md) From 9354cb9d1ce9b6240eb7aedef413c9f6de57e456 Mon Sep 17 00:00:00 2001 From: tadeubas Date: Sun, 21 Jul 2024 18:14:33 -0300 Subject: [PATCH 2/2] back label refactor --- src/krux/pages/__init__.py | 21 +++++++++++--------- src/krux/pages/encryption_ui.py | 4 +--- src/krux/pages/file_manager.py | 7 +++---- src/krux/pages/home_pages/addresses.py | 4 ---- src/krux/pages/home_pages/home.py | 6 ++---- src/krux/pages/home_pages/mnemonic_backup.py | 5 ----- src/krux/pages/home_pages/pub_key_view.py | 3 --- src/krux/pages/home_pages/sign_message_ui.py | 4 ++-- src/krux/pages/login.py | 8 +------- src/krux/pages/new_mnemonic/dice_rolls.py | 1 + src/krux/pages/qr_view.py | 8 +++----- src/krux/pages/settings_page.py | 8 +++----- src/krux/pages/tools.py | 2 -- src/krux/pages/wallet_settings.py | 6 +++--- tests/pages/test_menu.py | 2 ++ 15 files changed, 33 insertions(+), 56 deletions(-) diff --git a/src/krux/pages/__init__.py b/src/krux/pages/__init__.py index dc94d44f..e87f4b4e 100644 --- a/src/krux/pages/__init__.py +++ b/src/krux/pages/__init__.py @@ -108,8 +108,8 @@ def load_method(self): t("Load from SD card"), None if not self.has_sd_card() else lambda: None, ), - cta_back(lambda: None), ], + back_status=lambda: None, ) index, _ = load_menu.run_loop() return index @@ -569,9 +569,17 @@ class Menu: and invoke menu item callbacks that return a status """ - def __init__(self, ctx, menu, offset=None, disable_statusbar=False): + def __init__( + self, + ctx, + menu, + offset=None, + disable_statusbar=False, + back_label=t("Back"), + back_status=lambda: MENU_EXIT, + ): self.ctx = ctx - self.menu = menu + self.menu = menu + [("< " + back_label, back_status)] if back_label else menu self.disable_statusbar = disable_statusbar if offset is None: # Default offset for status bar @@ -907,14 +915,9 @@ def choose_len_mnemonic(ctx): [ (t("12 words"), lambda: 12), (t("24 words"), lambda: 24), - cta_back(lambda: None), ], + back_status=lambda: None, ) _, num_words = submenu.run_loop() ctx.display.clear() return num_words - - -def cta_back(status=lambda: MENU_EXIT, label=t("Back")): - """Reusable 'call-to-action: go back'. Currently a menu item tuple""" - return ("< " + label, status) diff --git a/src/krux/pages/encryption_ui.py b/src/krux/pages/encryption_ui.py index 8c73803a..1ac57062 100644 --- a/src/krux/pages/encryption_ui.py +++ b/src/krux/pages/encryption_ui.py @@ -27,7 +27,6 @@ Page, Menu, MENU_CONTINUE, - MENU_EXIT, ESC_KEY, LETTERS, UPPERCASE_LETTERS, @@ -53,6 +52,7 @@ def encryption_key(self): (t("Type Key"), self.load_key), (t("Scan Key QR Code"), self.load_qr_encryption_key), ], + back_label=None, ) _, key = submenu.run_loop() if key in (ESC_KEY, MENU_CONTINUE): @@ -108,7 +108,6 @@ def encrypt_menu(self): ), ), (t("Encrypted QR Code"), self.encrypted_qr_code), - (t("Back"), lambda: MENU_EXIT), ] submenu = Menu(self.ctx, encrypt_outputs_menu) _, _ = submenu.run_loop() @@ -254,7 +253,6 @@ def load_from_storage(self, remove_opt=False): ), ) ) - mnemonic_ids_menu.append((t("Back"), lambda: MENU_EXIT)) submenu = Menu(self.ctx, mnemonic_ids_menu) index, status = submenu.run_loop() if index == len(submenu.menu) - 1: diff --git a/src/krux/pages/file_manager.py b/src/krux/pages/file_manager.py index a42c4628..b2b714ae 100644 --- a/src/krux/pages/file_manager.py +++ b/src/krux/pages/file_manager.py @@ -22,7 +22,7 @@ import board import gc -from . import Page, Menu, MENU_EXIT, MENU_CONTINUE, cta_back +from . import Page, Menu, MENU_EXIT, MENU_CONTINUE from ..sd_card import SDHandler from ..krux_settings import t from ..format import generate_thousands_separator, render_decimal_separator @@ -56,8 +56,8 @@ def select_file( while True: # if is a dir then list all files in it if SDHandler.dir_exists(path): - items = [] - menu_items = [] + items = [] # simple reference for the files shown on the menu_items + menu_items = [] # the user menu to interact if path != SD_ROOT_PATH: items.append("..") @@ -115,7 +115,6 @@ def select_file( # We need to add this option because /sd can be empty! items.append("Back") - menu_items.append(cta_back()) submenu = Menu(self.ctx, menu_items) index, _ = submenu.run_loop() diff --git a/src/krux/pages/home_pages/addresses.py b/src/krux/pages/home_pages/addresses.py index 55dc3982..7f166603 100644 --- a/src/krux/pages/home_pages/addresses.py +++ b/src/krux/pages/home_pages/addresses.py @@ -29,7 +29,6 @@ Menu, MENU_CONTINUE, MENU_EXIT, - cta_back, ) SCAN_ADDRESS_LIMIT = 50 @@ -51,7 +50,6 @@ def addresses_menu(self): (t("Scan Address"), self.pre_scan_address), (t("Receive Addresses"), self.list_address_type), (t("Change Addresses"), lambda: self.list_address_type(1)), - cta_back(), ], ) submenu.run_loop() @@ -103,7 +101,6 @@ def list_address_type(self, addr_type=0): lambda: MENU_EXIT, ) ) - items.append(cta_back()) submenu = Menu(self.ctx, items) stay_on_this_addr_menu = True @@ -138,7 +135,6 @@ def pre_scan_address(self): [ (t("Receive"), self.scan_address), (t("Change"), lambda: self.scan_address(1)), - cta_back(), ], ) submenu.run_loop() diff --git a/src/krux/pages/home_pages/home.py b/src/krux/pages/home_pages/home.py index 44bbe376..017eae2a 100644 --- a/src/krux/pages/home_pages/home.py +++ b/src/krux/pages/home_pages/home.py @@ -32,7 +32,6 @@ ESC_KEY, LOAD_FROM_CAMERA, LOAD_FROM_SD, - cta_back, ) MAX_POLICY_COSIGNERS_DISPLAYED = 5 @@ -61,6 +60,7 @@ def __init__(self, ctx): (t("Sign"), self.sign), (t("Shutdown"), self.shutdown), ], + back_label=None, ), ) @@ -169,7 +169,6 @@ def wallet(self): (t("Passphrase"), self.passphrase), (t("Customize"), self.customize), ("BIP85", self.bip85), - cta_back(), ], ) submenu.run_loop() @@ -189,7 +188,6 @@ def sign(self): [ ("PSBT", self.sign_psbt), (t("Message"), self.sign_message), - cta_back(), ], ) index, status = submenu.run_loop() @@ -228,8 +226,8 @@ def _sign_menu(self): t("Sign to SD card"), None if not self.has_sd_card() else lambda: None, ), - cta_back(lambda: None), ], + back_status=lambda: None, ) index, _ = sign_menu.run_loop() return index diff --git a/src/krux/pages/home_pages/mnemonic_backup.py b/src/krux/pages/home_pages/mnemonic_backup.py index 1bddccfb..6d9db11b 100644 --- a/src/krux/pages/home_pages/mnemonic_backup.py +++ b/src/krux/pages/home_pages/mnemonic_backup.py @@ -27,7 +27,6 @@ Page, Menu, MENU_CONTINUE, - cta_back, ) @@ -42,7 +41,6 @@ def mnemonic(self): (t("QR Code"), self.qr_code_backup), (t("Encrypted"), self.encrypt_mnemonic_menu), (t("Other Formats"), self.other_backup_formats), - cta_back(), ], ) submenu.run_loop() @@ -57,7 +55,6 @@ def qr_code_backup(self): ("Compact SeedQR", lambda: self.display_seed_qr(True)), ("SeedQR", self.display_seed_qr), (t("Encrypted QR Code"), self.encrypt_qr_code), - cta_back(), ], ) submenu.run_loop() @@ -77,7 +74,6 @@ def other_backup_formats(self): (t("Numbers"), self.display_mnemonic_numbers), ("Stackbit 1248", self.stackbit), ("Tiny Seed", self.tiny_seed), - cta_back(), ], ) submenu.run_loop() @@ -149,7 +145,6 @@ def display_mnemonic_numbers(self): Utils.BASE_OCT_SUFFIX, ), ), - cta_back(), ], ) submenu.run_loop() diff --git a/src/krux/pages/home_pages/pub_key_view.py b/src/krux/pages/home_pages/pub_key_view.py index 4e908abb..ca668a99 100644 --- a/src/krux/pages/home_pages/pub_key_view.py +++ b/src/krux/pages/home_pages/pub_key_view.py @@ -27,7 +27,6 @@ Menu, MENU_CONTINUE, MENU_EXIT, - cta_back, ) from ...sd_card import PUBKEY_FILE_EXTENSION from ...key import P2SH_P2WPKH, P2SH_P2WSH, P2WPKH, P2WSH @@ -69,7 +68,6 @@ def _pub_key_text(version): else lambda: _save_xpub_to_sd(version) ), ), - cta_back(), ] full_pub_key = self.ctx.wallet.key.account_pubkey_str(version) menu_offset = 5 + len(self.ctx.display.to_lines(full_pub_key)) @@ -117,7 +115,6 @@ def _pub_key_qr(version): pub_key_menu_items.append( (title + " - " + t("QR Code"), lambda ver=version: _pub_key_qr(ver)) ) - pub_key_menu_items.append(cta_back()) pub_key_menu = Menu(self.ctx, pub_key_menu_items) while True: _, status = pub_key_menu.run_loop() diff --git a/src/krux/pages/home_pages/sign_message_ui.py b/src/krux/pages/home_pages/sign_message_ui.py index 8c0af5cb..88bde2b7 100644 --- a/src/krux/pages/home_pages/sign_message_ui.py +++ b/src/krux/pages/home_pages/sign_message_ui.py @@ -24,7 +24,7 @@ from embit import bip32, compact import hashlib import binascii -from .. import MENU_CONTINUE, LOAD_FROM_CAMERA, LOAD_FROM_SD, Menu, cta_back +from .. import MENU_CONTINUE, LOAD_FROM_CAMERA, LOAD_FROM_SD, Menu from ...themes import theme from ...display import ( DEFAULT_PADDING, @@ -199,8 +199,8 @@ def sign_message(self): t("Sign to SD card"), None if not self.has_sd_card() else lambda: None, ), - cta_back(lambda: None), ], + back_status=lambda: None, ) index, _ = sign_menu.run_loop() diff --git a/src/krux/pages/login.py b/src/krux/pages/login.py index 38a05a35..8260a5c2 100644 --- a/src/krux/pages/login.py +++ b/src/krux/pages/login.py @@ -37,7 +37,6 @@ ESC_KEY, LETTERS, choose_len_mnemonic, - cta_back, ) DIGITS = "0123456789" @@ -64,6 +63,7 @@ def __init__(self, ctx): (t("About"), self.about), (t("Shutdown"), self.shutdown), ], + back_label=None, ), ) @@ -75,7 +75,6 @@ def load_key(self): (t("Via Camera"), self.load_key_from_camera), (t("Via Manual Input"), self.load_key_from_manual_input), (t("From Storage"), self.load_mnemonic_from_storage), - cta_back(), ], ) index, status = submenu.run_loop() @@ -93,7 +92,6 @@ def load_key_from_camera(self): "Tiny Seed", self.load_key_from_tiny_seed_image, ), - cta_back(), ], ) index, status = submenu.run_loop() @@ -110,7 +108,6 @@ def load_key_from_manual_input(self): (t("Word Numbers"), self.pre_load_key_from_digits), ("Tiny Seed (Bits)", self.load_key_from_tiny_seed), ("Stackbit 1248", self.load_key_from_1248), - cta_back(), ], ) index, status = submenu.run_loop() @@ -137,7 +134,6 @@ def new_key(self): (t("Via Words"), lambda: self.load_key_from_text(new=True)), (t("Via D6"), self.new_key_from_dice), (t("Via D20"), lambda: self.new_key_from_dice(True)), - cta_back(), ], ) index, status = submenu.run_loop() @@ -245,7 +241,6 @@ def _load_key_from_words(self, words, charset=LETTERS): (t("Load Wallet"), lambda: None), (t("Passphrase"), lambda: None), (t("Customize"), lambda: None), - cta_back(), ], offset=info_len * FONT_HEIGHT + DEFAULT_PADDING, ) @@ -552,7 +547,6 @@ def pre_load_key_from_digits(self): (t("Decimal"), self.load_key_from_digits), (t("Hexadecimal"), self.load_key_from_hexadecimal), (t("Octal"), self.load_key_from_octal), - cta_back(), ], ) index, status = submenu.run_loop() diff --git a/src/krux/pages/new_mnemonic/dice_rolls.py b/src/krux/pages/new_mnemonic/dice_rolls.py index 38ce4a9d..0a74cfbd 100644 --- a/src/krux/pages/new_mnemonic/dice_rolls.py +++ b/src/krux/pages/new_mnemonic/dice_rolls.py @@ -309,6 +309,7 @@ def delete_roll(buffer): (t("Generate Mnemonic"), lambda: MENU_EXIT), ], offset=menu_offset, + back_label=None, ) index, _ = submenu.run_loop() if index == 0: diff --git a/src/krux/pages/qr_view.py b/src/krux/pages/qr_view.py index bb0e456f..53725da8 100644 --- a/src/krux/pages/qr_view.py +++ b/src/krux/pages/qr_view.py @@ -22,7 +22,7 @@ import qrcode from embit.wordlists.bip39 import WORDLIST -from . import Page, Menu, MENU_CONTINUE, MENU_EXIT, ESC_KEY, cta_back +from . import Page, Menu, MENU_CONTINUE, MENU_EXIT, ESC_KEY from ..themes import theme, WHITE, BLACK from ..krux_settings import t from ..qr import get_size @@ -414,8 +414,7 @@ def save_qr_image_menu(self): ), ) ) - qr_menu.append(cta_back()) - submenu = Menu(self.ctx, qr_menu, offset=2 * FONT_HEIGHT) + submenu = Menu(self.ctx, qr_menu, offset=2 * FONT_HEIGHT, back_label=None) submenu.run_loop() return MENU_CONTINUE # return MENU_EXIT # Use this to exit QR Viewer after saving @@ -487,9 +486,8 @@ def toggle_brightness(): ), ), (t("Print to QR"), printer_func), - cta_back(label=t("Back to Menu")), ] - submenu = Menu(self.ctx, qr_menu) + submenu = Menu(self.ctx, qr_menu, back_label=t("Back to Menu")) _, status = submenu.run_loop() if status == MENU_EXIT: return MENU_CONTINUE diff --git a/src/krux/pages/settings_page.py b/src/krux/pages/settings_page.py index 6f726f4a..519b3b83 100644 --- a/src/krux/pages/settings_page.py +++ b/src/krux/pages/settings_page.py @@ -51,7 +51,6 @@ MENU_EXIT, ESC_KEY, DEFAULT_PADDING, - cta_back, ) import os @@ -231,14 +230,13 @@ def handler(): if len(items) == 1: return items[0][1]() + back_status = lambda: MENU_EXIT # pylint: disable=C3001 # Case for "Back" on the main Settings if settings_namespace.namespace == Settings.namespace: items.append((t("Factory Settings"), self.restore_settings)) - items.append(cta_back(self._settings_exit_check)) - else: - items.append(cta_back()) + back_status = self._settings_exit_check - submenu = Menu(self.ctx, items) + submenu = Menu(self.ctx, items, back_status=back_status) index, status = submenu.run_loop() if index == len(submenu.menu) - 1: return MENU_CONTINUE diff --git a/src/krux/pages/tools.py b/src/krux/pages/tools.py index 82edbe3a..4507d416 100644 --- a/src/krux/pages/tools.py +++ b/src/krux/pages/tools.py @@ -34,7 +34,6 @@ UPPERCASE_LETTERS, NUM_SPECIAL_1, NUM_SPECIAL_2, - cta_back, ) from .file_manager import SD_ROOT_PATH from ..format import generate_thousands_separator @@ -55,7 +54,6 @@ def __init__(self, ctx): (t("Descriptor Addresses"), self.descriptor_addresses), (t("Remove Mnemonic"), self.rm_stored_mnemonic), (t("Wipe Device"), self.wipe_device), - cta_back(), ], ), ) diff --git a/src/krux/pages/wallet_settings.py b/src/krux/pages/wallet_settings.py index 2db11e78..62eccda3 100644 --- a/src/krux/pages/wallet_settings.py +++ b/src/krux/pages/wallet_settings.py @@ -34,7 +34,6 @@ UPPERCASE_LETTERS, NUM_SPECIAL_1, NUM_SPECIAL_2, - cta_back, ) from .settings_page import DIGITS from ..key import SINGLESIG_SCRIPT_PURPOSE, MULTISIG_SCRIPT_PURPOSE @@ -63,7 +62,6 @@ def load_passphrase_menu(self): [ (t("Type BIP39 Passphrase"), self._load_passphrase), (t("Scan BIP39 Passphrase"), self._load_qr_passphrase), - cta_back(), ], disable_statusbar=True, ) @@ -135,7 +133,6 @@ def customize_wallet(self, key): ("Single/Multisig", lambda: None), (t("Script Type"), (lambda: None) if not multisig else None), (t("Account"), lambda: None), - cta_back(), ], offset=info_len * FONT_HEIGHT + DEFAULT_PADDING, ) @@ -168,6 +165,7 @@ def _coin_type(self): ("Testnet", lambda: None), ], disable_statusbar=True, + back_label=None, ) index, _ = submenu.run_loop() return NETWORKS[TEST_TXT] if index == 1 else NETWORKS[MAIN_TXT] @@ -181,6 +179,7 @@ def _multisig(self): (t("Multisig"), lambda: MENU_EXIT), ], disable_statusbar=True, + back_label=None, ) index, _ = submenu.run_loop() return index == 1 @@ -196,6 +195,7 @@ def _script_type(self): ("Taproot - 86 (Experimental)", lambda: P2TR), ], disable_statusbar=True, + back_label=None, ) _, script_type = submenu.run_loop() return script_type diff --git a/tests/pages/test_menu.py b/tests/pages/test_menu.py index 8675dd3d..da1a0c50 100644 --- a/tests/pages/test_menu.py +++ b/tests/pages/test_menu.py @@ -29,6 +29,7 @@ def exception_raiser(): ("Longer Option", lambda: MENU_SHUTDOWN), ("The Longest Option", exception_raiser), ], + back_label=None, ) ctx.input.wait_for_button.side_effect = [BUTTON_ENTER, BUTTON_PAGE, BUTTON_ENTER] @@ -79,6 +80,7 @@ def exception_raiser(): ("Longer Option", lambda: MENU_SHUTDOWN), ("The Longest Option", exception_raiser), ], + back_label=None, ) ctx.input.wait_for_button.side_effect = [