connect: add tauri methods to get and set provider (#1406)

This commit is contained in:
Jon Häggblad
2022-06-27 20:54:58 +02:00
committed by GitHub
parent 97f77c4549
commit 479cc20083
6 changed files with 49 additions and 6 deletions
+6 -1
View File
@@ -897,6 +897,7 @@ dependencies = [
"network-defaults",
"thiserror",
"url",
"validator-api-requests",
"validator-client",
]
@@ -6298,6 +6299,10 @@ dependencies = [
name = "validator-api-requests"
version = "0.1.0"
dependencies = [
"bs58",
"coconut-interface",
"cosmrs",
"getset",
"mixnet-contract-common",
"schemars",
"serde",
@@ -6401,7 +6406,7 @@ checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
[[package]]
name = "vesting-contract"
version = "1.0.0"
version = "1.0.1"
dependencies = [
"config",
"cosmwasm-std",
+5 -2
View File
@@ -16,6 +16,8 @@ pub static SOCKS5_CONFIG_ID: Lazy<String> = Lazy::new(|| {
});
// TODO: make this configurable from the UI
// TODO: once we can set this is the UI, consider just removing it, and put in guards to halt if
// user hasn't chosen the provider
pub static PROVIDER_ADDRESS: &str = "EWa8DgePKfuWSjqPo6NEdavBK6gpnK4TKb2npi2HWuC2.6PGVT9y83UMGbFrPKDnCvTP2jJjpXYpD87ZpiRsLo1YR@CgQrYP8etksSBf4nALNqp93SHPpgFwEUyTsjBNNLj5WM";
const DEFAULT_ETH_ENDPOINT: &str = "https://rinkeby.infura.io/v3/00000000000000000000000000000000";
@@ -50,9 +52,10 @@ impl Config {
self.socks5.get_base_mut()
}
pub async fn init() {
pub async fn init(service_provider: Option<&String>) {
let service_provider = service_provider.map_or(PROVIDER_ADDRESS, String::as_str);
info!("Initialising...");
init_socks5(PROVIDER_ADDRESS, None).await;
init_socks5(service_provider, None).await;
info!("Configuration saved 🚀");
}
}
+2
View File
@@ -10,6 +10,8 @@ pub enum BackendError {
CouldNotConnect,
#[error("Could not disconnect")]
CouldNotDisconnect,
#[error("No serverice provider set")]
NoServiceProviderSet,
}
impl Serialize for BackendError {
+2
View File
@@ -34,6 +34,8 @@ fn main() {
tauri::Builder::default()
.manage(Arc::new(RwLock::new(State::new())))
.invoke_handler(tauri::generate_handler![
crate::operations::connection::connect::get_service_provider,
crate::operations::connection::connect::set_service_provider,
crate::operations::connection::connect::start_connecting,
crate::operations::connection::disconnect::start_disconnecting,
crate::operations::window::hide_window,
@@ -18,3 +18,24 @@ pub async fn start_connecting(
address: "Test".to_string(),
})
}
#[tauri::command]
pub async fn get_service_provider(
state: tauri::State<'_, Arc<RwLock<State>>>,
) -> Result<String, BackendError> {
let guard = state.read().await;
guard
.get_service_provider()
.clone()
.ok_or(BackendError::NoServiceProviderSet)
}
#[tauri::command]
pub async fn set_service_provider(
service_provider: String,
state: tauri::State<'_, Arc<RwLock<State>>>,
) -> Result<(), BackendError> {
let mut guard = state.write().await;
guard.set_service_provider(service_provider);
Ok(())
}
+13 -3
View File
@@ -16,6 +16,7 @@ use tauri::Manager;
pub struct State {
status: ConnectionStatusKind,
service_provider: Option<String>,
socks5_client_sender: Option<Socks5ControlMessageSender>,
}
@@ -23,6 +24,7 @@ impl State {
pub fn new() -> Self {
State {
status: ConnectionStatusKind::Disconnected,
service_provider: None,
socks5_client_sender: None,
}
}
@@ -42,8 +44,16 @@ impl State {
.unwrap();
}
pub async fn init_config() {
crate::config::Config::init().await;
pub fn get_service_provider(&self) -> &Option<String> {
&self.service_provider
}
pub fn set_service_provider(&mut self, provider: String) {
self.service_provider = Some(provider);
}
pub async fn init_config(&self) {
crate::config::Config::init(self.service_provider.as_ref()).await;
}
pub async fn start_connecting(&mut self, window: &tauri::Window<tauri::Wry>) {
@@ -52,7 +62,7 @@ impl State {
self.status = ConnectionStatusKind::Connecting;
// Setup configuration by writing to file
Self::init_config().await;
self.init_config().await;
// Kick of the main task and get the channel for controlling it
let sender = start_nym_socks5_client();