From 32942222f856b8699d86fb819d1c215d2ebaa6b5 Mon Sep 17 00:00:00 2001 From: Tal Derei Date: Tue, 7 May 2024 14:14:21 -0700 Subject: [PATCH] restore note prioritization logic --- crates/view/src/planner.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/crates/view/src/planner.rs b/crates/view/src/planner.rs index 8094dbee36..dc50a9f600 100644 --- a/crates/view/src/planner.rs +++ b/crates/view/src/planner.rs @@ -471,18 +471,26 @@ impl Planner { /// instance, a user might prefer a note prioritization strategy that harvested /// capital losses when possible, using cost basis information retained by the /// view server. - fn prioritize_and_filter_spendable_notes( + pub fn prioritize_and_filter_spendable_notes( &mut self, records: Vec, ) -> Vec { - // Filter out zero valued notes. let mut filtered = records .into_iter() .filter(|record| record.note.amount() > Amount::zero()) .collect::>(); - - filtered.sort_by(|a, b| b.note.amount().cmp(&a.note.amount())); - + filtered.sort_by(|a, b| { + // Sort by whether the note was sent to an ephemeral address... + match ( + a.address_index.is_ephemeral(), + b.address_index.is_ephemeral(), + ) { + (true, false) => std::cmp::Ordering::Less, + (false, true) => std::cmp::Ordering::Greater, + // ... then by largest amount. + _ => b.note.amount().cmp(&a.note.amount()), + } + }); filtered }