update to log in
- next up fix hyperlinks
This commit is contained in:
Generated
+1160
-1184
File diff suppressed because it is too large
Load Diff
@@ -35,6 +35,7 @@ futures = "0.3.15"
|
||||
itertools = "0.10"
|
||||
log = { version = "0.4", features = ["serde"] }
|
||||
once_cell = "1.7.2"
|
||||
open = "3.2"
|
||||
pretty_env_logger = "0.4"
|
||||
reqwest = { version = "0.12.4", features = ["json"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -11,7 +11,6 @@ use nym_validator_client::nyxd::AccountId as CosmosAccountId;
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::IntoEnumIterator;
|
||||
use tauri::Manager;
|
||||
use url::Url;
|
||||
|
||||
use nym_config::defaults::{DenomDetailsOwned, NymNetworkDetails, ValidatorDetails};
|
||||
@@ -105,35 +104,42 @@ impl NetworkConfig {
|
||||
}
|
||||
|
||||
impl Config {
|
||||
fn root_directory(app_handle: &tauri::AppHandle) -> PathBuf {
|
||||
app_handle
|
||||
.path()
|
||||
.local_data_dir()
|
||||
.expect("Failed to get config directory")
|
||||
fn root_directory() -> PathBuf {
|
||||
// tauri v1 (via `tauri::api::path::config_dir()`) was internally calling `dirs_next::config_dir()`
|
||||
// which ultimately was getting resolved to
|
||||
// - **Linux:** Resolves to `$XDG_CONFIG_HOME` or `$HOME/.config`.
|
||||
// - **macOS:** Resolves to `$HOME/Library/Application Support`.
|
||||
// - **Windows:** Resolves to `{FOLDERID_RoamingAppData}`.
|
||||
//
|
||||
// tauri v2 calls `dirs::config_dir().ok_or(Error::UnknownPath)` which ultimately does the same thing,
|
||||
// however, it changed its API so that it's called on a `PathResolver`.
|
||||
// but, to instantiate one here would be a hassle as we don't need those specific functionalities,
|
||||
// so let's just recreate tauri's behaviour
|
||||
dirs::config_dir().expect("Failed to get config directory")
|
||||
}
|
||||
|
||||
fn config_directory(app_handle: &tauri::AppHandle) -> PathBuf {
|
||||
Self::root_directory(app_handle).join(CONFIG_DIR_NAME)
|
||||
fn config_directory() -> PathBuf {
|
||||
Self::root_directory().join(CONFIG_DIR_NAME)
|
||||
}
|
||||
|
||||
fn config_file_path(app_handle: &tauri::AppHandle, network: Option<WalletNetwork>) -> PathBuf {
|
||||
fn config_file_path(network: Option<WalletNetwork>) -> PathBuf {
|
||||
if let Some(network) = network {
|
||||
let network_filename = format!("{}.toml", network.as_key());
|
||||
Self::config_directory(app_handle).join(network_filename)
|
||||
Self::config_directory().join(network_filename)
|
||||
} else {
|
||||
Self::config_directory(app_handle).join(CONFIG_FILENAME)
|
||||
Self::config_directory().join(CONFIG_FILENAME)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn save_to_files(&self, app_handle: &tauri::AppHandle) -> io::Result<()> {
|
||||
pub fn save_to_files(&self) -> io::Result<()> {
|
||||
log::trace!("Config::save_to_file");
|
||||
|
||||
// Make sure the whole directory structure actually exists
|
||||
fs::create_dir_all(Self::config_directory(app_handle))?;
|
||||
fs::create_dir_all(Self::config_directory())?;
|
||||
|
||||
// Global config
|
||||
if let Some(global) = &self.global {
|
||||
let location = Self::config_file_path(app_handle, None);
|
||||
let location = Self::config_file_path(None);
|
||||
|
||||
match toml::to_string_pretty(&global)
|
||||
.map_err(|toml_err| io::Error::new(io::ErrorKind::Other, toml_err))
|
||||
@@ -154,7 +160,7 @@ impl Config {
|
||||
}
|
||||
};
|
||||
|
||||
let location = Self::config_file_path(app_handle, Some(network));
|
||||
let location = Self::config_file_path(Some(network));
|
||||
match toml::to_string_pretty(config)
|
||||
.map_err(|toml_err| io::Error::new(io::ErrorKind::Other, toml_err))
|
||||
.map(|toml| fs::write(location.clone(), toml))
|
||||
@@ -166,10 +172,10 @@ impl Config {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn load_from_files(app_handle: &tauri::AppHandle) -> Self {
|
||||
pub fn load_from_files() -> Self {
|
||||
// Global
|
||||
let global = {
|
||||
let file = Self::config_file_path(app_handle, None);
|
||||
let file = Self::config_file_path(None);
|
||||
match load_from_file::<GlobalConfig>(file.clone()) {
|
||||
Ok(global) => {
|
||||
log::debug!("Loaded from file {:#?}", file);
|
||||
@@ -185,7 +191,7 @@ impl Config {
|
||||
// One file per network
|
||||
let mut networks = HashMap::new();
|
||||
for network in WalletNetwork::iter() {
|
||||
let file = Self::config_file_path(app_handle, Some(network));
|
||||
let file = Self::config_file_path(Some(network));
|
||||
match load_from_file::<NetworkConfig>(file.clone()) {
|
||||
Ok(config) => {
|
||||
log::trace!("Loaded from file {:#?}", file);
|
||||
@@ -265,8 +271,6 @@ impl Config {
|
||||
}
|
||||
}
|
||||
|
||||
////////
|
||||
|
||||
pub fn select_nyxd_url(&mut self, nyxd_url: Url, network: WalletNetwork) {
|
||||
if let Some(net) = self.networks.get_mut(&network.as_key()) {
|
||||
net.selected_nyxd_url = Some(nyxd_url);
|
||||
@@ -537,145 +541,145 @@ impl From<NymNetworkDetails> for NetworkDetails {
|
||||
}
|
||||
}
|
||||
|
||||
// #[cfg(test)]
|
||||
// mod tests {
|
||||
// use super::*;
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
// fn test_config() -> Config {
|
||||
// let netconfig = NetworkConfig {
|
||||
// selected_nyxd_url: None,
|
||||
// selected_api_url: Some("https://my_api_url.com".parse().unwrap()),
|
||||
fn test_config() -> Config {
|
||||
let netconfig = NetworkConfig {
|
||||
selected_nyxd_url: None,
|
||||
selected_api_url: Some("https://my_api_url.com".parse().unwrap()),
|
||||
|
||||
// nyxd_urls: Some(vec![
|
||||
// ValidatorConfigEntry {
|
||||
// nyxd_url: "https://foo".parse().unwrap(),
|
||||
// nyxd_name: Some("FooName".to_string()),
|
||||
// api_url: None,
|
||||
// },
|
||||
// ValidatorConfigEntry {
|
||||
// nyxd_url: "https://bar".parse().unwrap(),
|
||||
// nyxd_name: None,
|
||||
// api_url: Some("https://bar/api".parse().unwrap()),
|
||||
// },
|
||||
// ValidatorConfigEntry {
|
||||
// nyxd_url: "https://baz".parse().unwrap(),
|
||||
// nyxd_name: None,
|
||||
// api_url: Some("https://baz/api".parse().unwrap()),
|
||||
// },
|
||||
// ]),
|
||||
// ..NetworkConfig::default()
|
||||
// };
|
||||
nyxd_urls: Some(vec![
|
||||
ValidatorConfigEntry {
|
||||
nyxd_url: "https://foo".parse().unwrap(),
|
||||
nyxd_name: Some("FooName".to_string()),
|
||||
api_url: None,
|
||||
},
|
||||
ValidatorConfigEntry {
|
||||
nyxd_url: "https://bar".parse().unwrap(),
|
||||
nyxd_name: None,
|
||||
api_url: Some("https://bar/api".parse().unwrap()),
|
||||
},
|
||||
ValidatorConfigEntry {
|
||||
nyxd_url: "https://baz".parse().unwrap(),
|
||||
nyxd_name: None,
|
||||
api_url: Some("https://baz/api".parse().unwrap()),
|
||||
},
|
||||
]),
|
||||
..NetworkConfig::default()
|
||||
};
|
||||
|
||||
// Config {
|
||||
// base: Base::default(),
|
||||
// global: Some(GlobalConfig::default()),
|
||||
// networks: [(WalletNetwork::MAINNET.as_key(), netconfig)]
|
||||
// .into_iter()
|
||||
// .collect(),
|
||||
// }
|
||||
// }
|
||||
Config {
|
||||
base: Base::default(),
|
||||
global: Some(GlobalConfig::default()),
|
||||
networks: [(WalletNetwork::MAINNET.as_key(), netconfig)]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
|
||||
// #[test]
|
||||
// fn serialize_to_toml() {
|
||||
// let config = test_config();
|
||||
// let netconfig = &config.networks[&WalletNetwork::MAINNET.as_key()];
|
||||
// assert_eq!(
|
||||
// toml::to_string_pretty(netconfig).unwrap(),
|
||||
// r#"version = 1
|
||||
// selected_api_url = 'https://my_api_url.com/'
|
||||
#[test]
|
||||
fn serialize_to_toml() {
|
||||
let config = test_config();
|
||||
let netconfig = &config.networks[&WalletNetwork::MAINNET.as_key()];
|
||||
assert_eq!(
|
||||
toml::to_string_pretty(netconfig).unwrap(),
|
||||
r#"version = 1
|
||||
selected_api_url = 'https://my_api_url.com/'
|
||||
|
||||
// [[nyxd_urls]]
|
||||
// nyxd_url = 'https://foo/'
|
||||
// nyxd_name = 'FooName'
|
||||
[[nyxd_urls]]
|
||||
nyxd_url = 'https://foo/'
|
||||
nyxd_name = 'FooName'
|
||||
|
||||
// [[nyxd_urls]]
|
||||
// nyxd_url = 'https://bar/'
|
||||
// api_url = 'https://bar/api'
|
||||
[[nyxd_urls]]
|
||||
nyxd_url = 'https://bar/'
|
||||
api_url = 'https://bar/api'
|
||||
|
||||
// [[nyxd_urls]]
|
||||
// nyxd_url = 'https://baz/'
|
||||
// api_url = 'https://baz/api'
|
||||
// "#
|
||||
// );
|
||||
// }
|
||||
[[nyxd_urls]]
|
||||
nyxd_url = 'https://baz/'
|
||||
api_url = 'https://baz/api'
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
// #[test]
|
||||
// fn serialize_to_json() {
|
||||
// let config = test_config();
|
||||
// let netconfig = &config.networks[&WalletNetwork::MAINNET.as_key()];
|
||||
// println!("{}", serde_json::to_string_pretty(netconfig).unwrap());
|
||||
// assert_eq!(
|
||||
// serde_json::to_string_pretty(netconfig).unwrap(),
|
||||
// r#"{
|
||||
// "version": 1,
|
||||
// "selected_nyxd_url": null,
|
||||
// "default_nyxd_url": null,
|
||||
// "selected_api_url": "https://my_api_url.com/",
|
||||
// "nyxd_urls": [
|
||||
// {
|
||||
// "nyxd_url": "https://foo/",
|
||||
// "nyxd_name": "FooName",
|
||||
// "api_url": null
|
||||
// },
|
||||
// {
|
||||
// "nyxd_url": "https://bar/",
|
||||
// "nyxd_name": null,
|
||||
// "api_url": "https://bar/api"
|
||||
// },
|
||||
// {
|
||||
// "nyxd_url": "https://baz/",
|
||||
// "nyxd_name": null,
|
||||
// "api_url": "https://baz/api"
|
||||
// }
|
||||
// ]
|
||||
// }"#
|
||||
// );
|
||||
// }
|
||||
#[test]
|
||||
fn serialize_to_json() {
|
||||
let config = test_config();
|
||||
let netconfig = &config.networks[&WalletNetwork::MAINNET.as_key()];
|
||||
println!("{}", serde_json::to_string_pretty(netconfig).unwrap());
|
||||
assert_eq!(
|
||||
serde_json::to_string_pretty(netconfig).unwrap(),
|
||||
r#"{
|
||||
"version": 1,
|
||||
"selected_nyxd_url": null,
|
||||
"default_nyxd_url": null,
|
||||
"selected_api_url": "https://my_api_url.com/",
|
||||
"nyxd_urls": [
|
||||
{
|
||||
"nyxd_url": "https://foo/",
|
||||
"nyxd_name": "FooName",
|
||||
"api_url": null
|
||||
},
|
||||
{
|
||||
"nyxd_url": "https://bar/",
|
||||
"nyxd_name": null,
|
||||
"api_url": "https://bar/api"
|
||||
},
|
||||
{
|
||||
"nyxd_url": "https://baz/",
|
||||
"nyxd_name": null,
|
||||
"api_url": "https://baz/api"
|
||||
}
|
||||
]
|
||||
}"#
|
||||
);
|
||||
}
|
||||
|
||||
// #[test]
|
||||
// fn serialize_and_deserialize_to_toml() {
|
||||
// let config = test_config();
|
||||
// let netconfig = &config.networks[&WalletNetwork::MAINNET.as_key()];
|
||||
// let config_str = toml::to_string_pretty(netconfig).unwrap();
|
||||
// let config_from_toml: NetworkConfig = toml::from_str(&config_str).unwrap();
|
||||
// assert_eq!(netconfig, &config_from_toml);
|
||||
// }
|
||||
#[test]
|
||||
fn serialize_and_deserialize_to_toml() {
|
||||
let config = test_config();
|
||||
let netconfig = &config.networks[&WalletNetwork::MAINNET.as_key()];
|
||||
let config_str = toml::to_string_pretty(netconfig).unwrap();
|
||||
let config_from_toml: NetworkConfig = toml::from_str(&config_str).unwrap();
|
||||
assert_eq!(netconfig, &config_from_toml);
|
||||
}
|
||||
|
||||
// #[test]
|
||||
// fn get_urls_parsed_from_config() {
|
||||
// let config = test_config();
|
||||
#[test]
|
||||
fn get_urls_parsed_from_config() {
|
||||
let config = test_config();
|
||||
|
||||
// let nyxd_url = config
|
||||
// .get_configured_validators(WalletNetwork::MAINNET)
|
||||
// .next()
|
||||
// .map(|v| v.nyxd_url)
|
||||
// .unwrap();
|
||||
// assert_eq!(nyxd_url.as_ref(), "https://foo/");
|
||||
let nyxd_url = config
|
||||
.get_configured_validators(WalletNetwork::MAINNET)
|
||||
.next()
|
||||
.map(|v| v.nyxd_url)
|
||||
.unwrap();
|
||||
assert_eq!(nyxd_url.as_ref(), "https://foo/");
|
||||
|
||||
// // The first entry is missing an API URL
|
||||
// let api_url = config
|
||||
// .get_configured_validators(WalletNetwork::MAINNET)
|
||||
// .next()
|
||||
// .and_then(|v| v.api_url);
|
||||
// assert_eq!(api_url, None);
|
||||
// }
|
||||
// The first entry is missing an API URL
|
||||
let api_url = config
|
||||
.get_configured_validators(WalletNetwork::MAINNET)
|
||||
.next()
|
||||
.and_then(|v| v.api_url);
|
||||
assert_eq!(api_url, None);
|
||||
}
|
||||
|
||||
// #[test]
|
||||
// fn get_urls_from_defaults() {
|
||||
// let config = Config::default();
|
||||
#[test]
|
||||
fn get_urls_from_defaults() {
|
||||
let config = Config::default();
|
||||
|
||||
// let nyxd_url = config
|
||||
// .get_base_validators(WalletNetwork::MAINNET)
|
||||
// .next()
|
||||
// .map(|v| v.nyxd_url)
|
||||
// .unwrap();
|
||||
// assert_eq!(nyxd_url.as_ref(), "https://rpc.nymtech.net/");
|
||||
let nyxd_url = config
|
||||
.get_base_validators(WalletNetwork::MAINNET)
|
||||
.next()
|
||||
.map(|v| v.nyxd_url)
|
||||
.unwrap();
|
||||
assert_eq!(nyxd_url.as_ref(), "https://rpc.nymtech.net/");
|
||||
|
||||
// let api_url = config
|
||||
// .get_base_validators(WalletNetwork::MAINNET)
|
||||
// .next()
|
||||
// .and_then(|v| v.api_url)
|
||||
// .unwrap();
|
||||
// assert_eq!(api_url.as_ref(), "https://validator.nymtech.net/api/",);
|
||||
// }
|
||||
// }
|
||||
let api_url = config
|
||||
.get_base_validators(WalletNetwork::MAINNET)
|
||||
.next()
|
||||
.and_then(|v| v.api_url)
|
||||
.unwrap();
|
||||
assert_eq!(api_url.as_ref(), "https://validator.nymtech.net/api/",);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ async fn create_window(
|
||||
log::info!("Creating {} window...", new_window_label);
|
||||
match tauri::WebviewWindowBuilder::new(
|
||||
&app_handle,
|
||||
"main",
|
||||
new_window_label,
|
||||
tauri::WebviewUrl::App(new_window_url.into()),
|
||||
)
|
||||
.title("Nym Wallet")
|
||||
@@ -36,14 +36,14 @@ async fn create_window(
|
||||
{
|
||||
Ok(window) => {
|
||||
if let Err(err) = window.set_focus() {
|
||||
log::error!("Unable to focus log window: {err}");
|
||||
log::error!("Unable to focus window: {err}");
|
||||
}
|
||||
if let Err(err) = window.maximize() {
|
||||
log::error!("Could not maximize window: {err}");
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
log::error!("Unable to create log window: {err}");
|
||||
log::error!("Unable to create window: {err}");
|
||||
return Err(BackendError::NewWindowError);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user