Set wallet alias in settings if liana-connect wallet alias changed

This commit is contained in:
edouardparis 2025-05-20 11:09:00 +02:00
parent 36fb3d8775
commit 51d913b9ef

View File

@ -22,7 +22,13 @@ use liana_ui::{component::text, font, image, theme, widget::Element};
use lianad::commands::ListCoinsResult;
use liana_gui::{
app::{self, cache::Cache, settings::WalletSettings, wallet::Wallet, App},
app::{
self,
cache::Cache,
settings::{update_settings_file, WalletSettings},
wallet::Wallet,
App,
},
dir::LianaDirectory,
export::import_backup_at_launch,
hw::HardwareWalletConfig,
@ -428,10 +434,32 @@ pub fn create_app_with_remote_backend(
remote_backend: BackendWalletClient,
wallet: api::Wallet,
coins: ListCoinsResult,
datadir: LianaDirectory,
liana_dir: LianaDirectory,
network: bitcoin::Network,
config: app::Config,
) -> (app::App, iced::Task<app::Message>) {
// If someone modified the wallet_alias on Liana-Connect,
// then the new alias is imported and stored in the settings file.
if wallet.metadata.wallet_alias != wallet_settings.alias {
let network_directory = liana_dir.network_directory(network);
if let Err(e) = tokio::runtime::Handle::current().block_on(async {
update_settings_file(&network_directory, |mut settings| {
if let Some(w) = settings
.wallets
.iter_mut()
.find(|w| w.wallet_id() == wallet_settings.wallet_id())
{
w.alias = wallet.metadata.wallet_alias.clone();
tracing::info!("Wallet alias was changed. Settings updated.");
}
settings
})
.await
}) {
tracing::error!("Failed to update wallet settings with remote alias: {}", e);
}
}
let hws: Vec<HardwareWalletConfig> = wallet
.metadata
.ledger_hmacs
@ -460,13 +488,14 @@ pub fn create_app_with_remote_backend(
.into_iter()
.map(|pk| (pk.fingerprint, pk.into()))
.collect();
App::new(
Cache {
network,
coins: coins.coins,
rescan_progress: None,
sync_progress: 1.0, // Remote backend is always synced
datadir_path: datadir.clone(),
datadir_path: liana_dir.clone(),
blockheight: wallet.tip_height.unwrap_or(0),
// We ignore last poll fields for remote backend.
last_poll_timestamp: None,
@ -475,17 +504,17 @@ pub fn create_app_with_remote_backend(
Arc::new(
Wallet::new(wallet.descriptor)
.with_name(wallet.name)
.with_alias(wallet_settings.alias)
.with_alias(wallet.metadata.wallet_alias)
.with_pinned_at(wallet_settings.pinned_at)
.with_key_aliases(aliases)
.with_provider_keys(provider_keys)
.with_hardware_wallets(hws)
.load_hotsigners(&datadir, network)
.load_hotsigners(&liana_dir, network)
.expect("Datadir should be conform"),
),
config,
Arc::new(remote_backend),
datadir,
liana_dir,
None,
false,
)