accounts: check if selected account has wallet

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-04-22 17:52:00 -04:00
parent e6d9de2b99
commit fcec3b4c8e

View File

@@ -485,26 +485,31 @@ impl Accounts {
}
}
pub fn update_current_account(&mut self, update: impl FnOnce(&mut UserAccount)) {
/// Update the `UserAccount` via callback and save the result to disk.
/// return true if the update was successful
pub fn update_current_account(&mut self, update: impl FnOnce(&mut UserAccount)) -> bool {
{
let Some(cur_account) = self.get_selected_account_mut() else {
return;
return false;
};
update(cur_account);
}
let Some(cur_acc) = self.get_selected_account() else {
return;
return false;
};
let Some(key_store) = &self.key_store else {
return;
return false;
};
if let Err(err) = key_store.write_account(cur_acc) {
tracing::error!("Could not add account {:?} to storage: {err}", cur_acc.key);
return false;
}
true
}
pub fn num_accounts(&self) -> usize {
@@ -536,6 +541,14 @@ impl Accounts {
.map(|i| self.get_account(i))?
}
pub fn selected_account_has_wallet(&self) -> bool {
if let Some(acc) = self.get_selected_account() {
return acc.wallet.is_some();
}
false
}
pub fn get_selected_account_mut(&mut self) -> Option<&mut UserAccount> {
self.currently_selected_account
.map(|i| self.get_account_mut(i))?