Add specific comparaison order for HistoryTransaction
This commit is contained in:
parent
6de5016c08
commit
c620c8278f
@ -296,7 +296,7 @@ impl State for Home {
|
||||
limit += HISTORY_EVENT_PAGE_SIZE;
|
||||
events = daemon.list_history_txs(0, last_event_date, limit).await?;
|
||||
}
|
||||
events.sort_by(|a, b| b.time.cmp(&a.time));
|
||||
events.sort_by(|a, b| a.compare(b));
|
||||
Ok(events)
|
||||
},
|
||||
Message::HistoryTransactionsExtension,
|
||||
@ -332,7 +332,7 @@ impl State for Home {
|
||||
let mut txs = daemon
|
||||
.list_history_txs(0, now, HISTORY_EVENT_PAGE_SIZE)
|
||||
.await?;
|
||||
txs.sort_by(|a, b| b.time.cmp(&a.time));
|
||||
txs.sort_by(|a, b| a.compare(b));
|
||||
|
||||
let mut pending_txs = daemon.list_pending_txs().await?;
|
||||
pending_txs.extend(txs);
|
||||
|
||||
@ -239,7 +239,7 @@ impl State for TransactionsPanel {
|
||||
limit += HISTORY_EVENT_PAGE_SIZE;
|
||||
txs = daemon.list_history_txs(0, last_tx_date, limit).await?;
|
||||
}
|
||||
txs.sort_by(|a, b| b.time.cmp(&a.time));
|
||||
txs.sort_by(|a, b| a.compare(b));
|
||||
Ok(txs)
|
||||
},
|
||||
Message::HistoryTransactionsExtension,
|
||||
@ -272,7 +272,7 @@ impl State for TransactionsPanel {
|
||||
let mut txs = daemon
|
||||
.list_history_txs(0, now, HISTORY_EVENT_PAGE_SIZE)
|
||||
.await?;
|
||||
txs.sort_by(|a, b| b.time.cmp(&a.time));
|
||||
txs.sort_by(|a, b| a.compare(b));
|
||||
|
||||
let mut pending_txs = daemon.list_pending_txs().await?;
|
||||
pending_txs.extend(txs);
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use liana::descriptors::LianaDescriptor;
|
||||
@ -369,6 +370,18 @@ impl HistoryTransaction {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn compare(&self, other: &Self) -> Ordering {
|
||||
match (&self.time, &other.time) {
|
||||
// `None` values come first
|
||||
(None, Some(_)) => Ordering::Less,
|
||||
(Some(_), None) => Ordering::Greater,
|
||||
// Both are `None`, so we consider them equal
|
||||
(None, None) => self.txid.cmp(&other.txid),
|
||||
// Both are `Some`, compare by descending time, then by txid
|
||||
(Some(time1), Some(time2)) => time2.cmp(time1).then_with(|| self.txid.cmp(&other.txid)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_external(&self) -> bool {
|
||||
matches!(
|
||||
self.kind,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user