Skip to content

Commit

Permalink
SFT-2519: batch 8 of flow optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
mjg-foundation committed Aug 2, 2023
1 parent 3bf365e commit a090b3b
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 95 deletions.
1 change: 0 additions & 1 deletion ports/stm32/boards/Passport/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@
'flows/rename_account_flow.py',
'flows/rename_derived_key_flow.py',
'flows/rename_multisig_flow.py',
'flows/reset_pin_flow.py',
'flows/restore_backup_flow.py',
'flows/restore_seed_flow.py',
'flows/save_to_microsd_flow.py',
Expand Down
1 change: 0 additions & 1 deletion ports/stm32/boards/Passport/modules/flows/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
from .rename_account_flow import *
from .rename_derived_key_flow import *
from .rename_multisig_flow import *
from .reset_pin_flow import *
from .restore_backup_flow import *
from .restore_seed_flow import *
from .scv_flow import *
Expand Down
46 changes: 0 additions & 46 deletions ports/stm32/boards/Passport/modules/flows/reset_pin_flow.py

This file was deleted.

32 changes: 19 additions & 13 deletions ports/stm32/boards/Passport/modules/flows/update_firmware_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@
#
# update_firmware_flow.py - Flow to update firmware on Passport

import lvgl as lv
from files import CardSlot
from constants import FW_HEADER_SIZE, FW_MAX_SIZE
import machine
from pages import ErrorPage, ProgressPage, QuestionPage, SuccessPage, InsertMicroSDPage
from tasks import copy_firmware_to_spi_flash_task
from flows import Flow, FilePickerFlow
from utils import read_user_firmware_pubkey, is_all_zero, start_task
from errors import Error
from flows.flow import Flow


class UpdateFirmwareFlow(Flow):
Expand All @@ -29,9 +21,9 @@ async def on_done(self, error=None):
self.progress_page.set_result(error is None)

async def choose_file(self):
root_path = CardSlot.get_sd_root()
from flows.file_picker_flow import FilePickerFlow

result = await FilePickerFlow(initial_path=root_path, suffix='-passport.bin', show_folders=True).run()
result = await FilePickerFlow(suffix='-passport.bin', show_folders=True).run()
if result is None:
self.set_result(False)
return
Expand All @@ -42,7 +34,13 @@ async def choose_file(self):
self.goto(self.show_firmware_details)

async def show_firmware_details(self):
import common
from common import system
from files import CardSlot
from constants import FW_HEADER_SIZE, FW_MAX_SIZE
from utils import read_user_firmware_pubkey, is_all_zero
from pages.error_page import ErrorPage
from pages.question_page import QuestionPage

with CardSlot() as card:
with open(self.update_file_path, 'rb') as fp:
import os
Expand All @@ -68,7 +66,7 @@ async def show_firmware_details(self):
return

# Validate the header
is_valid, version, error_msg, is_user_signed = common.system.validate_firmware_header(header)
is_valid, version, error_msg, is_user_signed = system.validate_firmware_header(header)
# print('is_valid={}, version={}, error_msg={}, is_user_signed={}'.format(
# is_valid, version, error_msg, is_user_signed))
self.version = version
Expand Down Expand Up @@ -96,6 +94,14 @@ async def show_firmware_details(self):

async def copy_to_flash(self):
from common import settings, system, ui
import lvgl as lv
import machine
from errors import Error
from utils import start_task
from tasks import copy_firmware_to_spi_flash_task
from pages.progress_page import ProgressPage
from pages.success_page import SuccessPage
from pages.insert_microsd_page import InsertMicroSDPage

self.progress_page = ProgressPage(text='Preparing Update', left_micron=None, right_micron=None)

Expand Down
17 changes: 10 additions & 7 deletions ports/stm32/boards/Passport/modules/flows/verify_address_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
# verify_address_flow.py - Scan an address QR code and verify that it belongs to this Passport.


from flows import Flow
from common import ui
import microns
from flows.flow import Flow


_RECEIVE_ADDR = const(0)
Expand All @@ -22,6 +20,8 @@

class VerifyAddressFlow(Flow):
def __init__(self, sig_type=None, multisig_wallet=None):
from common import ui

if sig_type is not None:
initial_state = self.scan_address
else:
Expand All @@ -46,7 +46,7 @@ def __init__(self, sig_type=None, multisig_wallet=None):
self.high_size = [0, 0]

async def choose_sig_type(self):
from pages import SinglesigMultisigChooserPage
from pages.singlesig_multisig_chooser_page import SinglesigMultisigChooserPage
from multisig_wallet import MultisigWallet

if MultisigWallet.get_count() == 0:
Expand All @@ -67,7 +67,7 @@ async def choose_sig_type(self):

async def scan_address(self):
import chains
from pages import ErrorPage
from pages.error_page import ErrorPage
from flows import ScanQRFlow
from wallets.utils import get_addr_type_from_address, get_deriv_path_from_addr_type_and_acct
from utils import is_valid_btc_address, get_next_addr
Expand Down Expand Up @@ -187,8 +187,10 @@ async def search_for_address(self):
self.goto(self.not_found)

async def not_found(self):
from pages import ErrorPage, LongErrorPage
from pages.error_page import ErrorPage
from pages.long_error_page import LongErrorPage
import passport
import microns

