From 75527ab145d0189dc6efad809c6b28a75e85eb28 Mon Sep 17 00:00:00 2001 From: edouard Date: Wed, 5 Apr 2023 13:16:42 +0200 Subject: [PATCH] gui: fix list spend transactions ordering Spend transactions are first ordered by status in the following order: pending, broadcast, spent, deprecated, then by `updated_at` field with last updated tx first. close #281 --- gui/Cargo.lock | 2 +- gui/src/app/state/recovery.rs | 2 +- gui/src/app/state/spend/step.rs | 2 +- gui/src/daemon/mod.rs | 11 ++++++++++- gui/src/daemon/model.rs | 13 ++++++++++--- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/gui/Cargo.lock b/gui/Cargo.lock index e5fd2535..d0232a0a 100644 --- a/gui/Cargo.lock +++ b/gui/Cargo.lock @@ -1727,7 +1727,7 @@ dependencies = [ [[package]] name = "liana" version = "0.3.0" -source = "git+https://github.com/wizardsardine/liana?branch=master#045182e7eae5846d33934adeb2018ab6857173ae" +source = "git+https://github.com/wizardsardine/liana?branch=master#76deaab9888619249a5ca75dd19d75db155ee1f3" dependencies = [ "backtrace", "base64", diff --git a/gui/src/app/state/recovery.rs b/gui/src/app/state/recovery.rs index d22f4456..05f39b55 100644 --- a/gui/src/app/state/recovery.rs +++ b/gui/src/app/state/recovery.rs @@ -157,7 +157,7 @@ impl State for RecoveryPanel { .copied() .collect(); let sigs = desc.partial_spend_info(&psbt).unwrap(); - Ok(SpendTx::new(psbt, coins, sigs)) + Ok(SpendTx::new(None, psbt, coins, sigs)) }, Message::Recovery, ); diff --git a/gui/src/app/state/spend/step.rs b/gui/src/app/state/spend/step.rs index 56ab745c..33cd9434 100644 --- a/gui/src/app/state/spend/step.rs +++ b/gui/src/app/state/spend/step.rs @@ -451,7 +451,7 @@ impl Step for SaveSpend { .unwrap(); self.spend = Some(detail::SpendTxState::new( self.wallet.clone(), - SpendTx::new(psbt, draft.inputs.clone(), sigs), + SpendTx::new(None, psbt, draft.inputs.clone(), sigs), false, )); } diff --git a/gui/src/daemon/mod.rs b/gui/src/daemon/mod.rs index aff5c012..7b62af6d 100644 --- a/gui/src/daemon/mod.rs +++ b/gui/src/daemon/mod.rs @@ -97,8 +97,17 @@ pub trait Daemon: Debug { .main .partial_spend_info(&tx.psbt) .map_err(|e| DaemonError::Unexpected(e.to_string()))?; - spend_txs.push(model::SpendTx::new(tx.psbt, coins, sigs)) + spend_txs.push(model::SpendTx::new(tx.updated_at, tx.psbt, coins, sigs)) } + spend_txs.sort_by(|a, b| { + if a.status == b.status { + // last updated first + b.updated_at.cmp(&a.updated_at) + } else { + // follows status enum order + a.status.cmp(&b.status) + } + }); Ok(spend_txs) } diff --git a/gui/src/daemon/model.rs b/gui/src/daemon/model.rs index 2f57da14..283f022e 100644 --- a/gui/src/daemon/model.rs +++ b/gui/src/daemon/model.rs @@ -30,18 +30,24 @@ pub struct SpendTx { pub fee_amount: Amount, pub status: SpendStatus, pub sigs: PartialSpendInfo, + pub updated_at: Option, } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(PartialOrd, Ord, Debug, Clone, PartialEq, Eq)] pub enum SpendStatus { Pending, - Deprecated, Broadcast, Spent, + Deprecated, } impl SpendTx { - pub fn new(psbt: Psbt, coins: Vec, sigs: PartialSpendInfo) -> Self { + pub fn new( + updated_at: Option, + psbt: Psbt, + coins: Vec, + sigs: PartialSpendInfo, + ) -> Self { let mut change_indexes = Vec::new(); let (change_amount, spend_amount) = psbt.unsigned_tx.output.iter().enumerate().fold( (Amount::from_sat(0), Amount::from_sat(0)), @@ -73,6 +79,7 @@ impl SpendTx { } Self { + updated_at, coins, psbt, change_indexes,