quantus_cli/cli/
progress_spinner.rs1use crate::{chain::client::ChainConfig, error::Result};
2use colored::Colorize;
3use std::io::{self, Write};
4use subxt::OnlineClient;
5use tokio::time::Instant;
6
7pub struct ProgressSpinner {
9 chars: Vec<char>,
10 current: usize,
11 start_time: Instant,
12}
13
14impl Default for ProgressSpinner {
15 fn default() -> Self {
16 Self::new()
17 }
18}
19
20impl ProgressSpinner {
21 pub fn new() -> Self {
22 Self { chars: vec!['|', '/', '-', '\\'], current: 0, start_time: Instant::now() }
23 }
24
25 pub fn tick(&mut self) {
26 let elapsed = self.start_time.elapsed().as_secs();
27 print!(
28 "\rš Waiting for confirmation... {} ({}s)",
29 self.chars[self.current].to_string().bright_blue(),
30 elapsed
31 );
32 io::stdout().flush().unwrap();
33 self.current = (self.current + 1) % self.chars.len();
34 }
35}
36
37pub async fn wait_for_tx_confirmation(
39 _client: &OnlineClient<ChainConfig>,
40 _tx_hash: subxt::utils::H256,
41) -> Result<bool> {
42 let mut spinner = ProgressSpinner::new();
44
45 for _ in 0..10 {
47 spinner.tick();
48 tokio::time::sleep(std::time::Duration::from_secs(1)).await;
49 }
50
51 println!();
53
54 use crate::log_verbose;
55 log_verbose!("ā
Transaction likely finalized (after 6s delay)");
56 Ok(true)
57}