# Address was not found in that batch of 100, so offer to keep searching
msg = 'Address Not Found\nRanges Checked:\n'
Expand All @@ -211,7 +213,8 @@ async def not_found(self):
self.set_result(False)

async def found(self):
from pages import SuccessPage, LongSuccessPage
from pages.success_page import SuccessPage
from pages.long_success_page import LongSuccessPage
from utils import save_next_addr, format_btc_address
import passport

Expand Down
20 changes: 13 additions & 7 deletions ports/stm32/boards/Passport/modules/flows/verify_backup_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@
#
# verify_backup_flow.py - Verify a selected backup file.


from flows import Flow, FilePickerFlow
from pages import ErrorPage, SuccessPage, LongSuccessPage, InsertMicroSDPage
from utils import get_backups_folder_path, spinner_task
from tasks import verify_backup_task
from errors import Error
import passport
from flows.flow import Flow


class VerifyBackupFlow(Flow):
def __init__(self):
super().__init__(initial_state=self.choose_file, name='VerifyBackupFlow')

async def choose_file(self):
from flows.file_picker_flow import FilePickerFlow
from utils import get_backups_folder_path

backups_path = get_backups_folder_path()
result = await FilePickerFlow(initial_path=backups_path, suffix='.7z', show_folders=True).run()
if result is None:
Expand All @@ -30,6 +27,15 @@ async def choose_file(self):
self.goto(self.do_verify)

async def do_verify(self):
import passport
from errors import Error
from tasks import verify_backup_task
from utils import spinner_task
from pages.error_page import ErrorPage
from pages.success_page import SuccessPage
from pages.long_success_page import LongSuccessPage
from pages.insert_microsd_page import InsertMicroSDPage

(error,) = await spinner_task(
'Verifying Backup',
verify_backup_task,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
#
# view_backup_code_flow.py - Confirm the user wants to see this sensitive info, then show it.

from pages import QuestionPage, ErrorPage, BackupCodePage
from flows import Flow
from tasks import get_backup_code_task
from utils import spinner_task


class ViewBackupCodeFlow(Flow):
def __init__(self):
super().__init__(initial_state=self.confirm_show, name='ViewBackupCodeFlow')

async def confirm_show(self):
from pages.question_page import QuestionPage

result = await QuestionPage(
'The next screen will show your backup code.\n\n' +
'Display this sensitive information?').show()
Expand All @@ -24,6 +23,11 @@ async def confirm_show(self):
self.set_result(False)

async def show_backup_code(self):
from utils import spinner_task
from tasks import get_backup_code_task
from pages.error_page import ErrorPage
from pages.backup_code_page import BackupCodePage

(backup_code, error) = await spinner_task('Retrieving\nBackup Code', get_backup_code_task)
if error is None:
await BackupCodePage(digits=backup_code, editable=False, card_header={'title': 'Backup Code'}).show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
#
# view_current_firmware_flow.py - View the current firmware information

from flows import Flow
from pages import SuccessPage
import microns
from flows.flow import Flow


class ViewCurrentFirmwareFlow(Flow):
Expand All @@ -14,6 +12,9 @@ def __init__(self):

async def show_info(self):
from common import system, ui
from pages.success_page import SuccessPage
import microns

(fw_version, fw_timestamp, boot_counter, user_signed, fw_date) = system.get_software_info()

msg = '''Version {fw_version}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# view_derived_key_details_flow.py - Show user details of a derived key

from flows import Flow
from flows.flow import Flow


class ViewDerivedKeyDetailsFlow(Flow):
Expand All @@ -14,7 +14,8 @@ def __init__(self, context=None):
async def show_overview(self):
from utils import recolor
from styles.colors import HIGHLIGHT_TEXT_HEX
from pages import LongTextPage, ErrorPage
from pages.long_text_page import LongTextPage
from pages.error_page import ErrorPage
from derived_key import get_key_type_from_tn
import microns

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
#
# view_dev_pubkey_flow.py - Flow to show the developer pubkey to the user

from flows import Flow
from pages import StatusPage
import microns
from utils import read_user_firmware_pubkey, bytes_to_hex_str, split_to_lines
from flows.flow import Flow


class ViewDevPubkeyFlow(Flow):
def __init__(self):
super().__init__(initial_state=self.show_dev_pubkey)

async def show_dev_pubkey(self):
from pages.status_page import StatusPage
import microns
from utils import read_user_firmware_pubkey, bytes_to_hex_str, split_to_lines

pubkey_result, pubkey = read_user_firmware_pubkey()
if pubkey_result:
pubkey = bytes_to_hex_str(pubkey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#
# view_multisig_details_flow.py - Show user details of an existing wallet

from flows import Flow
from pages import LongTextPage
from flows.flow import Flow


class ViewMultisigDetailsFlow(Flow):
Expand All @@ -17,6 +16,8 @@ def __init__(self, context=None):
self.ms = MultisigWallet.get_by_idx(self.storage_idx)

async def show_overview(self):
from pages.long_text_page import LongTextPage

msg, _ = self.ms.format_overview(importing=False)

result = await LongTextPage(card_header={'title': self.ms.name}, text=msg, centered=True).show()
Expand All @@ -28,6 +29,8 @@ async def show_overview(self):

async def show_details(self):
import microns
from pages.long_text_page import LongTextPage

msg = self.ms.format_details()

result = await LongTextPage(card_header={'title': self.ms.name},
Expand Down
Loading

0 comments on commit a090b3b

Please sign in to comment.