Skip to content

Commit

Permalink
fix: hide unmined coinbase (#6159)
Browse files Browse the repository at this point in the history
Description
---
This reintroduced code to hide unmined coinbase transactions.

Motivation and Context
---
Will show and hide depending on the user preference all coinbases that
are reorged out and not in the main chain anymore.
  • Loading branch information
SWvheerden committed Mar 1, 2024
1 parent a875934 commit 2ccde17
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ impl<B: Backend> Component<B> for TransactionsTab {
error!(target: LOG_TARGET, "Error rebroadcasting transactions: {}", e);
}
},
'a' => app_state.toggle_abandoned_coinbase_filter(),
'\n' => match self.selected_tx_list {
SelectedTransactionList::None => {},
SelectedTransactionList::PendingTxs => {
Expand Down
25 changes: 24 additions & 1 deletion applications/minotari_console_wallet/src/ui/state/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub struct AppState {
inner: Arc<RwLock<AppStateInner>>,
cached_data: AppStateData,
cache_update_cooldown: Option<Instant>,
completed_tx_filter: TransactionFilter,
config: AppStateConfig,
wallet_config: WalletConfig,
wallet_connectivity: WalletConnectivityHandle,
Expand All @@ -121,6 +122,7 @@ impl AppState {
cached_data,
cache_update_cooldown: None,
config: AppStateConfig::default(),
completed_tx_filter: TransactionFilter::AbandonedCoinbases,
wallet_connectivity,
balance_enquiry_debouncer: BalanceEnquiryDebouncer::new(
inner,
Expand Down Expand Up @@ -185,6 +187,13 @@ impl AppState {
Ok(())
}

pub fn toggle_abandoned_coinbase_filter(&mut self) {
self.completed_tx_filter = match self.completed_tx_filter {
TransactionFilter::AbandonedCoinbases => TransactionFilter::None,
TransactionFilter::None => TransactionFilter::AbandonedCoinbases,
};
}

pub async fn update_cache(&mut self) {
let update = match self.cache_update_cooldown {
Some(last_update) => last_update.elapsed() > self.config.cache_update_cooldown,
Expand Down Expand Up @@ -556,7 +565,15 @@ impl AppState {
}

pub fn get_completed_txs(&self) -> Vec<&CompletedTransactionInfo> {
self.cached_data.completed_txs.iter().collect()
if self.completed_tx_filter == TransactionFilter::AbandonedCoinbases {
self.cached_data
.completed_txs
.iter()
.filter(|tx| !matches!(tx.status, TransactionStatus::CoinbaseNotInBlockChain))
.collect()
} else {
self.cached_data.completed_txs.iter().collect()
}
}

pub fn get_confirmations(&self, tx_id: TxId) -> Option<&u64> {
Expand Down Expand Up @@ -1370,3 +1387,9 @@ impl Default for AppStateConfig {
}
}
}

#[derive(Clone, PartialEq)]
pub enum TransactionFilter {
None,
AbandonedCoinbases,
}

0 comments on commit 2ccde17

Please sign in to comment.