Skip to content

Commit

Permalink
feat: trigger time lock balance update when block received (#3567)
Browse files Browse the repository at this point in the history
Description
---
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.


How Has This Been Tested?
---
cargo test
  • Loading branch information
philipr-za authored Nov 15, 2021
1 parent f013e19 commit 11b8afa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions applications/tari_console_wallet/src/ui/state/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 11b8afa

Please sign in to comment.