diff --git a/releases/Next-ChangeLog.md b/releases/Next-ChangeLog.md index 189e5b98..57f5e234 100644 --- a/releases/Next-ChangeLog.md +++ b/releases/Next-ChangeLog.md @@ -9,6 +9,7 @@ This lists the new changes that have not yet been published in a normal release. - Bugfix: Decrypting Tapsigner backup failed even for correct key - Bugfix: Clear any pending keystrokes before PSBT approval screen. - Enhancement: UX mention need to remove old duress wallets before locking down temporary seed +- Bugfix: UX show only 10 outputs with the biggest value on screen # Mk4 Specific Changes diff --git a/shared/auth.py b/shared/auth.py index f0deda19..ce031315 100644 --- a/shared/auth.py +++ b/shared/auth.py @@ -938,7 +938,10 @@ class ApproveTransaction(UserAuthorizedAction): continue if len(largest) < MAX_VISIBLE_OUTPUTS: - largest.append( (tx_out.nValue, self.render_output(tx_out)) ) + largest.append((tx_out.nValue, self.render_output(tx_out))) + if len(largest) == MAX_VISIBLE_OUTPUTS: + # descending sort from the biggest value to lowest (sort on out.nValue) + largest = sorted(largest, key=lambda x: x[0], reverse=True) continue # insertion sort diff --git a/testing/conftest.py b/testing/conftest.py index 3157917c..61e9872b 100644 --- a/testing/conftest.py +++ b/testing/conftest.py @@ -862,7 +862,7 @@ def use_mainnet(settings_set): @pytest.fixture(scope="function") def use_testnet(settings_set): - def doit(do_testnet): + def doit(do_testnet=True): settings_set('chain', 'XTN' if do_testnet else 'BTC') yield doit settings_set('chain', 'XTN') diff --git a/testing/test_sign.py b/testing/test_sign.py index 91fd770c..83603e4d 100644 --- a/testing/test_sign.py +++ b/testing/test_sign.py @@ -2880,4 +2880,36 @@ def test_bas64_psbt_qr(in_out, partial, segwit, scan_a_qr, readback_bbqr, press_cancel() # back to menu + +def test_sorting_outputs_by_size(fake_txn, start_sign, cap_story, use_testnet, + press_cancel): + use_testnet() + out_vals = [1000000, 2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000, + 9000000, 179989995, 11000000, 12000000, 13000000, 14000000, 15000000] + max_display_num = 10 + rest_num = len(out_vals) - max_display_num + psbt = fake_txn(3, 15, segwit_in=True, outstyles=ADDR_STYLES_SINGLE, + outvals=out_vals) + start_sign(psbt) + time.sleep(.1) + title, story = cap_story() + assert title == 'OK TO SEND?' + rest_sum = 0 + for i, ov in enumerate(sorted(out_vals, reverse=True)): + str_ov = f'{ov / 100000000:.8f} XTN' + if i < 10: + # these must be in story + assert str_ov in story + else: + # these are not covered in story, instead their vals are summed and + # provided just as rest sum + assert str_ov not in story + rest_sum += ov + + # check rest sum is correct + rest_story = f"plus {rest_num} smaller output(s), not shown here, which total: " + rest_story += f'{rest_sum / 100000000:.8f} XTN' + assert rest_story in story + press_cancel() + # EOF