Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hansieodendaal committed Sep 13, 2021
1 parent e58faf4 commit 38f3993
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
13 changes: 5 additions & 8 deletions applications/tari_console_wallet/src/ui/state/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl AppState {
wallet,
base_node_selected,
base_node_config,
node_config.wallet_balance_enquiry_cooldown_period,
Duration::from_secs(node_config.wallet_balance_enquiry_cooldown_period),
);
let cached_data = inner.data.clone();

Expand Down Expand Up @@ -152,7 +152,6 @@ impl AppState {
pub async fn refresh_balance_check(&self) -> Result<(), UiError> {
let mut inner = self.inner.write().await;
inner.refresh_balance_check().await?;
drop(inner);
Ok(())
}

Expand Down Expand Up @@ -458,7 +457,7 @@ pub struct AppStateInner {
wallet: WalletSqlite,
balance_enquiry_cooldown_start: Instant,
balance_enquiry_cooldown_infringement: bool,
balance_enquiry_cooldown_period: u64,
balance_enquiry_cooldown_period: Duration,
}

impl AppStateInner {
Expand All @@ -468,7 +467,7 @@ impl AppStateInner {
wallet: WalletSqlite,
base_node_selected: Peer,
base_node_config: PeerConfig,
balance_enquiry_cooldown_period: u64,
balance_enquiry_cooldown_period: Duration,
) -> Self {
let data = AppStateData::new(node_identity, network, base_node_selected, base_node_config);

Expand All @@ -477,7 +476,7 @@ impl AppStateInner {
data,
wallet,
balance_enquiry_cooldown_start: Instant::now()
.sub(Duration::from_secs(balance_enquiry_cooldown_period + 1)),
.sub(balance_enquiry_cooldown_period + Duration::from_secs(1)),
balance_enquiry_cooldown_infringement: false,
balance_enquiry_cooldown_period,
}
Expand Down Expand Up @@ -666,9 +665,7 @@ impl AppStateInner {
}

pub async fn refresh_balance(&mut self) -> Result<(), UiError> {
if Instant::now().duration_since(self.balance_enquiry_cooldown_start) >
Duration::from_secs(self.balance_enquiry_cooldown_period)
{
if self.balance_enquiry_cooldown_start.elapsed() > self.balance_enquiry_cooldown_period {
self.balance_enquiry_cooldown_start = Instant::now();
self.balance_enquiry_cooldown_infringement = false;
let balance = self.wallet.output_manager_service.get_balance().await?;
Expand Down
12 changes: 7 additions & 5 deletions base_layer/wallet/src/base_node_service/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,21 @@ impl<T: WalletBackend + 'static> BaseNodeMonitor<T> {

let start = Instant::now();
self.db.set_chain_metadata(chain_metadata.clone()).await?;
trace!(
target: LOG_TARGET,
"Update metadata in db {} ms",
start.elapsed().as_millis()
);

let start = Instant::now();
self.map_state(move |_| BaseNodeState {
chain_metadata: Some(chain_metadata),
is_synced: Some(is_synced),
updated: Some(Utc::now().naive_utc()),
latency: Some(latency),
})
.await;
trace!(
target: LOG_TARGET,
"Update metadata in db and publish event {} ms",
start.elapsed().as_millis()
);
trace!(target: LOG_TARGET, "Publish event {} ms", start.elapsed().as_millis());

time::sleep(self.interval).await
}
Expand Down

0 comments on commit 38f3993

Please sign in to comment.