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

UX upgrades to new key screen and easier display of recovery phrase #157

Merged
merged 4 commits into from
Jun 10, 2021
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
16 changes: 8 additions & 8 deletions src/gui/screens/mnemonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class MnemonicScreen(Screen):
def __init__(self, mnemonic="", title="Your recovery phrase", note=None):
def __init__(self, mnemonic="", title="Your recovery phrase:", note=None):
super().__init__()
self.title = add_label(title, scr=self, style="title")
if note is not None:
Expand All @@ -30,7 +30,7 @@ def __init__(
wordlist,
fixer,
title="Your recovery phrase:",
note="Write it down and never show to anybody.",
note="Write it down and never show it to anybody.",
):
self.fixer = fixer
self.wordlist = wordlist
Expand All @@ -42,11 +42,11 @@ def __init__(
self.table.set_click(True)

self.close_label.set_text(lv.SYMBOL.LEFT + " Back")
self.next_button = add_button(scr=self, callback=on_release(self.confirm))
self.done_button = add_button(scr=self, callback=on_release(self.confirm))

self.next_label = lv.label(self.next_button)
self.next_label.set_text("Next " + lv.SYMBOL.RIGHT)
align_button_pair(self.close_button, self.next_button)
self.done_label = lv.label(self.done_button)
self.done_label.set_text(lv.SYMBOL.OK + " Done")
align_button_pair(self.close_button, self.done_button)

# toggle switch 12-24 words
lbl = lv.label(self)
Expand Down Expand Up @@ -99,7 +99,7 @@ def change_word(self, idx):
word = self.table.words[idx]
self.instruction.set_text(
"Changing word number %d:\n%s (%d in wordlist)"
% (idx+1, word.upper(), self.wordlist.index(word))
% (idx+1, word.upper(), self.wordlist.index(word)+1)
)
# hide switch
if not self.switch.get_hidden():
Expand Down Expand Up @@ -132,7 +132,7 @@ def cb(obj, event):
self.table.set_mnemonic(self.fixer(mnemonic))
self.instruction.set_text(
"Changing word number %d:\n%s (%d in wordlist)"
% (idx+1, word.upper(), self.wordlist.index(word))
% (idx+1, word.upper(), self.wordlist.index(word)+1)
)
self.kb.set_event_cb(cb)

Expand Down
6 changes: 2 additions & 4 deletions src/keystore/flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,13 @@ async def init(self, show_fn, show_loader):
await super().init(show_fn, show_loader)

async def storage_menu(self):
"""Manage storage and display of the recovery phrase"""
"""Manage storage"""
buttons = [
# id, text
(None, "Key management"),
(0, "Save key to flash"),
(1, "Load key from flash"),
(2, "Delete key from flash"),
(3, "Show recovery phrase"),
]

# we stay in this menu until back is pressed
Expand Down Expand Up @@ -275,5 +274,4 @@ async def storage_menu(self):
"Success!", "Your key is deleted from flash.", button_text="OK"
)
)
elif menuitem == 3:
await self.show_mnemonic()

6 changes: 2 additions & 4 deletions src/keystore/memorycard.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,15 +313,14 @@ async def init(self, show_fn, show_loader):
await super().init(show_fn, show_loader)

async def storage_menu(self):
"""Manage storage and display of the recovery phrase"""
"""Manage storage"""
enabled = self.connection.isCardInserted()
buttons = [
# id, text
(None, "Smartcard storage"),
(0, "Save key to the card", enabled),
(1, "Load key from the card", enabled),
(2, "Delete key from the card", enabled),
(3, "Show recovery phrase"),
]

# we stay in this menu until back is pressed
Expand Down Expand Up @@ -355,5 +354,4 @@ async def storage_menu(self):
button_text="OK",
)
)
elif menuitem == 3:
await self.show_mnemonic()

42 changes: 1 addition & 41 deletions src/keystore/ram.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ class RAMKeyStore(KeyStore):
_set_pin, _unlock, _change_pin and other pin-related methods.
"""

# Button to go to storage menu
# Menu should be implemented in async storage_menu function
# Here we only have a single option - to show mnemonic
storage_button = "Show mnemonic"
storage_button = None

def __init__(self):
# bip39 mnemonic
Expand Down Expand Up @@ -352,40 +349,3 @@ async def show_mnemonic(self):
self.lock()
await self.unlock()
await self.show(MnemonicScreen(self.mnemonic))

async def storage_menu(self):
"""Manage storage and display of the recovery phrase"""
# This class can only show mnemonic, can't save
await self.show_mnemonic()
"""
# Example:
buttons = [
# id, text
(None, "Key management"),
(0, "Save key to flash"),
(1, "Load key from flash"),
(2, "Delete key from flash"),
(3, "Show recovery phrase"),
]
# wait for menu selection
menuitem = await self.show(Menu(buttons, last=(255, None)))

# process the menu button:
# back button
if menuitem == 255:
pass
elif menuitem == 0:
await self.save_mnemonic()
await self.show(Alert("Success!",
"Your key is stored in flash now."))
elif menuitem == 1:
await self.load_mnemonic()
await self.show(Alert("Success!",
"Your key is loaded."))
elif menuitem == 2:
await self.delete_mnemonic()
await self.show(Alert("Success!",
"Your key is deleted from flash."))
elif menuitem == 3:
await self.show(MnemonicScreen(self.mnemonic))
"""
7 changes: 2 additions & 5 deletions src/keystore/sdcard.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,13 @@ async def delete_mnemonic(self, path=None):
return True

async def storage_menu(self):
"""Manage storage and display of the recovery phrase"""
"""Manage storage"""
buttons = [
# id, text
(None, "Manage keys on SD card and internal flash"),
(0, "Save key"),
(1, "Load key"),
(2, "Delete key"),
(None, "Other"),
(3, "Show recovery phrase"),
]

# we stay in this menu until back is pressed
Expand All @@ -162,5 +160,4 @@ async def storage_menu(self):
await self.show(
Alert("Success!", "Your key is deleted.", button_text="OK")
)
elif menuitem == 3:
await self.show_mnemonic()

12 changes: 8 additions & 4 deletions src/specter.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,17 +276,19 @@ async def settingsmenu(self):
(None, "Key management"),
]
if self.keystore.storage_button is not None:
buttons.append((0, self.keystore.storage_button))
buttons.extend([(2, "Enter BIP-39 password"), (None, "Security")]) # delimiter
buttons.extend([(4, "Device settings")])
buttons.append((1, self.keystore.storage_button))
buttons.append((2, "Enter BIP-39 password"))
if hasattr(self.keystore, "show_mnemonic"):
buttons.append((3, "Show recovery phrase"))
buttons.extend([(None, "Security"), (4, "Device settings")]) # delimiter
# wait for menu selection
menuitem = await self.gui.menu(buttons, last=(255, None), note="Firmware version %s" % get_version())

# process the menu button:
# back button
if menuitem == 255:
return self.mainmenu
elif menuitem == 0:
elif menuitem == 1:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just changed this to 1 to have a proper ordering (now: 1, 2, 3, 4, 5).

await self.keystore.storage_menu()
elif menuitem == 2:
pwd = await self.gui.get_input()
Expand All @@ -295,6 +297,8 @@ async def settingsmenu(self):
self.keystore.set_mnemonic(password=pwd)
for app in self.apps:
app.init(self.keystore, self.network, self.gui.show_loader)
elif menuitem == 3:
await self.keystore.show_mnemonic()
elif menuitem == 4:
await self.update_devsettings()
elif menuitem == 5:
Expand Down