leo_lang/cli/commands/common/
interactive.rs1use super::*;
18use leo_ast::NetworkName;
19
20pub fn confirm(prompt: &str, skip_confirmation: bool) -> Result<bool> {
22 if skip_confirmation {
23 return Ok(true);
24 }
25
26 let result = Confirm::with_theme(&ColorfulTheme::default())
27 .with_prompt(prompt)
28 .default(false)
29 .interact()
30 .map_err(|e| CliError::custom(format!("Failed to prompt user: {e}")).into());
31
32 println!();
34
35 result
36}
37
38pub fn confirm_fee<N: Network>(
40 fee: &snarkvm::prelude::Fee<N>,
41 private_key: &PrivateKey<N>,
42 address: &Address<N>,
43 endpoint: &str,
44 network: NetworkName,
45 context: &Context,
46 skip: bool,
47) -> Result<bool> {
48 let total_cost = (*fee.amount()? as f64) / 1_000_000.0;
50 if fee.is_fee_public() {
51 let public_balance = get_public_balance(private_key, endpoint, network, context)? as f64 / 1_000_000.0;
52 println!("💰Your current public balance is {public_balance} credits.\n");
53 if public_balance < total_cost {
54 return Err(PackageError::insufficient_balance(address, public_balance, total_cost).into());
55 }
56 }
57 confirm(&format!("This transaction will cost you {total_cost} credits. Do you want to proceed?"), skip)
59}