mirror of
https://github.com/SeedSigner/seedsigner.git
synced 2026-10-06 07:28:24 +00:00
Various improvements
This commit is contained in:
@@ -289,7 +289,9 @@ class TextArea(BaseComponent):
|
||||
# fits in its bounding rect (plus accounting for edge padding) using its given
|
||||
# font.
|
||||
# Measure from left baseline ("ls")
|
||||
# getbbox() seems to ignore "\n" so won't affect height calcs
|
||||
# TODO: getbbox() seems to ignore "\n" so isn't properly factored into height
|
||||
# calcs and yields incorrect full_text_width. For now must specify self.height to
|
||||
# render properly. Centering will be wrong.
|
||||
(left, top, full_text_width, bottom) = self.font.getbbox(self.text, anchor="ls")
|
||||
self.text_font_height = -1 * top
|
||||
self.bbox_height = self.text_font_height + bottom
|
||||
|
||||
@@ -261,6 +261,24 @@ class ToolsDiceEntropyEntryScreen(BaseTopNavScreen):
|
||||
|
||||
|
||||
|
||||
@dataclass
|
||||
class ToolsCalcFinalWordFinalizePromptScreen(ButtonListScreen):
|
||||
mnemonic_length: int = None
|
||||
num_entropy_bits: int = None
|
||||
|
||||
def __post_init__(self):
|
||||
self.title = "Build Final Word"
|
||||
self.is_bottom_list = True
|
||||
self.is_button_text_centered = True
|
||||
super().__post_init__()
|
||||
|
||||
self.components.append(TextArea(
|
||||
text=f"The {self.mnemonic_length}th word is built from {self.num_entropy_bits} more entropy bits plus auto-calculated checksum.",
|
||||
screen_y=self.top_nav.height + GUIConstants.COMPONENT_PADDING,
|
||||
))
|
||||
|
||||
|
||||
|
||||
@dataclass
|
||||
class ToolsCoinFlipEntryScreen(BaseTopNavScreen):
|
||||
"""
|
||||
@@ -285,7 +303,7 @@ class ToolsCoinFlipEntryScreen(BaseTopNavScreen):
|
||||
button_height = int(1.5*GUIConstants.BUTTON_FONT_SIZE + 2*GUIConstants.EDGE_PADDING)
|
||||
self.keyboard_digits = Keyboard(
|
||||
draw=self.renderer.draw,
|
||||
charset="01",
|
||||
charset="10",
|
||||
font_size=button_height - GUIConstants.COMPONENT_PADDING,
|
||||
rows=rows,
|
||||
cols=4,
|
||||
@@ -298,7 +316,7 @@ class ToolsCoinFlipEntryScreen(BaseTopNavScreen):
|
||||
auto_wrap=[Keyboard.WRAP_LEFT, Keyboard.WRAP_RIGHT],
|
||||
render_now=False
|
||||
)
|
||||
self.keyboard_digits.set_selected_key(selected_letter="0")
|
||||
self.keyboard_digits.set_selected_key(selected_letter="1")
|
||||
|
||||
self.text_entry_display = TextEntryDisplay(
|
||||
canvas=self.renderer.canvas,
|
||||
@@ -312,6 +330,15 @@ class ToolsCoinFlipEntryScreen(BaseTopNavScreen):
|
||||
is_centered=False,
|
||||
)
|
||||
|
||||
self.components.append(TextArea(
|
||||
text="Heads = 1",
|
||||
screen_y = keyboard_start_y + self.keyboard_digits.height + 4*GUIConstants.COMPONENT_PADDING,
|
||||
))
|
||||
self.components.append(TextArea(
|
||||
text="Tails = 0",
|
||||
screen_y = self.components[-1].screen_y + self.components[-1].height + GUIConstants.COMPONENT_PADDING,
|
||||
))
|
||||
|
||||
|
||||
def _render(self):
|
||||
super()._render()
|
||||
@@ -371,6 +398,7 @@ class ToolsCoinFlipEntryScreen(BaseTopNavScreen):
|
||||
cursor_position += 1
|
||||
|
||||
if cursor_position == self.total_flips:
|
||||
# Return results as a binary string
|
||||
return self.coin_flips
|
||||
|
||||
# Render a new TextArea over the TopNav title bar
|
||||
@@ -426,7 +454,7 @@ class ToolsCalcFinalWordScreen(ButtonListScreen):
|
||||
discard_selected_bits = "_" * (len(self.checksum_bits))
|
||||
|
||||
self.components.append(TextArea(
|
||||
text=f"""Your Selection: \"{selection_text}\"""",
|
||||
text=f"""Your input: \"{selection_text}\"""",
|
||||
screen_y=self.top_nav.height,
|
||||
))
|
||||
|
||||
|
||||
@@ -127,13 +127,14 @@ class SeedMnemonicEntryView(View):
|
||||
|
||||
if ret == RET_CODE__BACK_BUTTON:
|
||||
if self.cur_word_index > 0:
|
||||
return Destination(
|
||||
SeedMnemonicEntryView,
|
||||
view_args={
|
||||
"cur_word_index": self.cur_word_index - 1,
|
||||
"is_calc_final_word": self.is_calc_final_word
|
||||
}
|
||||
)
|
||||
return Destination(BackStackView)
|
||||
# return Destination(
|
||||
# SeedMnemonicEntryView,
|
||||
# view_args={
|
||||
# "cur_word_index": self.cur_word_index - 1,
|
||||
# "is_calc_final_word": self.is_calc_final_word
|
||||
# }
|
||||
# )
|
||||
else:
|
||||
self.controller.storage.discard_pending_mnemonic()
|
||||
return Destination(MainMenuView)
|
||||
@@ -142,10 +143,10 @@ class SeedMnemonicEntryView(View):
|
||||
self.controller.storage.update_pending_mnemonic(ret, self.cur_word_index)
|
||||
|
||||
if self.is_calc_final_word and self.cur_word_index == self.controller.storage.pending_mnemonic_length - 2:
|
||||
# Time to calculate the last word. User must either select a final word to
|
||||
# contribute entropy to the checksum word OR we assume 0 ("abandon").
|
||||
from seedsigner.views.tools_views import ToolsCalcFinalWordSelectFinalWordPromptView
|
||||
return Destination(ToolsCalcFinalWordSelectFinalWordPromptView)
|
||||
# Time to calculate the last word. User must decide how they want to specify
|
||||
# the last bits of entropy for the final word.
|
||||
from seedsigner.views.tools_views import ToolsCalcFinalWordFinalizePromptView
|
||||
return Destination(ToolsCalcFinalWordFinalizePromptView)
|
||||
|
||||
if self.is_calc_final_word and self.cur_word_index == self.controller.storage.pending_mnemonic_length - 1:
|
||||
# Time to calculate the last word. User must either select a final word to
|
||||
|
||||
@@ -8,7 +8,7 @@ from PIL.ImageOps import autocontrast
|
||||
from seedsigner.hardware.camera import Camera
|
||||
from seedsigner.gui.components import FontAwesomeIconConstants
|
||||
from seedsigner.gui.screens import (RET_CODE__BACK_BUTTON, ButtonListScreen)
|
||||
from seedsigner.gui.screens.tools_screens import ToolsCalcFinalWordScreen, ToolsCoinFlipEntryScreen, ToolsDiceEntropyEntryScreen, ToolsImageEntropyFinalImageScreen, ToolsImageEntropyLivePreviewScreen, ToolsCalcFinalWordDoneScreen
|
||||
from seedsigner.gui.screens.tools_screens import ToolsCalcFinalWordFinalizePromptScreen, ToolsCalcFinalWordScreen, ToolsCoinFlipEntryScreen, ToolsDiceEntropyEntryScreen, ToolsImageEntropyFinalImageScreen, ToolsImageEntropyLivePreviewScreen, ToolsCalcFinalWordDoneScreen
|
||||
from seedsigner.helpers import mnemonic_generation
|
||||
from seedsigner.models.seed import Seed
|
||||
from seedsigner.models.settings_definition import SettingsConstants
|
||||
@@ -260,20 +260,24 @@ class ToolsCalcFinalWordNumWordsView(View):
|
||||
|
||||
|
||||
|
||||
class ToolsCalcFinalWordSelectFinalWordPromptView(View):
|
||||
class ToolsCalcFinalWordFinalizePromptView(View):
|
||||
def run(self):
|
||||
mnemonic = self.controller.storage.pending_mnemonic
|
||||
mnemonic_length = len(mnemonic)
|
||||
COIN_FLIPS = "Finalize w/coin flips"
|
||||
SELECT_WORD = f"Finalize w/{mnemonic_length}th word"
|
||||
ZEROS = "Finalize w/zeros"
|
||||
if mnemonic_length == 12:
|
||||
num_entropy_bits = 7
|
||||
else:
|
||||
num_entropy_bits = 3
|
||||
|
||||
COIN_FLIPS = "Coin flip entropy"
|
||||
SELECT_WORD = f"Word selection entropy"
|
||||
ZEROS = "Finalize with zeros"
|
||||
|
||||
button_data = [COIN_FLIPS, SELECT_WORD, ZEROS]
|
||||
selected_menu_num = ButtonListScreen(
|
||||
title=f"{mnemonic_length}th Word",
|
||||
selected_menu_num = ToolsCalcFinalWordFinalizePromptScreen(
|
||||
mnemonic_length=mnemonic_length,
|
||||
num_entropy_bits=num_entropy_bits,
|
||||
button_data=button_data,
|
||||
is_bottom_list=True,
|
||||
is_button_text_centered=True,
|
||||
).display()
|
||||
|
||||
if selected_menu_num == RET_CODE__BACK_BUTTON:
|
||||
@@ -283,18 +287,16 @@ class ToolsCalcFinalWordSelectFinalWordPromptView(View):
|
||||
return Destination(ToolsCalcFinalWordCoinFlipsView)
|
||||
|
||||
elif button_data[selected_menu_num] == SELECT_WORD:
|
||||
# Clear the final word slot, just in case we're returning via BACK button
|
||||
self.controller.storage.update_pending_mnemonic(None, mnemonic_length - 1)
|
||||
return Destination(SeedMnemonicEntryView, view_args=dict(is_calc_final_word=True, cur_word_index=mnemonic_length - 1))
|
||||
|
||||
elif button_data[selected_menu_num] == ZEROS:
|
||||
# User skipped the option to select a final word to provide last bits of
|
||||
# entropy. We'll insert all zeros and piggy-back on the coin flip attr
|
||||
if mnemonic_length == 12:
|
||||
total_flips = 7
|
||||
else:
|
||||
total_flips = 3
|
||||
wordlist_language_code = self.settings.get_value(SettingsConstants.SETTING__WORDLIST_LANGUAGE)
|
||||
self.controller.storage.update_pending_mnemonic(Seed.get_wordlist(wordlist_language_code)[0], mnemonic_length - 1)
|
||||
return Destination(ToolsCalcFinalWordShowFinalWordView, view_args=dict(coin_flips="0" * total_flips))
|
||||
return Destination(ToolsCalcFinalWordShowFinalWordView, view_args=dict(coin_flips="0" * num_entropy_bits))
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user