Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display toast when seed already exists #586

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/seedsigner/gui/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class SeedSignerIconConstants:
ERROR = "\ue912"
SUCCESS = "\ue913"
WARNING = "\ue914"
INFO = "\ue921"

# Informational icons
ADDRESS = "\ue915"
Expand All @@ -146,7 +147,7 @@ class SeedSignerIconConstants:
QRCODE = "\ue91f"

MIN_VALUE = SCAN
MAX_VALUE = QRCODE
MAX_VALUE = INFO



Expand Down
20 changes: 20 additions & 0 deletions src/seedsigner/gui/toast.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def toggle_renderer_lock(self):
def run(self):
logger.info(f"{self.__class__.__name__}: started")
start = time.time()
time.sleep(0.1)
while time.time() - start < self.activation_delay:
if self.hw_inputs.has_any_input():
# User has pressed a button, cancel the toast
Expand Down Expand Up @@ -230,3 +231,22 @@ def instantiate_toast(self) -> ToastOverlay:
icon_name=SeedSignerIconConstants.MICROSD,
label_text=self.message,
)

class AlreadyLoadedSeedToastManagerThread(BaseToastOverlayManagerThread):
def __init__(self, activation_delay=0):
# Note: activation_delay is configurable so the screenshot generator can get the
# toast to immediately render.
super().__init__(
activation_delay=activation_delay, # seconds
duration=5, # seconds
)


def instantiate_toast(self) -> ToastOverlay:
return ToastOverlay(
icon_name=SeedSignerIconConstants.INFO,
label_text="Seed already in memory",
font_size=GUIConstants.BODY_FONT_SIZE,
height=GUIConstants.BODY_FONT_SIZE * 2 + GUIConstants.BODY_LINE_SPACING + GUIConstants.EDGE_PADDING,
color=GUIConstants.INFO_COLOR,
)
3 changes: 3 additions & 0 deletions src/seedsigner/models/seed_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def finalize_pending_seed(self) -> int:
return index


def pending_seed_is_loaded(self) -> bool:
return self.pending_seed in self.seeds

def clear_pending_seed(self):
self.pending_seed = None

Expand Down
Binary file modified src/seedsigner/resources/fonts/seedsigner-icons.otf
Binary file not shown.
5 changes: 5 additions & 0 deletions src/seedsigner/views/seed_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from seedsigner.gui.screens import (RET_CODE__BACK_BUTTON, ButtonListScreen,
WarningScreen, DireWarningScreen, seed_screens)
from seedsigner.gui.screens.screen import LargeIconStatusScreen, QRDisplayScreen
from seedsigner.gui.toast import AlreadyLoadedSeedToastManagerThread
from seedsigner.helpers import embit_utils
from seedsigner.models.decode_qr import DecodeQR
from seedsigner.models.encode_qr import CompactSeedQrEncoder, GenericStaticQrEncoder, SeedQrEncoder, SpecterXPubQrEncoder, StaticXpubQrEncoder, UrXpubQrEncoder
Expand Down Expand Up @@ -325,6 +326,8 @@ def run(self):
)

if button_data[selected_menu_num] == self.FINALIZE:
if self.controller.storage.pending_seed_is_loaded():
self.controller.activate_toast(AlreadyLoadedSeedToastManagerThread())
seed_num = self.controller.storage.finalize_pending_seed()
return Destination(SeedOptionsView, view_args={"seed_num": seed_num}, clear_history=True)

Expand Down Expand Up @@ -428,6 +431,8 @@ def run(self):
return Destination(SeedAddPassphraseView)

elif button_data[selected_menu_num] == self.DONE:
if self.controller.storage.pending_seed_is_loaded():
self.controller.activate_toast(AlreadyLoadedSeedToastManagerThread())
seed_num = self.controller.storage.finalize_pending_seed()
return Destination(SeedOptionsView, view_args={"seed_num": seed_num}, clear_history=True)

Expand Down
5 changes: 3 additions & 2 deletions tests/screenshot_generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

from seedsigner.controller import Controller
from seedsigner.gui.renderer import Renderer
from seedsigner.gui.toast import BaseToastOverlayManagerThread, RemoveSDCardToastManagerThread, SDCardStateChangeToastManagerThread
from seedsigner.gui.toast import BaseToastOverlayManagerThread, RemoveSDCardToastManagerThread, SDCardStateChangeToastManagerThread, AlreadyLoadedSeedToastManagerThread
from seedsigner.hardware.microsd import MicroSD
from seedsigner.models.decode_qr import DecodeQR
from seedsigner.models.qr_type import QRType
Expand Down Expand Up @@ -180,6 +180,7 @@ def add_op_return_to_psbt(psbt: PSBT, raw_payload_data: bytes):
seed_views.SeedReviewPassphraseView,

(seed_views.SeedOptionsView, dict(seed_num=0)),
(seed_views.SeedOptionsView, dict(seed_num=0), "SeedOptionsView_AlreadyLoadedSeed", AlreadyLoadedSeedToastManagerThread(activation_delay=0)),
(seed_views.SeedBackupView, dict(seed_num=0)),
(seed_views.SeedExportXpubSigTypeView, dict(seed_num=0)),
(seed_views.SeedExportXpubScriptTypeView, dict(seed_num=0, sig_type="msig")),
Expand Down Expand Up @@ -326,6 +327,7 @@ def screencap_view(view_cls: View, view_args: dict = {}, view_name: str = None,
readme += """<table style="border: 0;">"""
readme += f"""<tr><td align="center">\n"""
for screenshot in screenshot_list:
toast_thread = None
if type(screenshot) == tuple:
if len(screenshot) == 2:
view_cls, view_args = screenshot
Expand All @@ -338,7 +340,6 @@ def screencap_view(view_cls: View, view_args: dict = {}, view_name: str = None,
view_cls = screenshot
view_args = {}
view_name = view_cls.__name__
toast_thread = None

screencap_view(view_cls, view_args=view_args, view_name=view_name, toast_thread=toast_thread)
readme += """ <table align="left" style="border: 1px solid gray;">"""
Expand Down
Loading