From fbfd59ec62dc18c5778c20e6d972703828feb3ec Mon Sep 17 00:00:00 2001 From: Matt Gleason Date: Wed, 24 Jul 2024 13:12:44 -0400 Subject: [PATCH] SFT-1943: fixed predictive text page holding onto previous entries --- .../Passport/modules/flows/restore_backup_flow.py | 7 +++++-- .../Passport/modules/flows/restore_seed_flow.py | 9 ++++++--- .../modules/pages/predictive_text_input_page.py | 11 +++++------ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/ports/stm32/boards/Passport/modules/flows/restore_backup_flow.py b/ports/stm32/boards/Passport/modules/flows/restore_backup_flow.py index c767706eb..2750b31bf 100644 --- a/ports/stm32/boards/Passport/modules/flows/restore_backup_flow.py +++ b/ports/stm32/boards/Passport/modules/flows/restore_backup_flow.py @@ -99,14 +99,17 @@ async def enter_backup_password(self): result = await PredictiveTextInputPage( word_list='bytewords', total_words=NUM_BACKUP_PASSWORD_WORDS, - initial_words=self.backup_password_words).show() + initial_words=self.backup_password_words, + initial_prefixes=self.backup_password_prefixes).show() + + (backup_password_words, self.backup_password_prefixes, _) = result if result is None: cancel = await QuestionPage(text='Cancel password entry? ' + 'All progress will be lost.').show() if cancel: self.back() else: - self.backup_password_words, self.backup_password_prefixes = result + self.backup_password_words = backup_password_words self.decryption_password = (' ').join(self.backup_password_words) # print('6 words: decryption_password={}'.format(self.decryption_password)) self.goto(self.do_restore) diff --git a/ports/stm32/boards/Passport/modules/flows/restore_seed_flow.py b/ports/stm32/boards/Passport/modules/flows/restore_seed_flow.py index 64824777e..c2a84d725 100644 --- a/ports/stm32/boards/Passport/modules/flows/restore_seed_flow.py +++ b/ports/stm32/boards/Passport/modules/flows/restore_seed_flow.py @@ -21,6 +21,7 @@ def __init__(self, refresh_cards_when_done=False, autobackup=True, full_backup=F self.validate_text = None self.index = 0 self.seed_words = [] + self.prefixes = [] self.full_backup = full_backup self.autobackup = autobackup self.statusbar = {'title': 'IMPORT SEED', 'icon': 'ICON_SEED'} @@ -103,9 +104,12 @@ async def enter_seed_words(self): word_list='bip39', total_words=self.seed_length, initial_words=self.seed_words, + initial_prefixes=self.prefixes, start_index=self.index).show() - if result is None: + seed_words, self.prefixes, get_last_word = result + + if seed_words is None: cancel = await QuestionPage( text='Cancel seed entry? All progress will be lost.').show() @@ -116,8 +120,7 @@ async def enter_seed_words(self): self.index = 0 return - self.seed_words, self.prefixes, get_last_word = result - + self.seed_words = seed_words if get_last_word: last_word = await RandomFinalWordFlow(self.seed_words).run() diff --git a/ports/stm32/boards/Passport/modules/pages/predictive_text_input_page.py b/ports/stm32/boards/Passport/modules/pages/predictive_text_input_page.py index 84c1c4e67..ea760fdef 100644 --- a/ports/stm32/boards/Passport/modules/pages/predictive_text_input_page.py +++ b/ports/stm32/boards/Passport/modules/pages/predictive_text_input_page.py @@ -29,8 +29,8 @@ def __init__(self, total_words=24, card_header=None, statusbar=None, - initial_words=[], - initial_prefixes=[], + initial_words=None, + initial_prefixes=None, left_micron=microns.Back, right_micron=microns.Forward, start_index=None): @@ -45,8 +45,8 @@ def __init__(self, self.total_words = total_words self.word_idx = start_index if (start_index is not None and start_index < self.total_words) else 0 self.prediction_idx = 0 - self.selected_words = initial_words - self.prefixes = initial_prefixes + self.selected_words = initial_words or [] + self.prefixes = initial_prefixes or [] self.predictions = [] with Stylize(self) as default: @@ -97,7 +97,6 @@ def update_predictions(self): # print('Lookup words for {}'.format(prefix)) set_list(self.prefixes, self.word_idx, prefix) self.predictions = get_words_matching_prefix(prefix, max=10, word_list=self.word_list) - print("len(predictions): {}".format(len(self.predictions))) elif self.word_idx == self.total_words - 1: self.predictions = [RANDOM_WORD_STRING] else: @@ -208,7 +207,7 @@ def left_action(self, is_pressed): self.update_title() self.update_predictions() else: - self.set_result(None) + self.set_result((None, self.prefixes, False)) def attach(self, group): super().attach(group)