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
This commit is contained in:
edouard 2023-04-05 13:16:42 +02:00
parent cbff93e25f
commit 75527ab145
5 changed files with 23 additions and 7 deletions

2
gui/Cargo.lock generated
View File

@ -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",

View File

@ -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,
);

View File

@ -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,
));
}

View File

@ -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)
}

View File

@ -30,18 +30,24 @@ pub struct SpendTx {
pub fee_amount: Amount,
pub status: SpendStatus,
pub sigs: PartialSpendInfo,
pub updated_at: Option<u32>,
}
#[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<Coin>, sigs: PartialSpendInfo) -> Self {
pub fn new(
updated_at: Option<u32>,
psbt: Psbt,
coins: Vec<Coin>,
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,