diff --git a/ports/stm32/boards/Passport/modules/flows/save_to_microsd_flow.py b/ports/stm32/boards/Passport/modules/flows/save_to_microsd_flow.py index 524ee72e1..75c30d340 100644 --- a/ports/stm32/boards/Passport/modules/flows/save_to_microsd_flow.py +++ b/ports/stm32/boards/Passport/modules/flows/save_to_microsd_flow.py @@ -49,7 +49,7 @@ async def check_inputs(self): if (not self.data and not self.write_fn) or (self.data and self.write_fn): await ErrorPage("Either data or a write function is required to save a file.").show() - self.set_result(False) + self.set_result(None) return self.goto(self.save) @@ -89,7 +89,7 @@ async def save(self): await ErrorPage(text='Failed to write file: {}'.format(e), right_micron=self.show_check) \ .show(auto_close_timeout=self.auto_timeout) - self.set_result(False) + self.set_result(None) return if written: @@ -104,4 +104,4 @@ async def success(self): await SuccessPage(text='Saved {} as {}'.format(self.success_text, self.out_full), right_micron=self.show_check) \ .show(auto_close_timeout=self.auto_timeout) - self.set_result(True) + self.set_result(self.out_full) diff --git a/ports/stm32/boards/Passport/modules/flows/sign_psbt_qr_flow.py b/ports/stm32/boards/Passport/modules/flows/sign_psbt_qr_flow.py index 0821fc0f5..cbefd37c3 100644 --- a/ports/stm32/boards/Passport/modules/flows/sign_psbt_qr_flow.py +++ b/ports/stm32/boards/Passport/modules/flows/sign_psbt_qr_flow.py @@ -14,10 +14,11 @@ def __init__(self): self.psbt = None self.txid = None self.is_comp = None - self.out_fn = None self.out2_fn = None + self.written = False self.signed_bytes = None self.max_frames = 35 + self.filename = None async def scan_transaction(self): from foundation import ur @@ -108,6 +109,7 @@ async def common_flow(self): self.goto(self.get_signed_bytes) async def get_signed_bytes(self): + import gc from foundation import FixedBytesIO from pages import ErrorPage from passport import mem @@ -127,6 +129,9 @@ async def get_signed_bytes(self): self.set_result(False) return + self.is_comp = self.psbt.is_complete() + self.psbt = None + gc.collect() self.goto(self.show_signed_transaction) async def show_signed_transaction(self): @@ -159,35 +164,21 @@ async def show_signed_transaction(self): self.set_result(True) - def write_final_fn(self, filename): - from utils import HexWriter - - # write psbt to file as hex - with HexWriter(open(filename, 'w+t')) as fd: - self.txid = self.psbt.finalize(fd) - self.out2_fn = filename - - def write_psbt_fn(self, filename): - # Attempt to write-out the transaction - with self.output_encoder(open(filename, 'wb')) as fd: - # save as updated PSBT - self.psbt.serialize(fd) - self.out_fn = filename - async def save_to_microsd(self): from flows import SaveToMicroSDFlow from pages import ErrorPage from utils import get_folder_path from public_constants import DIR_TRANSACTIONS + from ubinascii import hexlify as b2a_hex - # Check that the psbt has been written, and the transaction has been written if complete - if self.out_fn and (self.is_comp == bool(self.out2_fn)): + # Check that the psbt has been written + if self.written: self.goto(self.show_success) return + self.written = True base = 'QR' - self.is_comp = self.psbt.is_complete() if not self.is_comp: # Keep the filename under control during multiple passes target_fname = base + '-part.psbt' @@ -195,28 +186,16 @@ async def save_to_microsd(self): # Add -signed to end. We won't offer to sign again. target_fname = base + '-signed.psbt' - result_1 = await SaveToMicroSDFlow(filename=target_fname, - write_fn=self.write_psbt_fn, - success_text="psbt", - path=get_folder_path(DIR_TRANSACTIONS), - automatic=False, - auto_prompt=True).run() - if not result_1: + self.filename = await SaveToMicroSDFlow(filename=target_fname, + data=b2a_hex(self.signed_bytes), + success_text="psbt", + path=get_folder_path(DIR_TRANSACTIONS), + automatic=False, + auto_prompt=True).run() + if self.filename is None: self.back() return - if self.is_comp: - target2_fname = base + '-final.txn' - result_2 = await SaveToMicroSDFlow(filename=target2_fname, - write_fn=self.write_final_fn, - success_text="transaction", - path=get_folder_path(DIR_TRANSACTIONS), - automatic=False, - auto_prompt=True).run() - if not result_2: - self.back() - return - self.goto(self.show_success) async def show_success(self): @@ -225,13 +204,7 @@ async def show_success(self): from styles.colors import DEFAULT_LARGE_ICON_COLOR from pages import LongTextPage - msg = "Updated PSBT is:\n\n%s" % self.out_fn - if self.out2_fn: - msg += '\n\nFinalized transaction (ready for broadcast):\n\n%s' % self.out2_fn - - if self.txid: - msg += '\n\nFinal TXID:\n' + self.txid - + msg = "Updated PSBT is:\n\n%s" % self.filename result = await LongTextPage(text=msg, centered=True, left_micron=microns.ScanQR, diff --git a/ports/stm32/boards/Passport/modules/pages/show_qr_page.py b/ports/stm32/boards/Passport/modules/pages/show_qr_page.py index cfa50e33b..43961a72d 100644 --- a/ports/stm32/boards/Passport/modules/pages/show_qr_page.py +++ b/ports/stm32/boards/Passport/modules/pages/show_qr_page.py @@ -68,6 +68,7 @@ def __init__(self, self.prev_card_descs = None self.prev_card_idx = common.ui.active_card_idx + self.prev_top_level = False self.qr_size_idx = common.settings.get('last_qr_size_idx', 0) self.qr_card_descs = [ {'page_micron': microns.PageQRSmall},