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

[Enhancement] Add exit dialog when entering passphrase #563

Merged
merged 6 commits into from
Jul 14, 2024
Merged
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
5 changes: 3 additions & 2 deletions src/seedsigner/gui/screens/seed_screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,17 +844,18 @@ def _run(self):
keyboard_swap = False

# Check our two possible exit conditions
# TODO: note the unusual return value, consider refactoring to a Response object in the future
if input == HardwareButtonsConstants.KEY3:
# Save!
# First light up key3
self.hw_button3.is_selected = True
self.hw_button3.render()
self.renderer.show_image()
return self.passphrase
return dict(passphrase=self.passphrase)

elif input == HardwareButtonsConstants.KEY_PRESS and self.top_nav.is_selected:
# Back button clicked
return self.top_nav.selected_button
return dict(passphrase=self.passphrase, is_back_button=True)

# Check for keyboard swaps
if input == HardwareButtonsConstants.KEY1:
Expand Down
47 changes: 41 additions & 6 deletions src/seedsigner/views/seed_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,20 +355,55 @@ def __init__(self):

def run(self):
passphrase_title=self.seed.passphrase_label
ret = self.run_screen(seed_screens.SeedAddPassphraseScreen, passphrase=self.seed.passphrase, title=passphrase_title)
ret_dict = self.run_screen(seed_screens.SeedAddPassphraseScreen, passphrase=self.seed.passphrase, title=passphrase_title)

if ret == RET_CODE__BACK_BUTTON:
return Destination(BackStackView)

# The new passphrase will be the return value; it might be empty.
self.seed.set_passphrase(ret)
if len(self.seed.passphrase) > 0:
self.seed.set_passphrase(ret_dict["passphrase"])

if "is_back_button" in ret_dict:
if len(self.seed.passphrase) > 0:
return Destination(SeedAddPassphraseExitDialogView)
else:
return Destination(BackStackView)

elif len(self.seed.passphrase) > 0:
return Destination(SeedReviewPassphraseView)

else:
return Destination(SeedFinalizeView)



class SeedAddPassphraseExitDialogView(View):
EDIT = "Edit passphrase"
DISCARD = ("Discard passphrase", None, None, "red")

def __init__(self):
super().__init__()
self.seed = self.controller.storage.get_pending_seed()


def run(self):
button_data = [self.EDIT, self.DISCARD]

selected_menu_num = self.run_screen(
WarningScreen,
title="Discard passphrase?",
status_headline=None,
text=f"Your current passphrase entry will be erased",
show_back_button=False,
button_data=button_data,
)

if button_data[selected_menu_num] == self.EDIT:
return Destination(SeedAddPassphraseView)

elif button_data[selected_menu_num] == self.DISCARD:
self.seed.set_passphrase("")
return Destination(SeedFinalizeView)



class SeedReviewPassphraseView(View):
"""
Display the completed passphrase back to the user.
Expand Down
1 change: 1 addition & 0 deletions tests/screenshot_generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def add_op_return_to_psbt(psbt: PSBT, raw_payload_data: bytes):
seed_views.SeedMnemonicInvalidView,
seed_views.SeedFinalizeView,
seed_views.SeedAddPassphraseView,
seed_views.SeedAddPassphraseExitDialogView,
seed_views.SeedReviewPassphraseView,

(seed_views.SeedOptionsView, dict(seed_num=0)),
Expand Down
2 changes: 1 addition & 1 deletion tests/test_flows_psbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def load_seed_into_decoder(view: scan_views.ScanView):
FlowStep(psbt_views.PSBTSelectSeedView, button_data_selection=psbt_views.PSBTSelectSeedView.SCAN_SEED),
FlowStep(scan_views.ScanSeedQRView, before_run=load_seed_into_decoder),
FlowStep(seed_views.SeedFinalizeView, button_data_selection=SettingsConstants.LABEL__BIP39_PASSPHRASE),
FlowStep(seed_views.SeedAddPassphraseView, screen_return_value="abc"),
FlowStep(seed_views.SeedAddPassphraseView, screen_return_value=dict(passphrase="abc")),
FlowStep(seed_views.SeedReviewPassphraseView, button_data_selection=seed_views.SeedReviewPassphraseView.DONE),
FlowStep(seed_views.SeedOptionsView, is_redirect=True),
FlowStep(psbt_views.PSBTOverviewView),
Expand Down
9 changes: 7 additions & 2 deletions tests/test_flows_seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ def test_passphrase_entry_flow(self):
FlowStep(MainMenuView, button_data_selection=MainMenuView.SCAN),
FlowStep(scan_views.ScanView, before_run=load_seed_into_decoder), # simulate read SeedQR; ret val is ignored
FlowStep(seed_views.SeedFinalizeView, button_data_selection=SettingsConstants.LABEL__BIP39_PASSPHRASE),
FlowStep(seed_views.SeedAddPassphraseView, screen_return_value="muhpassphrase"),
FlowStep(seed_views.SeedAddPassphraseView, screen_return_value=dict(passphrase="muhpassphrase", is_back_button=True)),
FlowStep(seed_views.SeedAddPassphraseExitDialogView, button_data_selection=seed_views.SeedAddPassphraseExitDialogView.DISCARD),
FlowStep(seed_views.SeedFinalizeView, button_data_selection=SettingsConstants.LABEL__BIP39_PASSPHRASE),
FlowStep(seed_views.SeedAddPassphraseView, screen_return_value=dict(passphrase="muhpassphrase", is_back_button=True)),
FlowStep(seed_views.SeedAddPassphraseExitDialogView, button_data_selection=seed_views.SeedAddPassphraseExitDialogView.EDIT),
FlowStep(seed_views.SeedAddPassphraseView, screen_return_value=dict(passphrase="muhpassphrase")),
FlowStep(seed_views.SeedReviewPassphraseView, button_data_selection=seed_views.SeedReviewPassphraseView.EDIT),
FlowStep(seed_views.SeedAddPassphraseView, screen_return_value="muhpassphrase2"),
FlowStep(seed_views.SeedAddPassphraseView, screen_return_value=dict(passphrase="muhpassphrase")),
FlowStep(seed_views.SeedReviewPassphraseView, button_data_selection=seed_views.SeedReviewPassphraseView.DONE),
FlowStep(seed_views.SeedOptionsView),
])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_flows_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def load_seed_into_decoder(view: scan_views.ScanView):
self.run_sequence(
sequence=[
FlowStep(seed_views.SeedFinalizeView, button_data_selection=SettingsConstants.LABEL__BIP39_PASSPHRASE),
FlowStep(seed_views.SeedAddPassphraseView, screen_return_value="mypassphrase"),
FlowStep(seed_views.SeedAddPassphraseView, screen_return_value=dict(passphrase="mypassphrase")),
FlowStep(seed_views.SeedReviewPassphraseView, button_data_selection=seed_views.SeedReviewPassphraseView.DONE),
FlowStep(seed_views.SeedOptionsView, is_redirect=True),
FlowStep(seed_views.SeedExportXpubScriptTypeView),
Expand Down
Loading