From 6a00a4842a2f23a641dea6e8e8ba282478153ba3 Mon Sep 17 00:00:00 2001 From: Philip Robinson Date: Fri, 12 Nov 2021 16:01:33 +0200 Subject: [PATCH] feat: trigger time lock balance update when block received This PR update the console wallet event monitor to trigger a balance refresh when a new block is received IF there is a timelocked balanced that could potentially changed based on the block height. --- Cargo.lock | 8 ++++---- .../tari_console_wallet/src/ui/state/app_state.rs | 9 +++++++++ .../src/ui/state/wallet_event_monitor.rs | 6 ++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e128344af5..5a48731351 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4330,7 +4330,7 @@ dependencies = [ "config", "either", "futures 0.3.17", - "log 0.4.14", + "log", "log-mdc", "num_cpus", "opentelemetry", @@ -4441,7 +4441,7 @@ dependencies = [ "futures 0.3.17", "lazy_static 1.4.0", "lmdb-zero", - "log 0.4.14", + "log", "log-mdc", "multiaddr", "nom 5.1.2", @@ -4493,7 +4493,7 @@ dependencies = [ "lazy_static 1.4.0", "libsqlite3-sys", "lmdb-zero", - "log 0.4.14", + "log", "log-mdc", "petgraph", "pin-project 0.4.28", @@ -4599,7 +4599,7 @@ dependencies = [ "integer-encoding 3.0.2", "lazy_static 1.4.0", "lmdb-zero", - "log 0.4.14", + "log", "log-mdc", "monero", "newtype-ops", diff --git a/applications/tari_console_wallet/src/ui/state/app_state.rs b/applications/tari_console_wallet/src/ui/state/app_state.rs index 783693f525..9f6abcddaa 100644 --- a/applications/tari_console_wallet/src/ui/state/app_state.rs +++ b/applications/tari_console_wallet/src/ui/state/app_state.rs @@ -693,6 +693,15 @@ impl AppStateInner { Ok(()) } + pub fn has_time_locked_balance(&self) -> bool { + if let Some(time_locked_balance) = self.data.balance.time_locked_balance { + if time_locked_balance > MicroTari::from(0) { + return true; + } + } + false + } + pub async fn refresh_balance(&mut self, balance: Balance) -> Result<(), UiError> { self.data.balance = balance; self.updated = true; diff --git a/applications/tari_console_wallet/src/ui/state/wallet_event_monitor.rs b/applications/tari_console_wallet/src/ui/state/wallet_event_monitor.rs index 4f9e8da173..dca471ee9b 100644 --- a/applications/tari_console_wallet/src/ui/state/wallet_event_monitor.rs +++ b/applications/tari_console_wallet/src/ui/state/wallet_event_monitor.rs @@ -260,6 +260,12 @@ impl WalletEventMonitor { if let Err(e) = inner.refresh_base_node_state(state).await { warn!(target: LOG_TARGET, "Error refresh app_state: {}", e); } + + if inner.has_time_locked_balance() { + if let Err(e) = self.balance_enquiry_debounce_tx.send(()) { + warn!(target: LOG_TARGET, "Error refresh app_state: {}", e); + } + } } async fn trigger_base_node_peer_refresh(&mut self, peer: Peer) {