Skip to content

Commit

Permalink
Add select for multiple wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyera Eulberg committed Jan 31, 2020
1 parent d69ace5 commit bad3bc9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions keygen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ edition = "2018"
[dependencies]
bs58 = "0.3.0"
clap = "2.33"
dialoguer = "0.5.0"
dirs = "2.0.2"
num_cpus = "1.12.0"
rpassword = "4.0"
Expand Down
34 changes: 28 additions & 6 deletions keygen/src/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use clap::{
crate_description, crate_name, value_t, values_t_or_exit, App, AppSettings, Arg, ArgMatches,
SubCommand,
};
use dialoguer::{theme::ColorfulTheme, Select};
use num_cpus;
use solana_clap_utils::{
input_parsers::{derivation_of, pubkey_of},
Expand Down Expand Up @@ -396,21 +397,42 @@ fn main() -> Result<(), Box<dyn error::Error>> {
}
let wallet_base_pubkey =
pubkey_of(matches, "wallet_base_pubkey").unwrap_or_else(|| {
let devices = wallet_manager.list_devices();
if device_count > 1 {
// TODO: Prompt for choice
println!("Choosing between multiple wallets currently not supported");
exit(1);
let select_devices: Vec<String> = devices
.iter()
.map(|device_info| {
format!(
"{}, {}, base pubkey: {:?}",
device_info.manufacturer,
device_info.name,
device_info.pubkey
)
})
.collect();

let selection = Select::with_theme(&ColorfulTheme::default())
.with_prompt(
"Multiple hardware wallets found. Please select a device",
)
.default(0)
.items(&select_devices[..])
.interact()
.unwrap();
devices[selection].pubkey
} else {
devices[0].pubkey
}
wallet_manager.list_devices()[0].pubkey
});

let ledger = wallet_manager.get_ledger(&wallet_base_pubkey).unwrap_or_else(|_| {
println!("Wallet {:?} not found. Make sure the Solana Wallet app is still running.", wallet_base_pubkey);
exit(1);
});
let wallet_info = wallet_manager.get_wallet_info(&wallet_base_pubkey).unwrap();
println!(
"Getting key from wallet: {:?}",
wallet_manager.get_wallet_info(&wallet_base_pubkey).unwrap()
"Getting key from wallet: {}, {}, {:?}",
wallet_info.manufacturer, wallet_info.name, wallet_info.pubkey
);

let derivation = derivation_of(matches, "derivation")
Expand Down

0 comments on commit bad3bc9

Please sign in to comment.