mirror of
https://code.gri.mw/GUI/grim.git
synced 2026-07-12 09:48:55 +00:00
fix: external connection deletion
This commit is contained in:
@@ -105,7 +105,7 @@ impl ConnectionsContent {
|
||||
let ext_conn_size = ext_conn_list.len();
|
||||
if ext_conn_size != 0 {
|
||||
ui.add_space(8.0);
|
||||
for (index, conn) in ext_conn_list.iter().filter(|c| !c.deleted).enumerate() {
|
||||
for (index, conn) in ext_conn_list.iter().enumerate() {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
// Draw connection list item.
|
||||
Self::ext_conn_item_ui(ui, conn, index, ext_conn_size, |ui| {
|
||||
|
||||
@@ -104,10 +104,7 @@ impl WalletConnectionModal {
|
||||
|
||||
if !ext_conn_list.is_empty() {
|
||||
ui.add_space(8.0);
|
||||
for (index, conn) in ext_conn_list.iter().filter(|c| !c.deleted).enumerate() {
|
||||
if conn.deleted {
|
||||
continue;
|
||||
}
|
||||
for (index, conn) in ext_conn_list.iter().enumerate() {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
let len = ext_conn_list.len();
|
||||
ConnectionsContent::ext_conn_item_ui(ui, conn, index, len, |ui| {
|
||||
|
||||
@@ -74,7 +74,7 @@ impl ConnectionSettings {
|
||||
|
||||
/// Draw existing wallet connection setup content.
|
||||
pub fn wallet_ui(&mut self, ui: &mut egui::Ui, wallet: &Wallet, cb: &dyn PlatformCallbacks) {
|
||||
self.method = wallet.get_current_connection();
|
||||
self.method = wallet.get_current_connection();
|
||||
|
||||
// Draw setup content.
|
||||
let changed = self.ui(ui, cb);
|
||||
@@ -133,31 +133,39 @@ impl ConnectionSettings {
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
|
||||
// Check if it's current method.
|
||||
let is_current = |m: &ConnectionMethod, c: &ExternalConnection| -> Option<bool> {
|
||||
match m {
|
||||
ConnectionMethod::External(id, _) => if c.deleted && *id == c.id {
|
||||
None
|
||||
} else {
|
||||
Some(*id == c.id)
|
||||
},
|
||||
_ => Some(false)
|
||||
// Check for removed active connection.
|
||||
let cur_method = &self.method.clone();
|
||||
let mut ext_conn_list = ConnectionsConfig::ext_conn_list();
|
||||
let has_method = !ext_conn_list.iter().filter(|c| {
|
||||
match cur_method {
|
||||
ConnectionMethod::Integrated => true,
|
||||
ConnectionMethod::External(id, url) => id == &c.id || url == &c.url
|
||||
}
|
||||
};
|
||||
}).collect::<Vec<&ExternalConnection>>().is_empty();
|
||||
if !has_method {
|
||||
match cur_method {
|
||||
ConnectionMethod::External(id, url) => {
|
||||
ext_conn_list.push(ExternalConnection {
|
||||
id: *id,
|
||||
url: url.clone(),
|
||||
secret: None,
|
||||
available: Some(true),
|
||||
})
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
let method = &self.method.clone();
|
||||
let ext_conn_list = ConnectionsConfig::ext_conn_list();
|
||||
let ext_list = ext_conn_list.iter().filter(|c| {
|
||||
!c.deleted || is_current(method, c).unwrap_or(true)
|
||||
}).collect::<Vec<&ExternalConnection>>();
|
||||
let ext_size = ext_list.len();
|
||||
let ext_size = ext_conn_list.len();
|
||||
if ext_size != 0 {
|
||||
ui.add_space(8.0);
|
||||
|
||||
for (i, c) in ext_list.iter().enumerate() {
|
||||
for (i, c) in ext_conn_list.iter().enumerate() {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
// Draw external connection item.
|
||||
let is_current = is_current(method, c);
|
||||
let is_current = match cur_method {
|
||||
ConnectionMethod::External(id, url) => id == &c.id || url == &c.url,
|
||||
_ => false
|
||||
};
|
||||
Self::ext_conn_item_ui(ui, c, is_current, i, ext_size, || {
|
||||
self.method = ConnectionMethod::External(c.id, c.url.clone());
|
||||
changed = true;
|
||||
@@ -172,7 +180,7 @@ impl ConnectionSettings {
|
||||
/// Draw external connection item content.
|
||||
fn ext_conn_item_ui(ui: &mut egui::Ui,
|
||||
conn: &ExternalConnection,
|
||||
is_current: Option<bool>,
|
||||
is_current: bool,
|
||||
index: usize,
|
||||
len: usize,
|
||||
mut on_select: impl FnMut()) {
|
||||
@@ -187,7 +195,7 @@ impl ConnectionSettings {
|
||||
|
||||
ui.vertical(|ui| {
|
||||
ui.allocate_ui_with_layout(rect.size(), Layout::right_to_left(Align::Center), |ui| {
|
||||
if is_current.unwrap_or(true) {
|
||||
if is_current {
|
||||
ui.add_space(12.0);
|
||||
ui.label(RichText::new(CHECK_FAT).size(20.0).color(Colors::green()));
|
||||
} else {
|
||||
@@ -210,11 +218,7 @@ impl ConnectionSettings {
|
||||
// Setup connection status text.
|
||||
let status_text = if let Some(available) = conn.available {
|
||||
if available {
|
||||
format!("{} {}", CHECK_CIRCLE, if is_current.is_none() {
|
||||
t!("transport.connected")
|
||||
} else {
|
||||
t!("network.available")
|
||||
})
|
||||
format!("{} {}", CHECK_CIRCLE, t!("network.available"))
|
||||
} else {
|
||||
format!("{} {}", X_CIRCLE, t!("network.not_available"))
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user