Skip to content

Commit

Permalink
add ScanInvalidQRTypeView
Browse files Browse the repository at this point in the history
  • Loading branch information
kdmukai committed Jan 23, 2025
1 parent 7edcd33 commit c0fe676
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
35 changes: 22 additions & 13 deletions src/seedsigner/views/scan_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import re

from gettext import gettext as _
from seedsigner.gui.components import SeedSignerIconConstants
from seedsigner.helpers.l10n import mark_for_translation as _mft
from seedsigner.models.settings import SettingsConstants
from seedsigner.views.view import BackStackView, ErrorView, MainMenuView, NotYetImplementedView, View, Destination
from seedsigner.gui.screens.screen import ButtonOption

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -164,18 +164,7 @@ def run(self):
# For now, don't even try to re-do the attempted operation, just reset and
# start everything over.
self.controller.resume_main_flow = None

# TODO: Refactor this warning screen into its own Screen class; the
# screenshot generator is currently manually re-creating it, but it would be
# better if a dedicated Screen could just be instantiated instead.
return Destination(ErrorView, view_args=dict(
title=_("Error"),
status_icon_name=SeedSignerIconConstants.WARNING,
status_headline=_("Unknown QR Type"),
text=_("QRCode is invalid or is a data format not yet supported."),
button_text=_("Done"),
next_destination=Destination(MainMenuView, clear_history=True),
))
return Destination(ScanInvalidQRTypeView)

return Destination(MainMenuView)

Expand Down Expand Up @@ -218,3 +207,23 @@ class ScanAddressView(ScanView):
@property
def is_valid_qr_type(self):
return self.decoder.is_address



class ScanInvalidQRTypeView(View):
def run(self):
from seedsigner.gui.screens import WarningScreen

# TODO: This screen says "Error" but is intentionally using the WarningScreen in
# order to avoid the perception that something is broken on our end. This should
# either change to use the red ErrorScreen or the "Error" title should be
# changed to something softer.
self.run_screen(
WarningScreen,
title=_("Error"),
status_headline=_("Unknown QR Type"),
text=_("QRCode is invalid or is a data format not yet supported."),
button_data=[ButtonOption("Done")],
)

return Destination(MainMenuView, clear_history=True)
19 changes: 4 additions & 15 deletions tests/screenshot_generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
patch('PIL.ImageFont.core.HAVE_RAQM', False).start()

from seedsigner.controller import Controller
from seedsigner.gui.components import SeedSignerIconConstants
from seedsigner.gui.renderer import Renderer
from seedsigner.gui.screens.seed_screens import SeedAddPassphraseScreen
from seedsigner.gui.toast import BaseToastOverlayManagerThread, RemoveSDCardToastManagerThread, SDCardStateChangeToastManagerThread
from seedsigner.gui.toast import RemoveSDCardToastManagerThread, SDCardStateChangeToastManagerThread
from seedsigner.hardware.microsd import MicroSD
from seedsigner.helpers import embit_utils
from seedsigner.models.decode_qr import DecodeQR
Expand All @@ -37,9 +36,9 @@
from seedsigner.models.settings import Settings
from seedsigner.models.settings_definition import SettingsConstants, SettingsDefinition
from seedsigner.views import (MainMenuView, PowerOptionsView, RestartView, NotYetImplementedView, UnhandledExceptionView,
psbt_views, seed_views, settings_views, tools_views)
psbt_views, seed_views, settings_views, tools_views, scan_views)
from seedsigner.views.screensaver import OpeningSplashView
from seedsigner.views.view import ErrorView, NetworkMismatchErrorView, OptionDisabledView, PowerOffView, View
from seedsigner.views.view import NetworkMismatchErrorView, OptionDisabledView, PowerOffView

from .utils import ScreenshotComplete, ScreenshotConfig, ScreenshotRenderer

Expand Down Expand Up @@ -360,17 +359,7 @@ def PSBTOpReturnView_raw_hex_data_cb_before():
ScreenshotConfig(UnhandledExceptionView, dict(error=["IndexError", "line 1, in some_buggy_code.py", "list index out of range"])),
ScreenshotConfig(NetworkMismatchErrorView, dict(derivation_path="m/84'/1'/0'")),
ScreenshotConfig(OptionDisabledView, dict(settings_attr=SettingsConstants.SETTING__MESSAGE_SIGNING)),
ScreenshotConfig(
ErrorView,
dict(
title="Error",
status_icon_name=SeedSignerIconConstants.WARNING,
status_headline="Unknown QR Type",
text="QRCode is invalid or is a data format not yet supported.",
button_text="Back",
),
screenshot_name="ScanView__UnknownQRType"
),
ScreenshotConfig(scan_views.ScanInvalidQRTypeView)
]
}

Expand Down
2 changes: 1 addition & 1 deletion tests/test_flows_seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ def load_invalid_signmessage_qr(view: scan_views.ScanView):
FlowStep(seed_views.SeedFinalizeView, button_data_selection=seed_views.SeedFinalizeView.FINALIZE),
FlowStep(seed_views.SeedOptionsView, button_data_selection=seed_views.SeedOptionsView.SIGN_MESSAGE),
FlowStep(scan_views.ScanView, before_run=load_invalid_signmessage_qr), # simulate read message QR; ret val is ignored
FlowStep(ErrorView),
FlowStep(scan_views.ScanInvalidQRTypeView),
FlowStep(MainMenuView),
])

Expand Down

0 comments on commit c0fe676

Please sign in to comment.