mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-11 07:50:57 +00:00
core/management: fix word check, add icons to checklist
This commit is contained in:
parent
10e5ec6135
commit
a4039f9459
@ -245,7 +245,6 @@ async def slip39_show_checklist_set_shares(ctx):
|
||||
checklist.add("Set the threshold")
|
||||
checklist.add(("Write down and check", "all backup shares"))
|
||||
checklist.select(0)
|
||||
checklist.process()
|
||||
return await confirm(
|
||||
ctx,
|
||||
checklist,
|
||||
@ -261,7 +260,6 @@ async def slip39_show_checklist_set_threshold(ctx, num_of_shares):
|
||||
checklist.add("Set the threshold")
|
||||
checklist.add(("Write down and check", "all backup shares"))
|
||||
checklist.select(1)
|
||||
checklist.process()
|
||||
return await confirm(
|
||||
ctx,
|
||||
checklist,
|
||||
@ -277,7 +275,6 @@ async def slip39_show_checklist_show_shares(ctx, num_of_shares, threshold):
|
||||
checklist.add("Set the threshold")
|
||||
checklist.add(("Write down and check", "all backup shares"))
|
||||
checklist.select(2)
|
||||
checklist.process()
|
||||
return await confirm(
|
||||
ctx,
|
||||
checklist,
|
||||
@ -395,7 +392,6 @@ async def _slip39_show_share_words(ctx, share_index, share_words):
|
||||
# middle pages
|
||||
for chunk in chunks:
|
||||
text = Text(header_title, header_icon)
|
||||
text.br_half()
|
||||
for index, word in chunk:
|
||||
text.mono("%s. %s" % (index + 1, word))
|
||||
shares_words_check.append(word)
|
||||
@ -503,14 +499,11 @@ class ShamirNumInput(ui.Control):
|
||||
|
||||
class MnemonicWordSelect(ui.Layout):
|
||||
NUM_OF_CHOICES = 3
|
||||
MODE_CHECK = object()
|
||||
MODE_RECOVERY = object()
|
||||
|
||||
def __init__(self, words, share_index, word_index, mode):
|
||||
def __init__(self, words, share_index, word_index):
|
||||
self.words = words
|
||||
self.share_index = share_index
|
||||
self.word_index = word_index
|
||||
self.mode = mode
|
||||
self.buttons = []
|
||||
for i, word in enumerate(words):
|
||||
area = ui.grid(i + 2, n_x=1)
|
||||
@ -518,15 +511,9 @@ class MnemonicWordSelect(ui.Layout):
|
||||
btn.on_click = self.select(word)
|
||||
self.buttons.append(btn)
|
||||
if share_index is None:
|
||||
if self.mode is MnemonicWordSelect.MODE_CHECK:
|
||||
self.text = Text("Check seed")
|
||||
else: # self.mode is MnemonicWordSelect.MODE_RECOVERY
|
||||
self.text = Text("Recovery seed")
|
||||
self.text = Text("Check seed")
|
||||
else:
|
||||
if self.mode is MnemonicWordSelect.MODE_CHECK:
|
||||
self.text = Text("Check share #%s" % (share_index + 1))
|
||||
else: # self.mode is MnemonicWordSelect.MODE_RECOVERY
|
||||
self.text = Text("Recovery share #%s" % (share_index + 1))
|
||||
self.text = Text("Check share #%s" % (share_index + 1))
|
||||
self.text.normal("Choose the %s word:" % utils.format_ordinal(word_index + 1))
|
||||
|
||||
def dispatch(self, event, x, y):
|
||||
|
@ -1,55 +1,59 @@
|
||||
from micropython import const
|
||||
|
||||
from trezor import ui
|
||||
from trezor.ui import text
|
||||
from trezor import res, ui
|
||||
from trezor.ui.text import TEXT_HEADER_HEIGHT, TEXT_LINE_HEIGHT
|
||||
|
||||
_CHECKLIST_MAX_LINES = const(5)
|
||||
_CHECKLIST_OFFSET_X = const(24)
|
||||
_CHECKLIST_OFFSET_X_ICON = const(0)
|
||||
|
||||
|
||||
class Checklist(ui.Control):
|
||||
def __init__(self, title, icon):
|
||||
self.title = title
|
||||
self.icon = icon
|
||||
self.choices = []
|
||||
self.words = []
|
||||
self.items = []
|
||||
self.active = 0
|
||||
self.repaint = False
|
||||
self.repaint = True
|
||||
|
||||
def add(self, choice):
|
||||
self.choices.append(choice)
|
||||
self.items.append(choice)
|
||||
|
||||
def select(self, active):
|
||||
self.active = active
|
||||
|
||||
def process(self):
|
||||
w = self.words
|
||||
w.clear()
|
||||
for index, choice in enumerate(self.choices):
|
||||
if index < self.active:
|
||||
w.append(ui.BOLD)
|
||||
w.append(ui.GREEN)
|
||||
elif index == self.active:
|
||||
w.append(ui.BOLD)
|
||||
w.append(ui.FG)
|
||||
else: # index > self.active
|
||||
w.append(ui.NORMAL)
|
||||
w.append(ui.GREY)
|
||||
if isinstance(choice, str):
|
||||
w.append(choice)
|
||||
else: # choice is iterable
|
||||
w.extend(choice)
|
||||
w.append(text.BR)
|
||||
self.words = w
|
||||
self.repaint = True
|
||||
|
||||
def on_render(self):
|
||||
if self.repaint:
|
||||
ui.header(self.title, self.icon)
|
||||
text.render_text(
|
||||
self.words,
|
||||
new_lines=False, # we are adding line breaks manually
|
||||
max_lines=_CHECKLIST_MAX_LINES,
|
||||
offset_x=_CHECKLIST_OFFSET_X,
|
||||
)
|
||||
self.render_items()
|
||||
self.repaint = False
|
||||
|
||||
def render_items(self):
|
||||
offset_x = _CHECKLIST_OFFSET_X
|
||||
offset_y = TEXT_HEADER_HEIGHT + TEXT_LINE_HEIGHT
|
||||
bg = ui.BG
|
||||
|
||||
for index, item in enumerate(self.items):
|
||||
# compute font and color
|
||||
if index < self.active:
|
||||
font = ui.BOLD
|
||||
fg = ui.GREEN
|
||||
elif index == self.active:
|
||||
font = ui.BOLD
|
||||
fg = ui.FG
|
||||
else: # index > self.active
|
||||
font = ui.NORMAL
|
||||
fg = ui.GREY
|
||||
|
||||
# render item icon
|
||||
icon = res.load(ui.ICON_CONFIRM)
|
||||
ui.display.icon(0, offset_y - 14, icon, fg, bg)
|
||||
|
||||
# render item text
|
||||
if isinstance(item, str):
|
||||
ui.display.text(offset_x, offset_y, item, font, fg, bg)
|
||||
offset_y += TEXT_LINE_HEIGHT
|
||||
else:
|
||||
for line in item:
|
||||
ui.display.text(offset_x, offset_y, line, font, fg, bg)
|
||||
offset_y += TEXT_LINE_HEIGHT
|
||||
|
Loading…
Reference in New Issue
Block a user