Skip to content

Commit

Permalink
Merge pull request #4 from Foundation-Devices/v1.0.2-dev
Browse files Browse the repository at this point in the history
v1.0.2 dev branch
  • Loading branch information
FoundationKen authored May 27, 2021
2 parents 65277d2 + ccb1d6d commit 3c83a9b
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 68 deletions.
26 changes: 13 additions & 13 deletions ports/stm32/boards/Passport/modules/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from common import settings, system, noise, dis
from utils import (UXStateMachine, imported, pretty_short_delay, xfp2str, to_str,
truncate_string_to_width, set_next_addr, scan_for_address, get_accounts, run_chooser,
make_account_name_num, is_valid_address, save_next_addr)
make_account_name_num, is_valid_address, save_next_addr, needs_microsd)
from wallets.utils import get_export_mode, get_addr_type_from_address, get_deriv_path_from_addr_type_and_acct
from ux import (the_ux, ux_confirm, ux_enter_pin,
ux_enter_text, ux_scan_qr_code, ux_shutdown,
Expand All @@ -31,32 +31,24 @@
import trezorcrypto
from seed_check_ux import SeedCheckUX

async def needs_microsd():
# Standard msg shown if no SD card detected when we need one.
return await ux_show_story("Please insert a microSD card.", title='MicroSD', center=True, center_vertically=True)

async def about_info(*a):
from common import system
from display import FontTiny
from utils import swab32

while True:
serial = system.get_serial_number()
my_xfp = settings.get('xfp', 0)
xpub = settings.get('xpub', None)

msg = '''Serial Number:
{serial}
msg = '''
Master Fingerprint:
{xfp}
Reversed Fingerprint:
{rev_xfp}
Master XPUB:
{xpub}'''.format(serial=serial,
xfp=xfp2str(my_xfp) if my_xfp else '<No Seed Yet>',
{xpub}'''.format(xfp=xfp2str(my_xfp) if my_xfp else '<No Seed Yet>',
rev_xfp=xfp2str(swab32(my_xfp)) if my_xfp else '<No Seed Yet>',
xpub=xpub if xpub != None else '<No Seed Yet>')

Expand Down Expand Up @@ -622,7 +614,7 @@ async def create_new_seed(*a):
Experienced users can always view and record the 24-word seed in the Advanced settings menu.''', title='Backup')
if ch == 'x':
if await ux_confirm("Are you sure you want to cancel the backup?\n\nWithout a microSD backup or the seed phrase, you won't be able to recover your funds"):
if await ux_confirm("Are you sure you want to cancel the backup?\n\nWithout a microSD backup or the seed phrase, you won't be able to recover your funds."):
# Go back to the outer loop and show the selection again
break

Expand Down Expand Up @@ -1019,7 +1011,7 @@ async def file_picker(msg, suffix=None, min_size=None, max_size=None, taster=Non
# - escape: allow these chars to skip picking process
from menu import MenuSystem, MenuItem
import uos
from utils import get_filesize
from utils import get_filesize, folder_exists

system.turbo(True)

Expand All @@ -1035,6 +1027,10 @@ async def file_picker(msg, suffix=None, min_size=None, max_size=None, taster=Non
folder_path = [folder_path]

for path in folder_path:
# If the folder doesn't exist, skip it (e.g., if /sd/backups/ doesn't exist)
if not folder_exists(path):
continue

files = uos.ilistdir(path)
for fn, ftype, *var in files:
# print("fn={} ftype={} var={} suffix={}".format(fn, ftype, var, suffix))
Expand Down Expand Up @@ -1943,6 +1939,10 @@ async def test_read_flash_cache(*a):
async def toggle_screenshot_mode(*a):
import common
common.screenshot_mode_enabled = not common.screenshot_mode_enabled

if common.screenshot_mode_enabled:
await ux_show_story('Press and release the aA1 key in the lower right corner of the keypad to save a screenshot to the microSD card.\n\nIf no microSD is inserted, nothing will happen.',
title='Screenshots', center=True, center_vertically=True)
# print('common.screenshot_mode_enabled={}'.format(common.screenshot_mode_enabled))

async def toggle_snapshot_mode(*a):
Expand Down
6 changes: 4 additions & 2 deletions ports/stm32/boards/Passport/modules/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from multisig import make_multisig_menu
from wallets.utils import has_export_mode
from export import view_backup_password
from utils import is_new_wallet_in_progress, get_accounts
from utils import is_new_wallet_in_progress, get_accounts, is_screenshot_mode_enabled
from new_wallet import pair_new_wallet
from ie import show_browser

Expand Down Expand Up @@ -184,5 +184,7 @@ def not_account_zero():
# MenuItem('Developer Menu', menu=DeveloperMenu),
MenuItem('Snakamoto', f=play_snake),
MenuItem('Stacking Sats', f=play_stacking_sats),
MenuItem('Internet Browser', f=show_browser)
MenuItem('Internet Browser', f=show_browser),
MenuItem('Enable Screenshots', f=toggle_screenshot_mode, predicate=lambda: not is_screenshot_mode_enabled()),
MenuItem('Disable Screenshots', f=toggle_screenshot_mode, predicate=is_screenshot_mode_enabled)
]
98 changes: 74 additions & 24 deletions ports/stm32/boards/Passport/modules/self_test_ux.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,81 @@
#

from common import system
from utils import UXStateMachine
from utils import UXStateMachine, needs_microsd
from ux import ux_show_text_as_ur, ux_keypad_test, ux_scan_qr_code, ux_show_story, ux_draw_alignment_grid
from data_codecs.qr_type import QRType

async def microsd_test():
import uos
import os
from files import CardSlot, CardMissingError
from utils import file_exists

msg = 'The Times 03/Jan/2009 Chancellor on brink of second bailout for banks'

while True:
try:
with CardSlot() as card:
filename = '{}/microsd-test.txt'.format(card.get_sd_root())

if file_exists(filename):
os.remove(filename)

with open(filename, 'wt') as fd:
fd.write(msg)

with open(filename, 'rt') as fd:
read_msg = fd.read()

if read_msg != msg:
await ux_show_story('The text read back from the microSD card did not match that written. Read:\n\n {}'.format(read_msg), title='Error')
return False

os.remove(filename)
result = await ux_show_story('microSD card is working properly!', title='microSD Test', center=True, center_vertically=True)
if result == 'x':
return False
return True

except CardMissingError:
result = await needs_microsd()
if result == 'x':
return False

except Exception as e:
await ux_show_story('{}'.format(e), title='Exception')
return False


class SelfTestUX(UXStateMachine):

def __init__(self):
# States
self.SHOW_SERIAL_NUMBER = 1
self.KEYPAD_TEST = 2
self.CAMERA_TEST = 3
self.CAMERA_TEST_RESULT = 4
self.SCREEN_ALIGNMENT = 5
self.KEYPAD_TEST = 1
self.CAMERA_TEST = 2
self.CAMERA_TEST_RESULT = 3
self.SCREEN_ALIGNMENT = 4
self.MICROSD_TEST = 5
self.TESTS_COMPLETE = 6
self.qr_data = None

# print('SelfTestUX init')
super().__init__(self.SHOW_SERIAL_NUMBER)
super().__init__(self.KEYPAD_TEST)

async def show(self):
while True:
# print('show: state={}'.format(self.state))
if self.state == self.SHOW_SERIAL_NUMBER:
serial = system.get_serial_number()
result = await ux_show_text_as_ur(title='Serial Num.', qr_text=serial, qr_type=QRType.QR, msg=serial,
right_btn='NEXT') # If right_btn is specified, then RESIZE doesn't appear/work, which is fine here
if result == 'x':
return
else:
self.goto(self.KEYPAD_TEST)

elif self.state == self.KEYPAD_TEST:
if self.state == self.KEYPAD_TEST:
# print('Keypad Test!')
result = await ux_keypad_test()
if result == 'x':
self.goto(self.SHOW_SERIAL_NUMBER)
self.goto_prev()
else:
self.goto(self.SCREEN_ALIGNMENT)

elif self.state == self.SCREEN_ALIGNMENT:
result = await ux_draw_alignment_grid(title='Align Screen')
if result == 'x':
self.goto(self.KEYPAD_TEST)
self.goto_prev()
else:
self.goto(self.CAMERA_TEST)

Expand All @@ -56,19 +89,36 @@ async def show(self):
self.qr_data = await ux_scan_qr_code('Camera Test')
# print('qr_data=|{}|'.format(self.qr_data))
system.turbo(False)
self.goto(self.CAMERA_TEST_RESULT)
self.goto(self.CAMERA_TEST_RESULT, save_curr=False)

elif self.state == self.CAMERA_TEST_RESULT:
if self.qr_data == None:
result = await ux_show_story('No QR code scanned.', right_btn='RETRY')
if result == 'x':
self.goto(self.SCREEN_ALIGNMENT)
self.goto_prev()
else:
self.goto(self.CAMERA_TEST)
else:
# Show the data - The QR code used in the factory starts with "Camera Test Passed!"
result = await ux_show_story(self.qr_data, right_btn='DONE')
if result == 'x':
self.goto(self.SCREEN_ALIGNMENT)
self.goto_prev()
else:
self.goto(self.MICROSD_TEST)

elif self.state == self.MICROSD_TEST:
# Describe the microSD test
result = await ux_show_story('This test will exercise the read/write features of the microSD card.', title='microSD Test', right_btn='START', center=True, center_vertically=True)
if result == 'x':
self.goto_prev()
continue

if await microsd_test():
self.goto(self.TESTS_COMPLETE)

elif self.state == self.TESTS_COMPLETE:
result = await ux_show_story('All tests complete!', title='Complete', right_btn='SHUTDOWN', center=True, center_vertically=True)
if result == 'x':
self.goto_prev()
else:
return
system.shutdown()
20 changes: 20 additions & 0 deletions ports/stm32/boards/Passport/modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,17 @@ def file_exists(path):
except:
return False

def folder_exists(path):
import os
from stat import S_ISDIR

try:
s = os.stat(path)
mode = s[0]
return S_ISDIR(mode)
except OSError as e:
return False

# Derive addresses from the specified path until we find the address or have tried max_to_check addresses
# If single sig, we need `path`.
# If multisig, we need `ms_wallet`, but not `path`
Expand Down Expand Up @@ -650,6 +661,10 @@ def is_new_wallet_in_progress():
ap = settings.get('wallet_prog', None)
return ap != None

def is_screenshot_mode_enabled():
from common import screenshot_mode_enabled
return screenshot_mode_enabled

async def do_rename_account(acct_num, new_name):
from common import settings
from export import auto_backup
Expand Down Expand Up @@ -758,4 +773,9 @@ def is_alphanumeric_qr(buf):

return True

async def needs_microsd():
from ux import ux_show_story
# Standard msg shown if no SD card detected when we need one.
return await ux_show_story("Please insert a microSD card.", title='MicroSD', center=True, center_vertically=True)

# EOF
Loading

0 comments on commit 3c83a9b

Please sign in to comment.