diff --git a/src/gui/views/network/setup/node.rs b/src/gui/views/network/setup/node.rs index ebe4041..9cca0c7 100644 --- a/src/gui/views/network/setup/node.rs +++ b/src/gui/views/network/setup/node.rs @@ -356,8 +356,8 @@ impl NodeSetup { ui.add_space(6.0); let secret_value = match modal_id { - API_SECRET_MODAL => NodeConfig::get_api_secret(), - _ => NodeConfig::get_foreign_api_secret() + API_SECRET_MODAL => NodeConfig::get_api_secret(false), + _ => NodeConfig::get_api_secret(true) }; let secret_text = if secret_value.is_some() { diff --git a/src/node/config.rs b/src/node/config.rs index 71a3af3..1673750 100644 --- a/src/node/config.rs +++ b/src/node/config.rs @@ -505,22 +505,29 @@ impl NodeConfig { } /// Get API secret text. - pub fn get_api_secret() -> Option { + pub fn get_api_secret(foreign: bool) -> Option { let r_config = Settings::node_config_to_read(); - let api_secret_path = r_config - .node - .server - .api_secret_path - .clone(); - return if let Some(secret_path) = api_secret_path { - let api_secret_file = File::open(secret_path).unwrap(); - let buf_reader = BufReader::new(api_secret_file); - let mut lines_iter = buf_reader.lines(); - let first_line = lines_iter.next().unwrap(); - Some(first_line.unwrap()) + let api_secret_path = if foreign { + &r_config + .node + .server + .foreign_api_secret_path } else { - None - }; + &r_config + .node + .server + .api_secret_path + }.clone(); + if let Some(secret_path) = api_secret_path { + if let Ok(file) = File::open(secret_path) { + let buf_reader = BufReader::new(file); + let mut lines_iter = buf_reader.lines(); + if let Some(Ok(line)) = lines_iter.next() { + return Some(line); + } + } + } + None } /// Save API secret text. @@ -528,25 +535,6 @@ impl NodeConfig { Self::save_secret(api_secret, API_SECRET_FILE_NAME); } - /// Get Foreign API secret text. - pub fn get_foreign_api_secret() -> Option { - let r_config = Settings::node_config_to_read(); - let foreign_secret_path = r_config - .node - .server - .foreign_api_secret_path - .clone(); - return if let Some(secret_path) = foreign_secret_path { - let foreign_secret_file = File::open(secret_path).unwrap(); - let buf_reader = BufReader::new(foreign_secret_file); - let mut lines_iter = buf_reader.lines(); - let first_line = lines_iter.next().unwrap(); - Some(first_line.unwrap()) - } else { - None - }; - } - /// Update Foreign API secret. pub fn save_foreign_api_secret(api_secret: &String) { Self::save_secret(api_secret, FOREIGN_API_SECRET_FILE_NAME); diff --git a/src/wallet/wallet.rs b/src/wallet/wallet.rs index 2db304e..99e4ef6 100644 --- a/src/wallet/wallet.rs +++ b/src/wallet/wallet.rs @@ -171,7 +171,7 @@ impl Wallet { // Setup node client. let integrated = || { let api_url = format!("http://{}", NodeConfig::get_api_address()); - let api_secret = NodeConfig::get_foreign_api_secret(); + let api_secret = NodeConfig::get_api_secret(true); (api_url, api_secret) }; let (node_api_url, node_secret) = if let Some(id) = config.ext_conn_id {