ability to copy wallet address added
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
parent
db97ad13a6
commit
9704af3978
@ -1,6 +1,7 @@
|
||||
use std::path::PathBuf;
|
||||
use std::fs::File;
|
||||
use std::io::{Write, BufRead, BufReader};
|
||||
use std::process::Command;
|
||||
|
||||
use color_eyre::Result;
|
||||
use crossterm::event::{KeyCode, KeyEvent};
|
||||
@ -113,6 +114,31 @@ impl Accounts {
|
||||
}
|
||||
}
|
||||
|
||||
fn copy_to_clipboard(&mut self) {
|
||||
if let Some(index) = self.table_state.selected() {
|
||||
let address = self.wallet_keys[index].address.clone();
|
||||
match Command::new("xclip")
|
||||
.arg("-selection")
|
||||
.arg("clipboard")
|
||||
.stdin(std::process::Stdio::piped())
|
||||
.spawn()
|
||||
.and_then(|child| Ok(child
|
||||
.stdin
|
||||
.and_then(|mut cs| cs
|
||||
.write_all(address.as_bytes())
|
||||
.ok())
|
||||
))
|
||||
{
|
||||
Ok(Some(())) => self.log_event(
|
||||
format!("address {} copied to clipboard", &address),
|
||||
ActionLevel::Warn),
|
||||
_ => self.log_event(
|
||||
"could not use `xclip` to copy".to_string(),
|
||||
ActionLevel::Error),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn create_new_account(&mut self, name: String) {
|
||||
let (pair, seed) = Pair::generate();
|
||||
let secret_seed = hex::encode(seed);
|
||||
@ -402,17 +428,20 @@ impl Component for Accounts {
|
||||
}
|
||||
|
||||
fn handle_key_event(&mut self, key: KeyEvent) -> Result<Option<Action>> {
|
||||
if self.is_active {
|
||||
match key.code {
|
||||
KeyCode::Up | KeyCode::Char('k') if self.is_active => self.previous_row(),
|
||||
KeyCode::Down | KeyCode::Char('j') if self.is_active => self.next_row(),
|
||||
KeyCode::Char('K') if self.is_active => self.swap_up(),
|
||||
KeyCode::Char('J') if self.is_active => self.swap_down(),
|
||||
KeyCode::Char('g') if self.is_active => self.first_row(),
|
||||
KeyCode::Char('G') if self.is_active => self.last_row(),
|
||||
KeyCode::Char('D') if self.is_active => self.delete_row(),
|
||||
KeyCode::Char('R') if self.is_active => self.update_account_name(),
|
||||
KeyCode::Up | KeyCode::Char('k') => self.previous_row(),
|
||||
KeyCode::Down | KeyCode::Char('j') => self.next_row(),
|
||||
KeyCode::Char('K') => self.swap_up(),
|
||||
KeyCode::Char('J') => self.swap_down(),
|
||||
KeyCode::Char('g') => self.first_row(),
|
||||
KeyCode::Char('G') => self.last_row(),
|
||||
KeyCode::Char('D') => self.delete_row(),
|
||||
KeyCode::Char('R') => self.update_account_name(),
|
||||
KeyCode::Char('Y') => self.copy_to_clipboard(),
|
||||
_ => {},
|
||||
};
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user