Sort device paths for select (#8896)

This commit is contained in:
Tyera Eulberg 2020-03-16 18:23:21 -06:00 committed by GitHub
parent bfca226964
commit 2237f47b90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

View File

@ -433,13 +433,16 @@ pub fn get_ledger_from_info(
return Err(device.error.clone().unwrap()); return Err(device.error.clone().unwrap());
} }
} }
let (pubkeys, device_paths): (Vec<Pubkey>, Vec<String>) = matches let mut matches: Vec<(Pubkey, String)> = matches
.filter(|&device_info| device_info.error.is_none()) .filter(|&device_info| device_info.error.is_none())
.map(|device_info| (device_info.pubkey, device_info.get_pretty_path())) .map(|device_info| (device_info.pubkey, device_info.get_pretty_path()))
.unzip(); .collect();
if pubkeys.is_empty() { if matches.is_empty() {
return Err(RemoteWalletError::NoDeviceFound); return Err(RemoteWalletError::NoDeviceFound);
} }
matches.sort_by(|a, b| a.1.cmp(&b.1));
let (pubkeys, device_paths): (Vec<Pubkey>, Vec<String>) = matches.into_iter().unzip();
let wallet_base_pubkey = if pubkeys.len() > 1 { let wallet_base_pubkey = if pubkeys.len() > 1 {
let selection = Select::with_theme(&ColorfulTheme::default()) let selection = Select::with_theme(&ColorfulTheme::default())
.with_prompt(&format!( .with_prompt(&format!(