Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: console wallet recovery improvements for ledger #6455

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions applications/minotari_console_wallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ use tari_common::{
configuration::bootstrap::ApplicationType,
exit_codes::{ExitCode, ExitError},
};
use tari_common_types::wallet_types::WalletType;
use tari_key_manager::cipher_seed::CipherSeed;
#[cfg(all(unix, feature = "libtor"))]
use tari_libtor::tor::Tor;
Expand Down Expand Up @@ -128,8 +129,6 @@ pub fn run_wallet_with_cli(
// check for recovery based on existence of wallet file
let (mut boot_mode, password) = boot_with_password(&cli, &config.wallet)?;

let recovery_seed = get_recovery_seed(boot_mode, &cli)?;

let wallet_type = prompt_wallet_type(
boot_mode,
&config.wallet,
Expand All @@ -138,6 +137,8 @@ pub fn run_wallet_with_cli(
cli.spend_key.clone(),
);

let recovery_seed = get_recovery_seed(boot_mode, &cli, &wallet_type)?;

// get command line password if provided
let seed_words_file_name = cli.seed_words_file_name.clone();

Expand Down Expand Up @@ -168,6 +169,7 @@ pub fn run_wallet_with_cli(

let on_init = matches!(boot_mode, WalletBoot::New);
let not_recovery = recovery_seed.is_none();
let hardware_wallet = matches!(wallet_type, Some(WalletType::Ledger(_)));

// initialize wallet
let mut wallet = runtime.block_on(init_wallet(
Expand Down Expand Up @@ -195,7 +197,7 @@ pub fn run_wallet_with_cli(
}

// 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 {
if !cli.non_interactive_mode && not_recovery && on_init && !hardware_wallet {
match confirm_seed_words(&mut wallet) {
Ok(()) => {
print!("\x1Bc"); // Clear the screen
Expand Down Expand Up @@ -263,8 +265,12 @@ fn get_password(config: &ApplicationConfig, cli: &Cli) -> Option<SafePassword> {
.map(|s| s.to_owned())
}

fn get_recovery_seed(boot_mode: WalletBoot, cli: &Cli) -> Result<Option<CipherSeed>, ExitError> {
if matches!(boot_mode, WalletBoot::Recovery) {
fn get_recovery_seed(
boot_mode: WalletBoot,
cli: &Cli,
wallet_type: &Option<WalletType>,
) -> Result<Option<CipherSeed>, ExitError> {
if matches!(boot_mode, WalletBoot::Recovery) && !matches!(wallet_type, Some(WalletType::Ledger(_))) {
let seed = if let Some(ref seed_words) = cli.seed_words {
get_seed_from_seed_words(seed_words)?
} else {
Expand Down
Loading