quantus_cli/cli/
progress_spinner.rs

1use crate::{chain::client::ChainConfig, error::Result};
2use colored::Colorize;
3use std::io::{self, Write};
4use subxt::OnlineClient;
5use tokio::time::Instant;
6
7/// Simple progress spinner for showing waiting status
8pub 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
37/// Common function to wait for transaction finalization using ProgressSpinner
38pub async fn wait_for_tx_confirmation(
39	_client: &OnlineClient<ChainConfig>,
40	_tx_hash: subxt::utils::H256,
41) -> Result<bool> {
42	// Use ProgressSpinner to show waiting progress
43	let mut spinner = ProgressSpinner::new();
44
45	// For now, we use a simple delay approach similar to substrate-api-client
46	for _ in 0..10 {
47		spinner.tick();
48		tokio::time::sleep(std::time::Duration::from_secs(1)).await;
49	}
50
51	// Clear the spinner line and add newline
52	println!();
53
54	use crate::log_verbose;
55	log_verbose!("āœ… Transaction likely finalized (after 6s delay)");
56	Ok(true)
57}