Compare commits

..

4 Commits

Author SHA1 Message Date
pierre f3279ab3da fix: remove dead code 2023-03-20 12:37:58 +01:00
pierre 8f5e6992c1 refactor(nc-mobile): adjust ui 2023-03-20 12:25:08 +01:00
pierre 76a53c8ac9 feat(nc-mobile): select service provider ui 2023-03-20 11:09:19 +01:00
Jędrzej Stuczyński 7ff0becf72 replaced usage of 'serde_json' in mixnet contract in favour of 'serde_json_wasm' (#3191)
* replaced usage of 'serde_json' in mixnet contract in favour of 'serde_json_wasm'

* using stricter version number
2023-03-17 14:31:38 +00:00
39 changed files with 372 additions and 558 deletions
Generated
+1 -20
View File
@@ -505,22 +505,6 @@ dependencies = [
"zeroize",
]
[[package]]
name = "chitchat"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fec1bff4fabc59f0b7408478183a796ab0a9bcb0534bb413f3cf66f44ce2aca1"
dependencies = [
"anyhow",
"async-trait",
"bytes",
"rand 0.8.5",
"serde",
"tokio",
"tokio-stream",
"tracing",
]
[[package]]
name = "chrono"
version = "0.4.23"
@@ -2927,7 +2911,6 @@ name = "mixnode-common"
version = "0.1.0"
dependencies = [
"bytes",
"chitchat",
"futures",
"humantime-serde",
"log",
@@ -2943,7 +2926,6 @@ dependencies = [
"nym-task",
"rand 0.8.5",
"serde",
"serde_json",
"thiserror",
"tokio",
"tokio-util",
@@ -3495,7 +3477,7 @@ dependencies = [
"rand_chacha 0.3.1",
"schemars",
"serde",
"serde_json",
"serde-json-wasm",
"serde_repr",
"thiserror",
"time 0.3.17",
@@ -3509,7 +3491,6 @@ dependencies = [
"anyhow",
"atty",
"bs58",
"chitchat",
"clap 4.1.4",
"colored",
"cupid",
@@ -10,13 +10,15 @@ repository = { workspace = true }
[dependencies]
bs58 = "0.4.0"
cosmwasm-std = "1.0.0"
cosmwasm-std = "=1.0.0"
serde = { version = "1.0", features = ["derive"] }
serde_repr = "0.1"
schemars = "0.8"
thiserror = "1.0"
contracts-common = { path = "../contracts-common", package = "nym-contracts-common", version = "0.2.0" }
serde_json = "1.0.0"
# use 0.4.1 as that's the version used by cosmwasm-std 1.0.0
# (and ideally we don't want to pull the same dependency twice)
serde-json-wasm = "=0.4.1"
humantime-serde = "1.1.1"
# TO CHECK WHETHER STILL NEEDED:
@@ -128,7 +128,7 @@ pub struct GatewayConfigUpdate {
impl GatewayConfigUpdate {
pub fn to_inline_json(&self) -> String {
serde_json::to_string(self).unwrap_or_else(|_| "serialisation failure".into())
serde_json_wasm::to_string(self).unwrap_or_else(|_| "serialisation failure".into())
}
}
@@ -542,7 +542,7 @@ pub struct MixNodeCostParams {
impl MixNodeCostParams {
pub fn to_inline_json(&self) -> String {
serde_json::to_string(self).unwrap_or_else(|_| "serialisation failure".into())
serde_json_wasm::to_string(self).unwrap_or_else(|_| "serialisation failure".into())
}
}
@@ -636,7 +636,7 @@ pub struct MixNodeConfigUpdate {
impl MixNodeConfigUpdate {
pub fn to_inline_json(&self) -> String {
serde_json::to_string(self).unwrap_or_else(|_| "serialisation failure".into())
serde_json_wasm::to_string(self).unwrap_or_else(|_| "serialisation failure".into())
}
}
@@ -70,7 +70,7 @@ pub struct IntervalRewardParams {
impl IntervalRewardParams {
pub fn to_inline_json(&self) -> String {
serde_json::to_string(self).unwrap_or_else(|_| "serialisation failure".into())
serde_json_wasm::to_string(self).unwrap_or_else(|_| "serialisation failure".into())
}
}
@@ -282,6 +282,6 @@ impl IntervalRewardingParamsUpdate {
}
pub fn to_inline_json(&self) -> String {
serde_json::to_string(self).unwrap_or_else(|_| "serialisation failure".into())
serde_json_wasm::to_string(self).unwrap_or_else(|_| "serialisation failure".into())
}
}
+3 -13
View File
@@ -13,20 +13,12 @@ humantime-serde = "1.0"
log = { workspace = true }
rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
tokio = { version = "1.24.1", features = [
"time",
"macros",
"rt",
"net",
"io-util",
] }
tokio = { version = "1.24.1", features = ["time", "macros", "rt", "net", "io-util"] }
tokio-util = { version = "0.7.4", features = ["codec"] }
url = "2.2"
thiserror = "1.0.37"
chitchat = "0.5"
serde_json = "1"
nym-crypto = { path = "../crypto" }
nym-crypto = { path = "../crypto" }
nym-network-defaults = { path = "../network-defaults" }
nym-sphinx-acknowledgements = { path = "../nymsphinx/acknowledgements" }
nym-sphinx-addressing = { path = "../nymsphinx/addressing" }
@@ -35,7 +27,5 @@ nym-sphinx-framing = { path = "../nymsphinx/framing" }
nym-sphinx-params = { path = "../nymsphinx/params" }
nym-sphinx-types = { path = "../nymsphinx/types" }
nym-task = { path = "../task" }
validator-client = { path = "../client-libs/validator-client", features = [
"nyxd-client",
] }
validator-client = { path = "../client-libs/validator-client", features = ["nyxd-client"]}
nym-bin-common = { path = "../bin-common" }
+1 -14
View File
@@ -3,7 +3,6 @@
use crate::verloc::listener::PacketListener;
use crate::verloc::sender::{PacketSender, TestedNode};
use chitchat::Chitchat;
use futures::stream::FuturesUnordered;
use futures::StreamExt;
use log::*;
@@ -17,7 +16,6 @@ use std::net::SocketAddr;
use std::net::ToSocketAddrs;
use std::sync::Arc;
use std::time::Duration;
use tokio::sync::Mutex;
use tokio::task::JoinHandle;
use tokio::time::sleep;
use url::Url;
@@ -295,7 +293,7 @@ impl VerlocMeasurer {
MeasurementOutcome::Done
}
pub async fn run(&mut self, chitchat_handle: Arc<Mutex<Chitchat>>) {
pub async fn run(&mut self) {
self.start_listening();
while !self.shutdown_listener.is_shutdown() {
@@ -347,17 +345,6 @@ impl VerlocMeasurer {
})
.collect::<Vec<_>>();
let mut chitchat_guard = chitchat_handle.lock().await;
let cc_state = chitchat_guard.self_node_state();
let tested_nodes_cc = tested_nodes
.iter()
.map(|node| node.identity.to_string())
.collect::<Vec<String>>();
cc_state.set(
"tested_nodes",
serde_json::to_value(tested_nodes_cc).expect("Could not serialize"),
);
// on start of each run remove old results
self.results.reset_results(tested_nodes.len()).await;
-1
View File
@@ -377,7 +377,6 @@ pub const DEFAULT_CLIENT_LISTENING_PORT: u16 = 9000;
// 'MIXNODE'
pub const DEFAULT_VERLOC_LISTENING_PORT: u16 = 1790;
pub const DEFAULT_HTTP_API_LISTENING_PORT: u16 = 8000;
pub const DEFAULT_GOSSIP_PORT: u16 = 10000;
// 'CLIENT'
pub const DEFAULT_WEBSOCKET_LISTENING_PORT: u16 = 1977;
+13 -21
View File
@@ -29,40 +29,32 @@ log = { workspace = true }
pretty_env_logger = "0.4.0"
rand = "0.7.3"
rocket = { version = "0.5.0-rc.2", features = ["json"] }
serde = { version = "1.0", features = ["derive"] }
serde = { version="1.0", features = ["derive"] }
serde_json = "1.0"
sysinfo = "0.27.7"
tokio = { version = "1.21.2", features = ["rt-multi-thread", "net", "signal"] }
tokio-util = { version = "0.7.3", features = ["codec"] }
tokio = { version="1.21.2", features = ["rt-multi-thread", "net", "signal"] }
tokio-util = { version="0.7.3", features = ["codec"] }
toml = "0.5.8"
url = { version = "2.2", features = ["serde"] }
atty = "0.2"
## internal
nym-config = { path = "../common/config" }
nym-crypto = { path = "../common/crypto" }
nym-config = { path="../common/config" }
nym-crypto = { path="../common/crypto" }
nym-contracts-common = { path = "../common/cosmwasm-smart-contracts/contracts-common" }
mixnet-client = { path = "../common/client-libs/mixnet-client" }
mixnode-common = { path = "../common/mixnode-common" }
nym-nonexhaustive-delayqueue = { path = "../common/nonexhaustive-delayqueue" }
nym-sphinx = { path = "../common/nymsphinx" }
mixnet-client = { path="../common/client-libs/mixnet-client" }
mixnode-common = { path="../common/mixnode-common" }
nym-nonexhaustive-delayqueue = { path="../common/nonexhaustive-delayqueue" }
nym-sphinx = { path="../common/nymsphinx" }
nym-pemstore = { path = "../common/pemstore", version = "0.2.0" }
nym-task = { path = "../common/task" }
nym-types = { path = "../common/types" }
nym-topology = { path = "../common/topology" }
validator-client = { path = "../common/client-libs/validator-client" }
nym-bin-common = { path = "../common/bin-common" }
# chichat
chitchat = "0.5"
nym-topology = { path="../common/topology" }
validator-client = { path="../common/client-libs/validator-client" }
nym-bin-common = { path="../common/bin-common" }
[dev-dependencies]
tokio = { version = "1.21.2", features = [
"rt-multi-thread",
"net",
"signal",
"test-util",
] }
tokio = { version="1.21.2", features = ["rt-multi-thread", "net", "signal", "test-util"] }
nym-sphinx-types = { path = "../common/nymsphinx/types" }
nym-sphinx-params = { path = "../common/nymsphinx/params" }
+1 -1
View File
@@ -109,5 +109,5 @@ pub(crate) async fn execute(args: &Run, output: OutputFormat) {
Select the correct version and install it to your machine. You will need to provide the following: \n ");
mixnode.print_node_details(output);
mixnode.run().await.expect("Could not run mixnode")
mixnode.run().await
}
+1 -11
View File
@@ -4,8 +4,7 @@
use crate::config::template::config_template;
use nym_config::defaults::mainnet::NYM_API;
use nym_config::defaults::{
DEFAULT_GOSSIP_PORT, DEFAULT_HTTP_API_LISTENING_PORT, DEFAULT_MIX_LISTENING_PORT,
DEFAULT_VERLOC_LISTENING_PORT,
DEFAULT_HTTP_API_LISTENING_PORT, DEFAULT_MIX_LISTENING_PORT, DEFAULT_VERLOC_LISTENING_PORT,
};
use nym_config::NymConfig;
use serde::{Deserialize, Deserializer, Serialize};
@@ -259,10 +258,6 @@ impl Config {
self.mixnode.http_api_port
}
pub fn get_gossip_port(&self) -> u16 {
self.mixnode.gossip_port
}
pub fn get_packet_forwarding_initial_backoff(&self) -> Duration {
self.debug.packet_forwarding_initial_backoff
}
@@ -353,10 +348,6 @@ struct MixNode {
#[serde(default = "default_http_api_port")]
http_api_port: u16,
/// Port used for the gossip protocol
#[serde(default = "default_http_api_port")]
gossip_port: u16,
/// Path to file containing private identity key.
#[serde(default = "missing_string_value")]
private_identity_key_file: PathBuf,
@@ -411,7 +402,6 @@ impl Default for MixNode {
mix_port: DEFAULT_MIX_LISTENING_PORT,
verloc_port: DEFAULT_VERLOC_LISTENING_PORT,
http_api_port: DEFAULT_HTTP_API_LISTENING_PORT,
gossip_port: DEFAULT_GOSSIP_PORT,
private_identity_key_file: Default::default(),
public_identity_key_file: Default::default(),
private_sphinx_key_file: Default::default(),
-28
View File
@@ -1,28 +0,0 @@
use std::sync::Arc;
use chitchat::{Chitchat, ClusterStateSnapshot, NodeId};
use rocket::serde::json::Json;
use rocket::State;
use serde::Serialize;
use tokio::sync::Mutex;
#[derive(Serialize)]
pub struct ClusterState {
cluster_id: String,
cluster_state: ClusterStateSnapshot,
live_nodes: Vec<NodeId>,
dead_nodes: Vec<NodeId>,
}
/// Returns a description of the node and why someone might want to delegate stake to it.
#[get("/state")]
pub(crate) async fn state(chitchat: &State<Arc<Mutex<Chitchat>>>) -> Json<ClusterState> {
let chitchat_guard = chitchat.lock().await;
let cluster_state = ClusterState {
cluster_id: chitchat_guard.cluster_id().to_string(),
cluster_state: chitchat_guard.state_snapshot(),
live_nodes: chitchat_guard.live_nodes().cloned().collect::<Vec<_>>(),
dead_nodes: chitchat_guard.dead_nodes().cloned().collect::<Vec<_>>(),
};
Json(cluster_state)
}
-1
View File
@@ -1,5 +1,4 @@
pub(crate) mod description;
pub(crate) mod gossip;
pub(crate) mod hardware;
pub(crate) mod stats;
pub(crate) mod verloc;
+12 -67
View File
@@ -5,7 +5,6 @@ use crate::config::persistence::pathfinder::MixNodePathfinder;
use crate::config::Config;
use crate::node::http::{
description::description,
gossip,
hardware::hardware,
not_found,
stats::stats,
@@ -18,10 +17,6 @@ use crate::node::node_description::NodeDescription;
use crate::node::node_statistics::SharedNodeStats;
use crate::node::packet_delayforwarder::{DelayForwarder, PacketDelayForwardSender};
use crate::OutputFormat;
use chitchat::transport::UdpTransport;
use chitchat::{
spawn_chitchat, Chitchat, ChitchatConfig, ChitchatHandle, FailureDetectorConfig, NodeId,
};
use log::{error, info, warn};
use mixnode_common::verloc::{self, AtomicVerlocResult, VerlocMeasurer};
use nym_bin_common::version_checker::parse_version;
@@ -33,8 +28,6 @@ use rand::thread_rng;
use std::net::SocketAddr;
use std::process;
use std::sync::Arc;
use std::time::Duration;
use tokio::sync::Mutex;
mod http;
mod listener;
@@ -117,7 +110,6 @@ impl MixNode {
&self,
atomic_verloc_result: AtomicVerlocResult,
node_stats_pointer: SharedNodeStats,
chitchat: Arc<Mutex<Chitchat>>,
) {
info!("Starting HTTP API on http://localhost:8000");
@@ -133,15 +125,11 @@ impl MixNode {
tokio::spawn(async move {
rocket::build()
.configure(config)
.mount(
"/",
routes![verlocRoute, description, stats, hardware, gossip::state],
)
.mount("/", routes![verlocRoute, description, stats, hardware])
.register("/", catchers![not_found])
.manage(verloc_state)
.manage(descriptor)
.manage(node_stats_pointer)
.manage(chitchat)
.launch()
.await
});
@@ -211,11 +199,7 @@ impl MixNode {
packet_sender
}
fn start_verloc_measurements(
&self,
chitchat: Arc<Mutex<Chitchat>>,
shutdown: TaskClient,
) -> AtomicVerlocResult {
fn start_verloc_measurements(&self, shutdown: TaskClient) -> AtomicVerlocResult {
info!("Starting the round-trip-time measurer...");
// this is a sanity check to make sure we didn't mess up with the minimum version at some point
@@ -251,7 +235,7 @@ impl MixNode {
let mut verloc_measurer =
VerlocMeasurer::new(config, Arc::clone(&self.identity_keypair), shutdown);
let atomic_verloc_results = verloc_measurer.get_verloc_results_pointer();
tokio::spawn(async move { verloc_measurer.run(chitchat).await });
tokio::spawn(async move { verloc_measurer.run().await });
atomic_verloc_results
}
@@ -293,53 +277,18 @@ impl MixNode {
log::info!("Stopping nym mixnode");
}
fn gossip_node_id(&self) -> NodeId {
NodeId::new(
self.identity_keypair.public_key().to_string(),
(
self.config.get_listening_address(),
self.config.get_gossip_port(),
)
.into(),
)
}
fn gossip_config(&self) -> ChitchatConfig {
ChitchatConfig {
node_id: self.gossip_node_id(),
cluster_id: "hive_mind".to_string(),
gossip_interval: Duration::from_millis(500),
listen_addr: (
self.config.get_listening_address(),
self.config.get_gossip_port(),
)
.into(),
// We'd probably wanna get this from the nym_api, or have a few known good nodes, the ones we run probably
seed_nodes: vec![],
failure_detector_config: FailureDetectorConfig::default(),
is_ready_predicate: None,
}
}
pub async fn init_chitchat(&self) -> Result<ChitchatHandle, String> {
let chitchat_handler = spawn_chitchat(self.gossip_config(), Vec::new(), &UdpTransport)
.await
.map_err(|_| "Could not spawn chitchat")?;
Ok(chitchat_handler)
}
pub async fn run(&mut self) -> Result<(), String> {
pub async fn run(&mut self) {
info!("Starting nym mixnode");
if let Some(duplicate_node_key) = self.check_if_same_ip_node_exists().await {
if duplicate_node_key == self.identity_keypair.public_key().to_base58_string() {
warn!("You seem to have bonded your mixnode before starting it - that's highly unrecommended as in the future it might result in slashing");
} else {
let err = format!("Our announce-host is identical to an existing node's announce-host! (its key is {:?})",
duplicate_node_key);
log::error!("{err}");
return Err(err);
log::error!(
"Our announce-host is identical to an existing node's announce-host! (its key is {:?})",
duplicate_node_key
);
return;
}
}
@@ -354,18 +303,14 @@ impl MixNode {
delay_forwarding_channel,
shutdown.subscribe(),
);
let chitchat_handler = self.init_chitchat().await?;
let chitchat = chitchat_handler.chitchat();
let atomic_verloc_results =
self.start_verloc_measurements(chitchat.clone(), shutdown.subscribe());
let atomic_verloc_results = self.start_verloc_measurements(shutdown.subscribe());
// Rocket handles shutdown on it's own, but its shutdown handling should be incorporated
// with that of the rest of the tasks.
// Currently it's runtime is forcefully terminated once the mixnode exits.
self.start_http_api(atomic_verloc_results, node_stats_pointer, chitchat);
self.start_http_api(atomic_verloc_results, node_stats_pointer);
info!("Finished nym mixnode startup procedure - it should now be able to receive mix traffic!");
self.wait_for_interrupt(shutdown).await;
Ok(())
self.wait_for_interrupt(shutdown).await
}
}
+23 -188
View File
@@ -73,15 +73,6 @@ dependencies = [
"alloc-no-stdlib",
]
[[package]]
name = "android_system_properties"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
dependencies = [
"libc",
]
[[package]]
name = "anyhow"
version = "1.0.69"
@@ -512,21 +503,6 @@ dependencies = [
"keystream",
]
[[package]]
name = "chrono"
version = "0.4.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f"
dependencies = [
"iana-time-zone",
"js-sys",
"num-integer",
"num-traits",
"time 0.1.45",
"wasm-bindgen",
"winapi",
]
[[package]]
name = "cipher"
version = "0.3.0"
@@ -628,7 +604,7 @@ dependencies = [
"sqlx 0.6.2",
"tap",
"thiserror",
"time 0.3.19",
"time",
"tokio",
"tokio-stream",
"tokio-tungstenite",
@@ -672,16 +648,6 @@ dependencies = [
"objc",
]
[[package]]
name = "codespan-reporting"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e"
dependencies = [
"termcolor",
"unicode-width",
]
[[package]]
name = "color_quant"
version = "1.1.0"
@@ -1133,50 +1099,6 @@ dependencies = [
"serde",
]
[[package]]
name = "cxx"
version = "1.0.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86d3488e7665a7a483b57e25bdd90d0aeb2bc7608c8d0346acf2ad3f1caf1d62"
dependencies = [
"cc",
"cxxbridge-flags",
"cxxbridge-macro",
"link-cplusplus",
]
[[package]]
name = "cxx-build"
version = "1.0.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48fcaf066a053a41a81dfb14d57d99738b767febb8b735c3016e469fac5da690"
dependencies = [
"cc",
"codespan-reporting",
"once_cell",
"proc-macro2",
"quote",
"scratch",
"syn",
]
[[package]]
name = "cxxbridge-flags"
version = "1.0.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2ef98b8b717a829ca5603af80e1f9e2e48013ab227b68ef37872ef84ee479bf"
[[package]]
name = "cxxbridge-macro"
version = "1.0.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "086c685979a698443656e5cf7856c95c642295a38599f12fb1ff76fb28d19892"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "darling"
version = "0.13.4"
@@ -2542,30 +2464,6 @@ dependencies = [
"tokio-native-tls",
]
[[package]]
name = "iana-time-zone"
version = "0.1.53"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765"
dependencies = [
"android_system_properties",
"core-foundation-sys",
"iana-time-zone-haiku",
"js-sys",
"wasm-bindgen",
"winapi",
]
[[package]]
name = "iana-time-zone-haiku"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca"
dependencies = [
"cxx",
"cxx-build",
]
[[package]]
name = "ico"
version = "0.2.0"
@@ -2848,30 +2746,6 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libappindicator"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89e1edfdc9b0853358306c6dfb4b77c79c779174256fe93d80c0b5ebca451a2f"
dependencies = [
"glib",
"gtk",
"gtk-sys",
"libappindicator-sys",
"log",
]
[[package]]
name = "libappindicator-sys"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08fcb2bea89cee9613982501ec83eaa2d09256b24540ae463c52a28906163918"
dependencies = [
"gtk-sys",
"libloading",
"once_cell",
]
[[package]]
name = "libc"
version = "0.2.139"
@@ -2899,16 +2773,6 @@ dependencies = [
"pkg-config",
]
[[package]]
name = "libloading"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f"
dependencies = [
"cfg-if",
"winapi",
]
[[package]]
name = "libm"
version = "0.2.6"
@@ -2947,15 +2811,6 @@ dependencies = [
"safemem",
]
[[package]]
name = "link-cplusplus"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5"
dependencies = [
"cc",
]
[[package]]
name = "linked-hash-map"
version = "0.5.6"
@@ -3031,7 +2886,7 @@ dependencies = [
"dirs-next",
"objc-foundation",
"objc_id",
"time 0.3.19",
"time",
]
[[package]]
@@ -3300,6 +3155,15 @@ dependencies = [
"syn",
]
[[package]]
name = "num_threads"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44"
dependencies = [
"libc",
]
[[package]]
name = "nym-api-requests"
version = "0.1.0"
@@ -3376,11 +3240,10 @@ dependencies = [
[[package]]
name = "nym-connect"
version = "1.1.9"
version = "1.1.12"
dependencies = [
"anyhow",
"bip39",
"chrono",
"client-core",
"dirs",
"eyre",
@@ -3409,6 +3272,7 @@ dependencies = [
"tempfile",
"tendermint-rpc",
"thiserror",
"time",
"tokio",
"ts-rs",
"url",
@@ -3521,10 +3385,10 @@ dependencies = [
"nym-contracts-common",
"schemars",
"serde",
"serde_json",
"serde-json-wasm",
"serde_repr",
"thiserror",
"time 0.3.19",
"time",
]
[[package]]
@@ -4352,7 +4216,7 @@ dependencies = [
"line-wrap",
"quick-xml 0.26.0",
"serde",
"time 0.3.19",
"time",
]
[[package]]
@@ -4955,12 +4819,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "scratch"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2"
[[package]]
name = "sct"
version = "0.6.1"
@@ -5753,7 +5611,6 @@ dependencies = [
"core-foundation",
"core-graphics",
"crossbeam-channel",
"dirs-next",
"dispatch",
"gdk",
"gdk-pixbuf",
@@ -5767,7 +5624,6 @@ dependencies = [
"instant",
"jni",
"lazy_static",
"libappindicator",
"libc",
"log",
"ndk",
@@ -5906,7 +5762,7 @@ dependencies = [
"sha2 0.10.6",
"tauri-utils",
"thiserror",
"time 0.3.19",
"time",
"url",
"uuid 1.3.0",
"walkdir",
@@ -6046,7 +5902,7 @@ dependencies = [
"subtle 2.4.1",
"subtle-encoding",
"tendermint-proto",
"time 0.3.19",
"time",
"zeroize",
]
@@ -6079,7 +5935,7 @@ dependencies = [
"serde",
"serde_bytes",
"subtle-encoding",
"time 0.3.19",
"time",
]
[[package]]
@@ -6107,7 +5963,7 @@ dependencies = [
"tendermint-config",
"tendermint-proto",
"thiserror",
"time 0.3.19",
"time",
"tokio",
"tracing",
"url",
@@ -6171,17 +6027,6 @@ dependencies = [
"once_cell",
]
[[package]]
name = "time"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a"
dependencies = [
"libc",
"wasi 0.10.0+wasi-snapshot-preview1",
"winapi",
]
[[package]]
name = "time"
version = "0.3.19"
@@ -6190,6 +6035,8 @@ checksum = "53250a3b3fed8ff8fd988587d8925d26a83ac3845d9e03b220b37f34c2b8d6c2"
dependencies = [
"itoa 1.0.5",
"js-sys",
"libc",
"num_threads",
"serde",
"time-core",
"time-macros",
@@ -6542,12 +6389,6 @@ version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36"
[[package]]
name = "unicode-width"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
[[package]]
name = "unicode-xid"
version = "0.2.4"
@@ -6671,7 +6512,7 @@ dependencies = [
"rustc_version 0.4.0",
"rustversion",
"thiserror",
"time 0.3.19",
"time",
]
[[package]]
@@ -6734,12 +6575,6 @@ version = "0.9.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]]
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
+5 -5
View File
@@ -1,7 +1,7 @@
[package]
name = "nym-connect"
version = "1.1.9"
description = "nym-connect for Mobile"
version = "1.1.12"
description = "nym-connect mobile"
authors = ["Nym Technologies SA"]
license = ""
repository = ""
@@ -26,7 +26,6 @@ tauri-mobile = { git = "https://github.com/tauri-apps/tauri-mobile", branch = "
[dependencies]
anyhow = "1.0"
bip39 = { version = "2.0.0", features = ["zeroize"] }
chrono = "0.4"
dirs = "4.0"
eyre = "0.6.5"
fix-path-env = { git = "https://github.com/tauri-apps/fix-path-env-rs", branch = "release"}
@@ -42,10 +41,11 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_repr = "0.1"
tap = "1.0.1"
# tauri = { git = "https://github.com/tauri-apps/tauri", branch = "next", features = ["clipboard-write-text", "native-tls-vendored", "notification-all", "shell-open", "system-tray", "window-close", "window-minimize", "window-start-dragging"] }
tauri = { version = "2.0.0-alpha.3", features = ["clipboard-write-text", "native-tls-vendored", "notification-all", "shell-open", "system-tray", "window-close", "window-minimize", "window-start-dragging"] }
# tauri = { git = "https://github.com/tauri-apps/tauri", branch = "next", features = ["clipboard-write-text", "native-tls-vendored", "notification-all", "shell-open"] }
tauri = { version = "2.0.0-alpha.3", features = ["clipboard-write-text", "native-tls-vendored", "notification-all", "shell-open"] }
tendermint-rpc = "0.23.0"
thiserror = "1.0"
time = { version = "0.3.17", features = ["local-offset"] }
tokio = { version = "1.24.1", features = ["sync", "time"] }
url = "2.2"
yaml-rust = "0.4"
-5
View File
@@ -16,11 +16,6 @@ pub mod operations;
mod state;
mod tasks;
#[cfg(desktop)]
mod menu;
#[cfg(desktop)]
mod window;
pub use state::State;
#[cfg(mobile)]
+33 -4
View File
@@ -1,9 +1,26 @@
use std::str::FromStr;
use fern::colors::{Color, ColoredLevelConfig};
use serde::Serialize;
use serde_repr::{Deserialize_repr, Serialize_repr};
use std::str::FromStr;
use tauri::Manager;
use time::{format_description, OffsetDateTime};
fn formatted_time() -> String {
// if we fail to obtain local time according to local offset, fallback to utc
let _now = OffsetDateTime::now_local().unwrap_or_else(|_| OffsetDateTime::now_utc());
// if we're running it in the unit test, use the hardcoded value
#[cfg(test)]
let _now = OffsetDateTime::from_unix_timestamp(1666666666).unwrap();
// the unwraps are fine as we know this description is correct
// note: the reason for this very particular format is a very simple one
// it's what we've always been using since we copied it from the example,
// so feel free to update it to whatever
let format =
format_description::parse("[[[year]-[month]-[day]][[[hour]:[minute]:[second]]").unwrap();
_now.format(&format).unwrap()
}
pub fn setup_logging(app_handle: tauri::AppHandle) -> Result<(), log::SetLoggerError> {
let colors = ColoredLevelConfig::new()
@@ -21,7 +38,7 @@ pub fn setup_logging(app_handle: tauri::AppHandle) -> Result<(), log::SetLoggerE
.format(move |out, message, record| {
out.finish(format_args!(
"{}[{}][{}] {}",
chrono::Local::now().format("[%Y-%m-%d][%H:%M:%S]"),
formatted_time(),
record.target(),
colors.color(record.level()),
message,
@@ -33,7 +50,7 @@ pub fn setup_logging(app_handle: tauri::AppHandle) -> Result<(), log::SetLoggerE
.format(move |out, message, record| {
out.finish(format_args!(
"{}[{}] {}",
chrono::Local::now().format("[%Y-%m-%d][%H:%M:%S]"),
formatted_time(),
record.target(),
message,
))
@@ -116,3 +133,15 @@ impl From<log::Level> for LogLevel {
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn log_formatting() {
let expected_chrono_formated = "[2022-10-25][02:57:46]".to_string();
let new_time_based = formatted_time();
assert_eq!(new_time_based, expected_chrono_formated)
}
}
-6
View File
@@ -6,11 +6,5 @@
use nym_connect::AppBuilder;
fn main() {
// As per breaking change description here
// https://github.com/tauri-apps/tauri/blob/feac1d193c6d618e49916ad0707201f43d5cdd36/tooling/bundler/CHANGELOG.md
//if let Err(error) = fix_path_env::fix() {
// log::warn!("Failed to fix PATH: {error}");
//}
AppBuilder::new().run();
}
-62
View File
@@ -1,62 +0,0 @@
use tauri::{
AppHandle, CustomMenuItem, Menu, Submenu, SystemTray, SystemTrayEvent, SystemTrayMenu,
SystemTrayMenuItem, Wry,
};
use crate::window::window_toggle;
pub const SHOW_LOG_WINDOW: &str = "show_log_window";
pub const CLEAR_STORAGE: &str = "clear_storage";
pub trait AddDefaultSubmenus {
fn add_default_app_submenus(self) -> Self;
}
impl AddDefaultSubmenus for Menu {
fn add_default_app_submenus(self) -> Self {
let submenu = Submenu::new(
"Help",
Menu::new().add_item(CustomMenuItem::new(SHOW_LOG_WINDOW, "Show logs")),
);
self.add_submenu(submenu)
}
}
pub const TRAY_MENU_QUIT: &str = "quit";
pub const TRAY_MENU_SHOW_HIDE: &str = "show-hide";
pub const TRAY_MENU_CONNECTION: &str = "connection";
pub(crate) fn create_tray_menu() -> SystemTray {
let quit = CustomMenuItem::new(TRAY_MENU_QUIT, "Quit");
let hide = CustomMenuItem::new(TRAY_MENU_SHOW_HIDE, "Hide");
let connection = CustomMenuItem::new(TRAY_MENU_CONNECTION, "Connect");
let tray_menu = SystemTrayMenu::new()
.add_item(hide)
.add_item(connection)
.add_native_item(SystemTrayMenuItem::Separator)
.add_item(quit);
SystemTray::new().with_menu(tray_menu)
}
pub(crate) fn tray_menu_event_handler(app: &AppHandle<Wry>, event: SystemTrayEvent) {
match event {
SystemTrayEvent::LeftClick { position, size, .. } => {
println!("Event {position:?} {size:?}");
}
SystemTrayEvent::MenuItemClick { id, .. } => {
println!("Event {id}");
match id.as_str() {
TRAY_MENU_SHOW_HIDE => {
window_toggle(app);
}
TRAY_MENU_QUIT => {
// TODO: add disconnecting first
app.exit(0);
}
_ => {}
}
}
_ => {}
}
}
@@ -3,5 +3,3 @@ pub mod directory;
pub mod export;
pub mod help;
pub mod http;
#[cfg(desktop)]
pub mod window;
@@ -1,7 +0,0 @@
use crate::window::window_hide;
use tauri::{AppHandle, Wry};
#[tauri::command]
pub fn hide_window(app: AppHandle<Wry>) {
window_hide(&app);
}
@@ -1,30 +0,0 @@
use crate::menu::TRAY_MENU_SHOW_HIDE;
use tauri::{AppHandle, Manager};
pub(crate) fn window_hide(app: &AppHandle<tauri::Wry>) {
let window = app.get_window("main").unwrap();
let item_handle = app.tray_handle().get_item(TRAY_MENU_SHOW_HIDE);
if window.is_visible().unwrap() {
window.hide().unwrap();
item_handle.set_title("Show").unwrap();
}
}
pub(crate) fn window_show(app: &AppHandle<tauri::Wry>) {
let window = app.get_window("main").unwrap();
let item_handle = app.tray_handle().get_item(TRAY_MENU_SHOW_HIDE);
if !window.is_visible().unwrap() {
window.show().unwrap();
item_handle.set_title("Hide").unwrap();
window.set_focus().unwrap();
}
}
pub(crate) fn window_toggle(app: &AppHandle<tauri::Wry>) {
let window = app.get_window("main").unwrap();
if window.is_visible().unwrap() {
window_hide(app);
} else {
window_show(app);
}
}
+8 -11
View File
@@ -1,7 +1,7 @@
{
"package": {
"productName": "nym-connect",
"version": "1.1.9"
"version": "1.1.12"
},
"build": {
"distDir": "../dist",
@@ -14,7 +14,13 @@
"active": true,
"targets": "all",
"identifier": "net.nymtech.connect",
"icon": ["icons/32x32.png", "icons/128x128.png", "icons/128x128@2x.png", "icons/icon.icns", "icons/icon.ico"],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"resources": [],
"externalBin": [],
"copyright": "Copyright © 2021-2022 Nym Technologies SA",
@@ -37,10 +43,6 @@
"timestampUrl": ""
}
},
"systemTray": {
"iconPath": "icons/tray_icon.png",
"iconAsTemplate": true
},
"updater": {
"active": false
},
@@ -51,11 +53,6 @@
"clipboard": {
"writeText": true
},
"window": {
"startDragging": true,
"close": true,
"minimize": true
},
"notification": {
"all": true
}
@@ -6,12 +6,13 @@ import { CustomTitleBar } from './CustomTitleBar';
export const AppWindowFrame: FCWithChildren = ({ children }) => {
const location = useLocation();
const { userDefinedGateway, setUserDefinedGateway } = useClientContext();
const { userDefinedGateway, setUserDefinedGateway, userDefinedSPAddress, setUserDefinedSPAddress } =
useClientContext();
// defined functions to be used when moving away from pages
const onBack = () => {
switch (location.pathname) {
case '/menu/settings':
case '/menu/settings/gateway':
return () => {
// when the user moves away from the settings page and the gateway is not valid
// set isActive to false
@@ -19,6 +20,14 @@ export const AppWindowFrame: FCWithChildren = ({ children }) => {
setUserDefinedGateway((current) => ({ ...current, isActive: false }));
}
};
case '/menu/settings/service-provider':
return () => {
// when the user moves away from the settings page and the sp is not valid
// set isActive to false
if (!userDefinedSPAddress?.address) {
setUserDefinedSPAddress((current) => ({ ...current, isActive: false }));
}
};
default:
return undefined;
}
@@ -33,7 +42,7 @@ export const AppWindowFrame: FCWithChildren = ({ children }) => {
}}
>
<CustomTitleBar path={location.pathname} onBack={onBack()} />
<Box style={{ padding: '16px', paddingTop: '24px' }}>{children}</Box>
<Box style={{ padding: '16px' }}>{children}</Box>
</Box>
);
};
@@ -38,7 +38,8 @@ const ArrowBackIcon = ({ onBack }: { onBack?: () => void }) => {
return <CustomButton Icon={ArrowBack} onClick={handleBack} />;
};
const getTitleIcon = (path: string) => {
const getTitle = (path: string) => {
if (path.includes('settings')) return 'Settings';
if (path !== '/') {
const title = path.split('/').slice(-1);
return (
@@ -60,7 +61,7 @@ export const CustomTitleBar = ({ path = '/', onBack }: { path?: string; onBack?:
<Box style={customTitleBarStyles.titlebar}>
{/* set width to keep logo centered */}
<Box sx={{ width: '40px' }}>{path === '/' ? <MenuIcon /> : <ArrowBackIcon onBack={onBack} />}</Box>
{getTitleIcon(path)}
{path !== '/' && <Box sx={{ width: '40px' }} />}
{getTitle(path)}
<Box sx={{ width: '40px' }} />
</Box>
);
@@ -4,6 +4,10 @@ import { ServiceProvider } from 'src/types/directory';
export const ServiceProviderInfo = ({ serviceProvider }: { serviceProvider: ServiceProvider }) => (
<Stack gap={1} sx={{ wordWrap: 'break-word', maxWidth: 200, p: 1 }}>
<Typography variant="body2" fontWeight="bold">
Connection info
</Typography>
<Divider />
<Typography variant="caption" fontWeight="bold">
Gateway <Typography variant="caption">{serviceProvider.gateway}</Typography>
</Typography>
@@ -16,6 +20,10 @@ export const ServiceProviderInfo = ({ serviceProvider }: { serviceProvider: Serv
export const GatwayWarningInfo = () => (
<Stack gap={1} sx={{ wordWrap: 'break-word', maxWidth: 200, p: 1 }}>
<Typography variant="body2" fontWeight="bold" color="warning.main">
Connection issue
</Typography>
<Divider />
<Typography variant="caption">Try disconnecting and connecting again</Typography>
</Stack>
);
+50 -35
View File
@@ -4,13 +4,14 @@ import { invoke } from '@tauri-apps/api';
import { Error } from 'src/types/error';
import { getVersion } from '@tauri-apps/api/app';
import { useEvents } from 'src/hooks/events';
import { UserDefinedGateway } from 'src/types/gateway';
import { forage } from '@tauri-apps/tauri-forage';
import { UserDefinedGateway, UserDefinedSPAddress } from 'src/types/service-provider';
import { getItemFromStorage, setItemInStorage } from 'src/utils';
import { ConnectionStatusKind, GatewayPerformance } from '../types';
import { ConnectionStatsItem } from '../components/ConnectionStats';
import { ServiceProvider } from '../types/directory';
const FORAGE_KEY = 'nym-connect-user-gateway';
const FORAGE_GATEWAY_KEY = 'nym-connect-user-gateway';
const FORAGE_SP_KEY = 'nym-connect-user-sp';
type ModeType = 'light' | 'dark';
@@ -25,16 +26,19 @@ export type TClientContext = {
selectedProvider?: ServiceProvider;
showInfoModal: boolean;
userDefinedGateway?: UserDefinedGateway;
userDefinedSPAddress: UserDefinedSPAddress;
serviceProviders?: ServiceProvider[];
setMode: (mode: ModeType) => void;
clearError: () => void;
setConnectionStatus: (connectionStatus: ConnectionStatusKind) => void;
setConnectionStats: (connectionStats: ConnectionStatsItem[] | undefined) => void;
setConnectedSince: (connectedSince: DateTime | undefined) => void;
setShowInfoModal: (show: boolean) => void;
setRandomSerivceProvider: () => void;
setSerivceProvider: () => void;
startConnecting: () => Promise<void>;
startDisconnecting: () => Promise<void>;
setUserDefinedGateway: React.Dispatch<React.SetStateAction<UserDefinedGateway>>;
setUserDefinedSPAddress: React.Dispatch<React.SetStateAction<UserDefinedSPAddress>>;
};
export const ClientContext = createContext({} as TClientContext);
@@ -50,43 +54,39 @@ export const ClientContextProvider: FCWithChildren = ({ children }) => {
const [appVersion, setAppVersion] = useState<string>();
const [gatewayPerformance, setGatewayPerformance] = useState<GatewayPerformance>('Good');
const [showInfoModal, setShowInfoModal] = useState(false);
const [userDefinedGateway, setUserDefinedGateway] = useState<UserDefinedGateway>({ isActive: false, gateway: '' });
const [userDefinedGateway, setUserDefinedGateway] = useState<UserDefinedGateway>({
isActive: false,
gateway: undefined,
});
const [userDefinedSPAddress, setUserDefinedSPAddress] = useState<UserDefinedSPAddress>({
isActive: false,
address: undefined,
});
const getAppVersion = async () => {
const version = await getVersion();
return version;
};
const setUserGatewayInStorage = async (gateway: UserDefinedGateway) => {
try {
await forage.setItem({
key: FORAGE_KEY,
value: gateway,
} as any)();
} catch (e) {
console.warn(e);
}
return undefined;
};
useEffect(() => {
setItemInStorage({ key: FORAGE_GATEWAY_KEY, value: userDefinedGateway });
}, [userDefinedGateway]);
const getUserGatewayFromStorage = async (): Promise<UserDefinedGateway | undefined> => {
try {
const gatewayFromStorage = await forage.getItem({ key: FORAGE_KEY })();
return gatewayFromStorage;
} catch (e) {
console.warn(e);
}
return undefined;
};
useEffect(() => {
setItemInStorage({ key: FORAGE_SP_KEY, value: userDefinedSPAddress });
}, [userDefinedSPAddress]);
const initialiseApp = async () => {
const services = await invoke('get_services');
const AppVersion = await getAppVersion();
const storedUserDefinedGateway = await getUserGatewayFromStorage();
const storedUserDefinedGateway = await getItemFromStorage({ key: FORAGE_GATEWAY_KEY });
const storedUserDefinedSP = await getItemFromStorage({ key: FORAGE_SP_KEY });
setAppVersion(AppVersion);
setServiceProviders(services as ServiceProvider[]);
if (storedUserDefinedGateway) setUserDefinedGateway(storedUserDefinedGateway);
if (storedUserDefinedSP) setUserDefinedSPAddress(storedUserDefinedSP);
};
useEvents({
@@ -125,27 +125,37 @@ export const ClientContextProvider: FCWithChildren = ({ children }) => {
}, []);
const shouldUseUserGateway = !!userDefinedGateway.gateway && userDefinedGateway.isActive;
const shouldUseUserSP = !!userDefinedSPAddress.address && userDefinedSPAddress.isActive;
const setServiceProvider = async (newServiceProvider: ServiceProvider) => {
await invoke('set_gateway', {
gateway: newServiceProvider.gateway,
gateway: shouldUseUserGateway ? userDefinedGateway.gateway : newServiceProvider.gateway,
});
await invoke('set_service_provider', {
serviceProvider: shouldUseUserSP ? userDefinedSPAddress.address : newServiceProvider.address,
});
await invoke('set_service_provider', { serviceProvider: newServiceProvider.address });
};
const getRandomSPFromList = (services: ServiceProvider[]) => {
const randomSelection = services[Math.floor(Math.random() * services.length)];
if (shouldUseUserGateway) return { ...randomSelection, gateway: userDefinedGateway.gateway } as ServiceProvider;
return randomSelection;
};
const setRandomSerivceProvider = async () => {
const buildServiceProvider = async (serviceProvider: ServiceProvider) => {
const sp = { ...serviceProvider };
if (shouldUseUserGateway) sp.gateway = userDefinedGateway.gateway as string;
if (shouldUseUserSP) sp.address = userDefinedSPAddress.address as string;
return sp;
};
const setSerivceProvider = async () => {
if (serviceProviders) {
const randomServiceProvider = getRandomSPFromList(serviceProviders);
await setServiceProvider(randomServiceProvider);
await setUserGatewayInStorage(userDefinedGateway);
setSelectedProvider(randomServiceProvider);
const withUserDefinitions = await buildServiceProvider(randomServiceProvider);
await setServiceProvider(withUserDefinitions);
setSelectedProvider(withUserDefinitions);
}
return undefined;
};
@@ -165,21 +175,25 @@ export const ClientContextProvider: FCWithChildren = ({ children }) => {
showInfoModal,
setConnectionStats,
selectedProvider,
serviceProviders,
connectedSince,
setConnectedSince,
setRandomSerivceProvider,
setSerivceProvider,
startConnecting,
startDisconnecting,
gatewayPerformance,
setShowInfoModal,
userDefinedSPAddress,
userDefinedGateway,
setUserDefinedGateway,
setUserDefinedSPAddress,
}),
[
mode,
appVersion,
error,
showInfoModal,
serviceProviders,
connectedSince,
connectionStatus,
connectionStats,
@@ -187,6 +201,7 @@ export const ClientContextProvider: FCWithChildren = ({ children }) => {
gatewayPerformance,
selectedProvider,
userDefinedGateway,
userDefinedSPAddress,
],
);
@@ -10,6 +10,7 @@ const mockValues: TClientContext = {
gatewayPerformance: 'Good',
showInfoModal: false,
userDefinedGateway: { isActive: false, gateway: '' },
userDefinedSPAddress: { isActive: false, address: '' },
setShowInfoModal: () => {},
setMode: () => {},
clearError: () => {},
@@ -18,8 +19,9 @@ const mockValues: TClientContext = {
setConnectionStatus: () => {},
startConnecting: async () => {},
startDisconnecting: async () => {},
setRandomSerivceProvider: () => {},
setSerivceProvider: () => {},
setUserDefinedGateway: () => {},
setUserDefinedSPAddress: () => {},
};
export const MockProvider: FCWithChildren<{
@@ -29,7 +29,7 @@ export const ConnectionPage = () => {
// eslint-disable-next-line default-case
switch (currentStatus) {
case 'disconnected':
await context.setRandomSerivceProvider();
await context.setSerivceProvider();
await context.startConnecting();
context.setConnectedSince(DateTime.now());
context.setShowInfoModal(true);
+1 -1
View File
@@ -9,7 +9,7 @@ const appsSchema = {
export const CompatibleApps = () => (
<Box>
<Typography fontWeight={600} sx={{ mb: 3 }}>
<Typography fontWeight={600} color="grey.600" sx={{ mb: 3 }}>
Supported apps
</Typography>
<Typography color="nym.highlight" fontWeight={400} sx={{ mb: 2 }}>
@@ -5,8 +5,8 @@ import { useClientContext } from 'src/context/main';
import { ConnectionStatusKind } from 'src/types';
import { AppVersion } from 'src/components/AppVersion';
export const Settings = () => {
const { userDefinedGateway, setUserDefinedGateway } = useClientContext();
export const GatewaySettings = () => {
const { userDefinedGateway, setUserDefinedGateway, connectionStatus } = useClientContext();
const [gatewayKey, setGatewayKey] = useState<string | undefined>(userDefinedGateway?.gateway);
const handleIsValidGatewayKey = (isValid: boolean) => {
@@ -20,17 +20,14 @@ export const Settings = () => {
};
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
console.warn('HANERE***');
setUserDefinedGateway((current) => ({ ...current, isActive: e.target.checked }));
};
const { connectionStatus } = useClientContext();
return (
<Box height="100%">
<Stack justifyContent="space-between" height="100%">
<Box>
<Typography fontWeight="bold" variant="body2" mb={1} fontSize="14px">
<Box mt={3}>
<Typography fontWeight="bold" variant="body2" mb={1}>
Select your Gateway
</Typography>
<Typography color="grey.300" variant="body2" mb={3}>
@@ -61,6 +58,7 @@ export const Settings = () => {
onValidate={handleIsValidGatewayKey}
sx={{ mt: 3 }}
disabled={connectionStatus === 'connected' || !userDefinedGateway?.isActive}
autoFocus
/>
)}
</FormControl>
@@ -0,0 +1,101 @@
import React, { ChangeEvent } from 'react';
import {
Autocomplete,
Box,
FormControl,
FormControlLabel,
FormHelperText,
Stack,
Switch,
TextField,
Typography,
} from '@mui/material';
import { AppVersion } from 'src/components/AppVersion';
import { ConnectionStatusKind } from 'src/types';
import { useClientContext } from 'src/context/main';
export const ServiceProviderSettings = () => {
const { connectionStatus, serviceProviders, userDefinedSPAddress, setUserDefinedSPAddress } = useClientContext();
const toggleOnOff = (e: ChangeEvent<HTMLInputElement>) => {
setUserDefinedSPAddress((current) => ({ ...current, isActive: e.target.checked }));
};
const handleSelectFromList = (value: string | null) => {
setUserDefinedSPAddress((current) => ({ ...current, address: value ?? undefined }));
};
const getSPDescription = (spAddress: string) => {
const match = serviceProviders?.find((sp) => sp.address === spAddress);
if (match) return match.description;
return 'N/A';
};
const validateInput = (value: string) => {
setUserDefinedSPAddress((current) => ({ ...current, address: !value.length ? undefined : value }));
};
return (
<Box height="100%">
<Stack justifyContent="space-between" height="100%">
<Box mt={3}>
<Typography fontWeight="bold" variant="body2" mb={1}>
Select your Service Provider
</Typography>
<Typography color="grey.300" variant="body2" mb={3}>
Pick a service provider from the list or enter your own
</Typography>
<FormControl fullWidth>
<FormControlLabel
control={
<Switch
checked={userDefinedSPAddress.isActive}
onChange={toggleOnOff}
disabled={connectionStatus === ConnectionStatusKind.connected}
size="small"
sx={{ ml: 1 }}
/>
}
label={userDefinedSPAddress.isActive ? 'On' : 'Off'}
/>
{connectionStatus === ConnectionStatusKind.connected && (
<FormHelperText sx={{ m: 0, my: 1 }}>This setting is disabled during an active connection</FormHelperText>
)}
{userDefinedSPAddress.isActive && serviceProviders && (
<Autocomplete
clearOnEscape
disabled={connectionStatus === 'connected'}
sx={{ mt: 3 }}
options={serviceProviders.map((sp) => sp.address)}
freeSolo
value={userDefinedSPAddress.address || ''}
onChange={(e, value) => handleSelectFromList(value)}
size="small"
renderInput={(params) => (
<TextField
autoFocus
{...params}
placeholder="Service provider"
onChange={(e) => validateInput(e.target.value)}
/>
)}
ListboxProps={{ style: { background: 'unset', fontSize: '14px' } }}
/>
)}
</FormControl>
{userDefinedSPAddress.address && userDefinedSPAddress.isActive && (
<Box sx={{ mt: 3 }}>
<Typography variant="body2">Name of Service Provider</Typography>
<Typography variant="body2" sx={{ mt: 1 }} color="grey.400">
{getSPDescription(userDefinedSPAddress.address)}
</Typography>
</Box>
)}
</Box>
<AppVersion />
</Stack>
</Box>
);
};
@@ -0,0 +1,26 @@
import React from 'react';
import { Link as RouterLink } from 'react-router-dom';
import { Link, List, ListItem, ListItemButton, ListItemText, Stack } from '@mui/material';
import { AppVersion } from 'src/components/AppVersion';
const menuSchema = [
{ title: 'Select your gateway', path: 'gateway' },
{ title: 'Select a service provider', path: 'service-provider' },
];
export const SettingsMenu = () => (
<Stack justifyContent="space-between" height="100%">
<List sx={{ mt: 3 }} dense disablePadding>
{menuSchema.map((item) => (
<Link component={RouterLink} to={item.path} underline="none" color="white" key={item.title}>
<ListItem disablePadding>
<ListItemButton>
<ListItemText>{item.title}</ListItemText>
</ListItemButton>
</ListItem>
</Link>
))}
</List>
<AppVersion />
</Stack>
);
+8 -2
View File
@@ -4,7 +4,9 @@ import { ConnectionPage } from 'src/pages/connection';
import { Menu } from 'src/pages/menu';
import { CompatibleApps } from 'src/pages/menu/Apps';
import { HelpGuide } from 'src/pages/menu/Guide';
import { Settings } from 'src/pages/menu/Settings';
import { SettingsMenu } from 'src/pages/menu/settings';
import { GatewaySettings } from 'src/pages/menu/settings/GatewaySettings';
import { ServiceProviderSettings } from 'src/pages/menu/settings/ServiceProviderSettings';
export const AppRoutes = () => (
<Routes>
@@ -13,7 +15,11 @@ export const AppRoutes = () => (
<Route index element={<Menu />} />
<Route path="apps" element={<CompatibleApps />} />
<Route path="guide" element={<HelpGuide />} />
<Route path="settings" element={<Settings />} />
<Route path="settings">
<Route index element={<SettingsMenu />} />
<Route path="gateway" element={<GatewaySettings />} />
<Route path="service-provider" element={<ServiceProviderSettings />} />
</Route>
</Route>
</Routes>
);
@@ -0,0 +1,9 @@
export interface UserDefinedGateway {
isActive: boolean;
gateway?: string;
}
export interface UserDefinedSPAddress {
isActive: boolean;
address?: string;
}
+4
View File
@@ -0,0 +1,4 @@
export interface StorageKeyValue<T> {
key: string;
value: T;
}
+29
View File
@@ -1,5 +1,8 @@
import { useEffect, useRef } from 'react';
import { EventName, listen, UnlistenFn, EventCallback } from '@tauri-apps/api/event';
import { invoke } from '@tauri-apps/api';
import { forage } from '@tauri-apps/tauri-forage';
import { StorageKeyValue } from 'src/types/storage';
export const useTauriEvents = <T>(event: EventName, handler: EventCallback<T>) => {
const unlisten = useRef<UnlistenFn>();
@@ -17,3 +20,29 @@ export const useTauriEvents = <T>(event: EventName, handler: EventCallback<T>) =
};
}, []);
};
export const toggleLogViewer = async () => {
await invoke('help_log_toggle_window');
};
export async function setItemInStorage<T>({ key, value }: StorageKeyValue<T>) {
try {
await forage.setItem({
key,
value,
} as any)();
} catch (e) {
console.warn(e);
}
return undefined;
}
export const getItemFromStorage = async ({ key }: Pick<StorageKeyValue<undefined>, 'key'>) => {
try {
const gatewayFromStorage = await forage.getItem({ key })();
return gatewayFromStorage;
} catch (e) {
console.warn(e);
}
return undefined;
};
+1 -1
View File
@@ -2912,7 +2912,7 @@ dependencies = [
"nym-contracts-common",
"schemars",
"serde",
"serde_json",
"serde-json-wasm",
"serde_repr",
"thiserror",
"time",