From 53a96e567d0729f8145e7db0eb16c633efaf59fc Mon Sep 17 00:00:00 2001 From: ardocrat Date: Wed, 4 Jun 2025 15:33:34 +0300 Subject: [PATCH] wallet: sort accounts to show current first --- src/wallet/wallet.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/wallet/wallet.rs b/src/wallet/wallet.rs index 421ed72a..2a95fff9 100644 --- a/src/wallet/wallet.rs +++ b/src/wallet/wallet.rs @@ -504,6 +504,7 @@ impl Wallet { label: label.clone(), path: id.to_bip_32_string(), }); + w_data.sort_by_key(|w| w.label != label.clone()); } Ok(()) }) @@ -1491,10 +1492,11 @@ fn start_api_server(wallet: &Wallet) -> Result<(ApiServer, u16), Error> { /// Update wallet accounts data. fn update_accounts(wallet: &Wallet, current_height: u64, current_spendable: Option) { + let current_account = wallet.get_config().account; if let Some(spendable) = current_spendable { let mut accounts = wallet.accounts.read().clone(); for a in accounts.iter_mut() { - if a.label == wallet.get_config().account { + if a.label == current_account { a.spendable_amount = spendable; } } @@ -1518,15 +1520,14 @@ fn update_accounts(wallet: &Wallet, current_height: u64, current_spendable: Opti }); } } - // Sort in reverse. - accounts.reverse(); + accounts.sort_by_key(|w| w.label != current_account); // Save accounts data. let mut w_data = wallet.accounts.write(); *w_data = accounts; // Set current active account from config. - api.set_active_account(m, wallet.get_config().account.as_str())?; + api.set_active_account(m, current_account.as_str())?; Ok(()) });