wallet: store unlocked accounts in Vec to preserve order
This commit is contained in:
@@ -4,7 +4,7 @@ use crate::error::BackendError;
|
||||
use crate::network::Network as WalletNetwork;
|
||||
use crate::nymd_client;
|
||||
use crate::state::State;
|
||||
use crate::wallet_storage::account_data::{StoredLogin, WalletAccount};
|
||||
use crate::wallet_storage::account_data::StoredLogin;
|
||||
use crate::wallet_storage::{self, DEFAULT_WALLET_ACCOUNT_ID};
|
||||
|
||||
use bip39::{Language, Mnemonic};
|
||||
@@ -444,10 +444,9 @@ pub async fn sign_in_with_password(
|
||||
|
||||
{
|
||||
// Keep track of all accounts for that id
|
||||
let all_accounts: HashMap<String, WalletAccount> = stored_account
|
||||
let all_accounts: Vec<_> = stored_account
|
||||
.unwrap_into_multiple_accounts(id)
|
||||
.into_accounts()
|
||||
.map(|a| (a.id.to_string(), a))
|
||||
.collect();
|
||||
|
||||
let mut w_state = state.write().await;
|
||||
@@ -514,7 +513,6 @@ pub async fn list_accounts(
|
||||
|
||||
let all_accounts = state
|
||||
.get_all_accounts()
|
||||
.values()
|
||||
.map(|account| AccountEntry {
|
||||
id: account.id.to_string(),
|
||||
address: derive_address(account.account.mnemonic().clone(), prefix)
|
||||
@@ -558,13 +556,12 @@ pub async fn sign_in_decrypted_account(
|
||||
log::info!("Signing in to already decrypted account: {account_id}");
|
||||
let mnemonic = {
|
||||
let state = state.read().await;
|
||||
state
|
||||
let account = &state
|
||||
.get_all_accounts()
|
||||
.get(account_id)
|
||||
.find(|a| a.id.as_ref() == account_id)
|
||||
.ok_or(BackendError::NoSuchIdInWalletLoginEntry)?
|
||||
.account
|
||||
.mnemonic()
|
||||
.clone()
|
||||
.account;
|
||||
account.mnemonic().clone()
|
||||
};
|
||||
_connect_with_mnemonic(mnemonic, state).await
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ pub struct State {
|
||||
|
||||
// All the accounts the we get from decrypting the wallet. We hold on to these for being able to
|
||||
// switch accounts on-the-fly
|
||||
all_accounts: HashMap<String, WalletAccount>,
|
||||
all_accounts: Vec<WalletAccount>,
|
||||
|
||||
/// Validators that have been fetched dynamically, probably during startup.
|
||||
fetched_validators: OptionalValidators,
|
||||
@@ -68,13 +68,12 @@ impl State {
|
||||
self.current_network
|
||||
}
|
||||
|
||||
pub(crate) fn set_all_accounts(&mut self, all_accounts: HashMap<String, WalletAccount>) {
|
||||
self.all_accounts.clear();
|
||||
self.all_accounts.extend(all_accounts)
|
||||
pub(crate) fn set_all_accounts(&mut self, all_accounts: Vec<WalletAccount>) {
|
||||
self.all_accounts = all_accounts
|
||||
}
|
||||
|
||||
pub(crate) fn get_all_accounts(&self) -> &HashMap<String, WalletAccount> {
|
||||
&self.all_accounts
|
||||
pub(crate) fn get_all_accounts(&self) -> impl Iterator<Item = &WalletAccount> {
|
||||
self.all_accounts.iter()
|
||||
}
|
||||
|
||||
pub fn logout(&mut self) {
|
||||
|
||||
Reference in New Issue
Block a user