bugfix: properly sub to new selected acc after removal of selected
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -50,20 +50,20 @@ impl AccountCache {
|
||||
self.accounts.entry(pk).insert(account)
|
||||
}
|
||||
|
||||
pub(super) fn remove(&mut self, pk: &Pubkey) -> Option<UserAccount> {
|
||||
pub(super) fn remove(&mut self, pk: &Pubkey) -> Option<AccountDeletionResponse> {
|
||||
if *pk == self.fallback && self.accounts.len() == 1 {
|
||||
// no point in removing it since it'll just get re-added anyway
|
||||
return None;
|
||||
}
|
||||
|
||||
let removed = self.accounts.remove(pk);
|
||||
let removed = self.accounts.remove(pk)?;
|
||||
|
||||
if self.accounts.is_empty() {
|
||||
self.accounts
|
||||
.insert(self.fallback, self.fallback_account.clone());
|
||||
}
|
||||
|
||||
if removed.is_some() && self.selected == *pk {
|
||||
if self.selected == *pk {
|
||||
// TODO(kernelkind): choose next better
|
||||
let (next, _) = self
|
||||
.accounts
|
||||
@@ -71,9 +71,17 @@ impl AccountCache {
|
||||
.next()
|
||||
.expect("accounts can never be empty");
|
||||
self.selected = *next;
|
||||
|
||||
return Some(AccountDeletionResponse {
|
||||
deleted: removed.key,
|
||||
swap_to: Some(*next),
|
||||
});
|
||||
}
|
||||
|
||||
removed
|
||||
Some(AccountDeletionResponse {
|
||||
deleted: removed.key,
|
||||
swap_to: None,
|
||||
})
|
||||
}
|
||||
|
||||
/// guarenteed that all selected exist in accounts
|
||||
@@ -111,3 +119,8 @@ impl<'a> IntoIterator for &'a AccountCache {
|
||||
self.accounts.iter()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AccountDeletionResponse {
|
||||
pub deleted: enostr::Keypair,
|
||||
pub swap_to: Option<Pubkey>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user