Migrate to new AccountManagementView conception
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
committed by
William Casarin
parent
2ca47edf4d
commit
f489ed3b9e
@@ -1,3 +1,5 @@
|
||||
use std::cmp::Ordering;
|
||||
|
||||
use enostr::FullKeypair;
|
||||
|
||||
pub use crate::user_account::UserAccount;
|
||||
@@ -51,9 +53,19 @@ impl AccountManager {
|
||||
pub fn remove_account(&mut self, index: usize) {
|
||||
if let Some(account) = self.accounts.get(index) {
|
||||
let _ = self.key_store.remove_key(&account.key);
|
||||
}
|
||||
if index < self.accounts.len() {
|
||||
self.accounts.remove(index);
|
||||
|
||||
if let Some(selected_index) = self.currently_selected_account {
|
||||
match selected_index.cmp(&index) {
|
||||
Ordering::Greater => {
|
||||
self.select_account(selected_index - 1);
|
||||
}
|
||||
Ordering::Equal => {
|
||||
self.clear_selected_account();
|
||||
}
|
||||
Ordering::Less => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,4 +96,8 @@ impl AccountManager {
|
||||
self.currently_selected_account = Some(index)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clear_selected_account(&mut self) {
|
||||
self.currently_selected_account = None
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user