fix: external connection deletion

This commit is contained in:
ardocrat
2025-04-23 15:10:48 +03:00
parent f1f0f002ce
commit 43720b34ba
6 changed files with 37 additions and 56 deletions
+1 -3
View File
@@ -121,9 +121,7 @@ impl WalletConfig {
pub fn connection(&self) -> ConnectionMethod {
if let Some(ext_conn_id) = self.ext_conn_id {
if let Some(conn) = ConnectionsConfig::ext_conn(ext_conn_id) {
if !conn.deleted {
return ConnectionMethod::External(conn.id, conn.url);
}
return ConnectionMethod::External(conn.id, conn.url);
}
}
ConnectionMethod::Integrated
+3 -15
View File
@@ -49,13 +49,7 @@ impl ConnectionsConfig {
/// Save connections configuration.
pub fn save(&mut self) {
// Check deleted external connections.
let mut config = self.clone();
config.external = config.external.iter()
.map(|c| c.clone())
.filter(|c| !c.deleted)
.collect::<Vec<ExternalConnection>>();
let config = self.clone();
let sub_dir = Some(AppConfig::chain_type().shortname());
Settings::write_to_file(&config, Settings::config_path(Self::FILE_NAME, sub_dir));
}
@@ -106,13 +100,7 @@ impl ConnectionsConfig {
/// Remove [`ExternalConnection`] with provided identifier.
pub fn remove_ext_conn(id: i64) {
let mut w_config = Settings::conn_config_to_update();
if let Some(pos) = w_config.external.iter().position(|c| {
c.id == id
}) {
if let Some(conn) = w_config.external.get_mut(pos) {
conn.deleted = true;
w_config.save();
}
}
w_config.external = w_config.external.iter().filter(|c| c.id != id).cloned().collect();
w_config.save();
}
}
-6
View File
@@ -31,10 +31,6 @@ pub struct ExternalConnection {
/// Flag to check if server is available.
#[serde(skip_serializing, skip_deserializing)]
pub available: Option<bool>,
/// Flag to check if connection was deleted.
#[serde(skip_serializing, skip_deserializing)]
pub deleted: bool
}
/// Default external node URL for main network.
@@ -61,7 +57,6 @@ impl ExternalConnection {
url: url.to_string(),
secret: None,
available: None,
deleted: false,
}
}).collect::<Vec<ExternalConnection>>()
}
@@ -74,7 +69,6 @@ impl ExternalConnection {
url,
secret,
available: None,
deleted: false
}
}