notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit fcec3b4c8e9f2b8f21499a3a581e3029d48b2247
parent e6d9de2b99825217f856a45543296a9af9ecd7f7
Author: kernelkind <kernelkind@gmail.com>
Date:   Tue, 22 Apr 2025 17:52:00 -0400

accounts: check if selected account has wallet

Signed-off-by: kernelkind <kernelkind@gmail.com>

Diffstat:
Mcrates/notedeck/src/accounts.rs | 21+++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/crates/notedeck/src/accounts.rs b/crates/notedeck/src/accounts.rs @@ -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))?