gui: implement Daemon.update_wallet_metadata() for lianad

This commit is contained in:
pythcoiner 2025-03-08 19:10:51 +01:00
parent 6988fa40c9
commit 02e28bbd3e
No known key found for this signature in database
GPG Key ID: C1048AEEDF303B88
2 changed files with 43 additions and 2 deletions

View File

@ -107,6 +107,25 @@ impl WalletSetting {
}
map
}
pub fn update_alias(&mut self, key: &Fingerprint, alias: &str) {
let key_aliases = self.keys_aliases();
if key_aliases.contains_key(key) {
self.keys = self
.keys
.clone()
.into_iter()
.map(|mut ks| {
if ks.master_fingerprint == *key {
ks.name = alias.into();
ks
} else {
ks
}
})
.collect();
}
}
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, Hash)]

View File

@ -21,6 +21,7 @@ use lianad::{
StartupError,
};
use crate::app::settings::Settings;
use crate::{hw::HardwareWalletConfig, node};
#[derive(Debug)]
@ -364,12 +365,33 @@ pub trait Daemon: Debug {
Ok(events)
}
/// Implemented by LianaLite backend
/// Reimplemented by LianaLite backend
async fn update_wallet_metadata(
&self,
_fingerprint_aliases: &HashMap<Fingerprint, String>,
fingerprint_aliases: &HashMap<Fingerprint, String>,
_hws: &[HardwareWalletConfig],
) -> Result<(), DaemonError> {
if let Some(datadir) = self
.config()
.ok_or(DaemonError::Unexpected("Config missing".into()))?
.data_dir()
{
let network = self.get_info().await?.network;
let mut settings = Settings::from_file(datadir, network)
.map_err(|_| DaemonError::Unexpected("Fail to read Settings from file".into()))?;
let wallet = if settings.wallets.len() == 1 {
settings.wallets.get_mut(0).expect("already checked")
} else {
return Err(DaemonError::Unexpected(
"Settings file contains more than one wallet".into(),
));
};
for fg in wallet.keys_aliases().keys() {
if fingerprint_aliases.contains_key(fg) {
wallet.update_alias(fg, fingerprint_aliases.get(fg).expect("checked"));
}
}
}
Ok(())
}
}