allow removal of Damoose account

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-07-17 19:24:33 -04:00
parent b9cae65b72
commit 8daa1d2adf

View File

@@ -6,6 +6,7 @@ use crate::{SingleUnkIdAction, UserAccount};
pub struct AccountCache {
selected: Pubkey,
fallback: Pubkey,
fallback_account: UserAccount,
// never empty at rest
accounts: HashMap<Pubkey, UserAccount>,
@@ -16,12 +17,13 @@ impl AccountCache {
let mut accounts = HashMap::with_capacity(1);
let pk = fallback.key.pubkey;
accounts.insert(pk, fallback);
accounts.insert(pk, fallback.clone());
(
Self {
selected: pk,
fallback: pk,
fallback_account: fallback,
accounts,
},
SingleUnkIdAction::pubkey(pk),
@@ -49,13 +51,18 @@ impl AccountCache {
}
pub(super) fn remove(&mut self, pk: &Pubkey) -> Option<UserAccount> {
// fallback account should never be removed
if *pk == self.fallback {
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);
if self.accounts.is_empty() {
self.accounts
.insert(self.fallback, self.fallback_account.clone());
}
if removed.is_some() && self.selected == *pk {
// TODO(kernelkind): choose next better
let (next, _) = self