wallet: contructors for DecryptedAccount

This commit is contained in:
Jon Häggblad
2022-04-29 15:36:06 +02:00
parent a7caf97b73
commit 05374393ef
2 changed files with 20 additions and 18 deletions
@@ -442,29 +442,17 @@ pub async fn sign_in_with_password(
}
};
// Keep track of all accounts
// WIP(JON): simplify
// Keep track of all accounts for that id
let all_accounts: HashMap<_, _> = match stored_account {
StoredLogin::Mnemonic(ref account) => [(
id.to_string(),
DecryptedAccount {
id: id.to_string(),
mnemonic: account.mnemonic().clone(),
},
DecryptedAccount::new(id.to_string(), account.mnemonic().clone()),
)]
.into_iter()
.collect(),
StoredLogin::Multiple(ref accounts) => accounts
.get_accounts()
.map(|account| {
(
account.id.to_string(),
DecryptedAccount {
id: account.id.to_string(),
mnemonic: account.account.mnemonic().clone(),
},
)
})
.map(|account| (account.id.to_string(), account.into()))
.collect(),
};
{
+17 -3
View File
@@ -1,8 +1,8 @@
use crate::config::{Config, OptionalValidators, ValidatorUrl};
use crate::error::BackendError;
use crate::network::Network;
use crate::wallet_storage::account_data::WalletAccount;
use bip39::Mnemonic;
use strum::IntoEnumIterator;
use validator_client::nymd::SigningNymdClient;
use validator_client::Client;
@@ -180,8 +180,22 @@ macro_rules! client {
#[derive(Clone)]
pub(crate) struct DecryptedAccount {
pub id: String,
pub mnemonic: Mnemonic,
// address: String
pub mnemonic: bip39::Mnemonic,
}
impl DecryptedAccount {
pub fn new(id: String, mnemonic: bip39::Mnemonic) -> Self {
Self { id, mnemonic }
}
}
impl From<&WalletAccount> for DecryptedAccount {
fn from(wallet_account: &WalletAccount) -> Self {
Self {
id: wallet_account.id.to_string(),
mnemonic: wallet_account.account.mnemonic().clone(),
}
}
}
#[macro_export]