Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def on_render(self) -> None:
if not self.repaint:
return
image = None
if not storage.is_initialized():
label = "Go to trezor.io/start"
else:
label = storage.device.get_label() or "My Trezor"
image = storage.device.get_homescreen()
if not image:
image = res.load("apps/homescreen/res/bg.toif")
if storage.is_initialized() and storage.device.no_backup():
ui.header_error("SEEDLESS")
elif storage.is_initialized() and storage.device.unfinished_backup():
ui.header_error("BACKUP FAILED!")
elif storage.is_initialized() and storage.device.needs_backup():
ui.header_warning("NEEDS BACKUP!")
elif storage.is_initialized() and not config.has_pin():
ui.header_warning("PIN NOT SET!")
else:
ui.display.bar(0, 0, ui.WIDTH, ui.HEIGHT, ui.BG)
ui.display.avatar(48, 48 - 10, image, ui.WHITE, ui.BLACK)
ui.display.text_center(ui.WIDTH // 2, 220, label, ui.BOLD, ui.FG, ui.BG)
self.repaint = False
async def display_homescreen():
from apps.common import storage
if not storage.is_initialized():
label = 'Open trezor.io/start'
image = None
else:
label = storage.get_label() or 'My TREZOR'
image = storage.get_homescreen()
if not image:
image = res.load('apps/homescreen/res/homescreen.toif')
ui.display.bar(0, 0, ui.SCREEN, ui.SCREEN, ui.BG)
ui.display.avatar((ui.SCREEN - 144) // 2, (ui.SCREEN - 144) // 2 - 10, image, ui.WHITE, ui.BLACK)
ui.display.text_center(ui.SCREEN // 2, ui.SCREEN - 20, label, ui.BOLD, ui.FG, ui.BG)
await dim_screen()
def edit(self, text: str, word: str, pending: bool) -> None:
self.word = word
self.text = text
self.pending = pending
self.repaint = True
if word:
if text == word: # confirm button
self.enable()
self.normal_style = ButtonMonoConfirm.normal
self.active_style = ButtonMonoConfirm.active
self.icon = res.load(ui.ICON_CONFIRM)
else: # auto-complete button
self.enable()
self.normal_style = ButtonMono.normal
self.active_style = ButtonMono.active
self.icon = res.load(ui.ICON_CLICK)
else: # disabled button
self.disabled_style = ButtonMono.disabled
self.disable()
self.icon = b""
def header(
title: str,
icon: str = style.ICON_DEFAULT,
fg: int = style.FG,
bg: int = style.BG,
ifg: int = style.GREEN,
) -> None:
if icon is not None:
display.icon(14, 15, res.load(icon), ifg, bg)
display.text(44, 35, title, BOLD, fg, bg)
self.stop_ms = None
if r == target:
s = self.active_style
else:
s = self.normal_style
if s["icon"] is None:
ui.display.loader(r, -24, s["fg-color"], s["bg-color"])
elif s["icon-fg-color"] is None:
ui.display.loader(r, -24, s["fg-color"], s["bg-color"], res.load(s["icon"]))
else:
ui.display.loader(
r,
-24,
s["fg-color"],
s["bg-color"],
res.load(s["icon"]),
s["icon-fg-color"],
)
def __init__(
self,
prompt: str,
subprompt: Optional[str],
allow_cancel: bool = True,
maxlength: int = 9,
) -> None:
self.maxlength = maxlength
self.input = PinInput(prompt, subprompt, "")
icon_confirm = res.load(ui.ICON_CONFIRM)
self.confirm_button = Button(ui.grid(14), icon_confirm, ButtonConfirm)
self.confirm_button.on_click = self.on_confirm # type: ignore
self.confirm_button.disable()
icon_back = res.load(ui.ICON_BACK)
self.reset_button = Button(ui.grid(12), icon_back, ButtonClear)
self.reset_button.on_click = self.on_reset # type: ignore
if allow_cancel:
icon_lock = res.load(ui.ICON_LOCK)
self.cancel_button = Button(ui.grid(12), icon_lock, ButtonCancel)
self.cancel_button.on_click = self.on_cancel # type: ignore
else:
self.cancel_button = Button(ui.grid(12), "")
self.cancel_button.disable()
digits = list(range(start, end))
self.buttons = [Button(digit_area(i), str(d)) for i, d in enumerate(digits)]
if len(digits) == ITEMS_PER_PAGE:
more = Button(
digit_area(PLUS_BUTTON_POSITION), str(end) + "+", style=ui.BTN_KEY_DARK
)
self.buttons.append(more)
# move the tenth button to its proper place and make place for the back button
self.buttons[BACK_BUTTON_POSITION].area = digit_area(
BACK_BUTTON_POSITION + 1
)
back = Button(
digit_area(BACK_BUTTON_POSITION),
res.load(ui.ICON_BACK),
style=ui.BTN_KEY_DARK,
)
if self.page == 0:
back.disable()
self.buttons.append(back)
def render_swipe_icon() -> None:
PULSE_PERIOD = const(1200000)
icon = res.load(ui.ICON_SWIPE)
t = ui.pulse(PULSE_PERIOD)
c = ui.blend(ui.GREY, ui.DARK_GREY, t)
ui.display.icon(70, 205, icon, c, ui.BG)
def func(foreground):
ui.display.loader(p, c, 0, res.load('apps/playground_stick/res/fingerprint.toig'), foreground)
p = (p + 10) % 1000
def __init__(self, prompt: str = ""):
self.prompt = prompt
self.input = Input(ui.grid(1, n_x=4, n_y=4, cells_x=3), "", "")
self.back = Button(
ui.grid(0, n_x=4, n_y=4), res.load(ui.ICON_BACK), style=ui.BTN_CLEAR
)
self.keys = key_buttons(MNEMONIC_KEYS)
self.pbutton = None # pending key button
self.pindex = 0 # index of current pending char in pbutton