Skip to content

Commit

Permalink
feat: print warning for wallets in direct send only (#5883)
Browse files Browse the repository at this point in the history
Description
---
Prints out a warning for wallets set to use direct send only

Motivation and Context
---
See: #5861 

How Has This Been Tested?
---
Manual

Fixes: #5861
  • Loading branch information
SWvheerden authored Nov 1, 2023
1 parent 1070298 commit 6d8686d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
29 changes: 29 additions & 0 deletions applications/minotari_console_wallet/src/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,35 @@ pub(crate) fn confirm_seed_words(wallet: &mut WalletSqlite) -> Result<(), ExitEr
}
}

pub(crate) fn confirm_direct_only_send(wallet: &mut WalletSqlite) -> Result<(), ExitError> {
let seed_words = wallet.get_seed_words(&MnemonicLanguage::English)?;

println!();
println!("=========================");
println!(" IMPORTANT! ");
println!("=========================");
println!("This wallet is set to use DirectOnly.");
println!("This is primarily used for testing and can result in not all messages being sent.");
println!();
println!("\x07"); // beep!

let mut rl = Editor::<()>::new();
loop {
println!("I confirm this warning.");
println!(r#"Type the word "confirm" , "yes" or "y" to continue."#);
let readline = rl.readline(">> ");
match readline {
Ok(line) => match line.to_lowercase().as_ref() {
"confirm" | "yes" | "y" => return Ok(()),
_ => continue,
},
Err(e) => {
return Err(ExitError::new(ExitCode::IOError, e));
},
}
}
}

/// Clear the terminal and print the Tari splash
pub fn tari_splash_screen(heading: &str) {
// clear the terminal
Expand Down
18 changes: 17 additions & 1 deletion applications/minotari_console_wallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub use cli::{
use init::{change_password, get_base_node_peer_config, init_wallet, start_wallet, tari_splash_screen, WalletBoot};
use log::*;
use minotari_app_utilities::{common_cli_args::CommonCliArgs, consts, network_check::is_network_choice_valid};
use minotari_wallet::transaction_service::config::TransactionRoutingMechanism;
use recovery::{get_seed_from_seed_words, prompt_private_key_from_seed_words};
use tari_common::{
configuration::bootstrap::ApplicationType,
Expand All @@ -63,7 +64,7 @@ use tokio::runtime::Runtime;
use wallet_modes::{command_mode, grpc_mode, recovery_mode, script_mode, tui_mode, WalletMode};

pub use crate::config::ApplicationConfig;
use crate::init::{boot_with_password, confirm_seed_words, wallet_mode};
use crate::init::{boot_with_password, confirm_direct_only_send, confirm_seed_words, wallet_mode};

pub const LOG_TARGET: &str = "wallet::console_wallet::main";

Expand Down Expand Up @@ -102,6 +103,7 @@ pub fn run_wallet(shutdown: &mut Shutdown, runtime: Runtime, config: &mut Applic
run_wallet_with_cli(shutdown, runtime, config, cli)
}

#[allow(clippy::too_many_lines)]
pub fn run_wallet_with_cli(
shutdown: &mut Shutdown,
runtime: Runtime,
Expand Down Expand Up @@ -169,6 +171,20 @@ pub fn run_wallet_with_cli(
cli.non_interactive_mode,
))?;

if !cli.non_interactive_mode &&
config.wallet.transaction_service_config.transaction_routing_mechanism ==
TransactionRoutingMechanism::DirectOnly
{
match confirm_direct_only_send(&mut wallet) {
Ok(()) => {
print!("\x1Bc"); // Clear the screen
},
Err(error) => {
return Err(error);
},
};
}

// if wallet is being set for the first time, wallet seed words are prompted on the screen
if !cli.non_interactive_mode && not_recovery && on_init {
match confirm_seed_words(&mut wallet) {
Expand Down

0 comments on commit 6d8686d

Please sign in to comment.