Skip to content

Commit

Permalink
UX minor improvements for wallet CLI (#627)
Browse files Browse the repository at this point in the history
* fix: add more ux info

* fix: make aliases visible in help

* fix: cli parsing errors when multiple spaces are given

* fix: add error message about init for wallet

* fix: after merge
  • Loading branch information
qrayven authored Jun 23, 2023
1 parent c7b37f4 commit 6525c4f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cli/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub async fn account_prompt_internal(account: Account, history: &mut AccountHist
_ => {
// Prepend `Account: ` so the parsing will be correct
let command = format!("Account: {}", command.trim());
let account_cli = match AccountCli::try_parse_from(command.split(' ')) {
let account_cli = match AccountCli::try_parse_from(command.split_whitespace()) {
Ok(account_cli) => account_cli,
Err(err) => {
println!("{err}");
Expand Down
5 changes: 2 additions & 3 deletions cli/src/command/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ pub enum AccountCommand {
/// Synchronize the account.
Sync,
/// Show the details of the transaction.
#[clap(alias = "tx")]
#[clap(visible_alias = "tx")]
Transaction {
/// Transaction ID to be displayed e.g. 0x84fe6b1796bddc022c9bc40206f0a692f4536b02aa8c13140264e2e01a3b7e4b.
transaction_id: String,
},
/// List the account transactions.
#[clap(alias = "txs")]
#[clap(visible_alias = "txs")]
Transactions {
/// List account transactions with all details.
#[arg(long, default_value_t = false)]
Expand Down Expand Up @@ -576,7 +576,6 @@ pub async fn mint_nft_command(
.with_tag(tag)
.with_sender(sender)
.with_issuer(issuer);

let transaction = account.mint_nfts([nft_options], None).await?;

println_log_info!(
Expand Down
14 changes: 10 additions & 4 deletions cli/src/command/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use log::LevelFilter;
use crate::{
error::Error,
helper::{check_file_exists, enter_or_generate_mnemonic, generate_mnemonic, get_password, import_mnemonic},
println_log_info,
println_log_error, println_log_info,
};

const DEFAULT_LOG_LEVEL: &str = "debug";
Expand Down Expand Up @@ -123,6 +123,8 @@ pub async fn change_password_command(storage_path: &Path, snapshot_path: &Path)
let new_password = get_password("Stronghold new password", true)?;
wallet.change_stronghold_password(password, new_password).await?;

println_log_info!("The password has been changed");

Ok(wallet)
}

Expand Down Expand Up @@ -267,13 +269,17 @@ pub async fn unlock_wallet(
None
};

let wallet = Wallet::builder()
let maybe_wallet = Wallet::builder()
.with_secret_manager(secret_manager)
.with_storage_path(storage_path.to_str().expect("invalid unicode"))
.finish()
.await?;
.await;

Ok(wallet)
if let Err(iota_sdk::wallet::Error::MissingParameter(_)) = maybe_wallet {
println_log_error!("Please make sure the wallet is initialized.");
}

Ok(maybe_wallet?)
}

pub async fn add_account(wallet: &Wallet, alias: Option<String>) -> Result<String, Error> {
Expand Down
1 change: 1 addition & 0 deletions cli/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub fn get_password(prompt: &str, confirmation: bool) -> Result<Password, Error>
password.with_prompt(prompt);

if confirmation {
password.with_prompt("Provide a new Stronghold password");
password.with_confirmation("Confirm password", "Password mismatch");
}

Expand Down

0 comments on commit 6525c4f

Please sign in to comment.