diff --git a/crates/common/src/dotrain_order/mod.rs b/crates/common/src/dotrain_order/mod.rs index eef3c5386..927638fb2 100644 --- a/crates/common/src/dotrain_order/mod.rs +++ b/crates/common/src/dotrain_order/mod.rs @@ -28,6 +28,12 @@ pub struct DotrainOrder { orderbook_yaml: OrderbookYaml, } +impl PartialEq for DotrainOrder { + fn eq(&self, other: &Self) -> bool { + self.dotrain == other.dotrain + } +} + #[derive(Error, Debug)] pub enum DotrainOrderError { #[error(transparent)] diff --git a/crates/js_api/src/gui/mod.rs b/crates/js_api/src/gui/mod.rs index b6dcce7e6..c230b571a 100644 --- a/crates/js_api/src/gui/mod.rs +++ b/crates/js_api/src/gui/mod.rs @@ -4,7 +4,7 @@ use base64::{engine::general_purpose::URL_SAFE, Engine}; use flate2::{read::GzDecoder, write::GzEncoder, Compression}; use rain_orderbook_app_settings::{ gui::{Gui, GuiDeployment, GuiFieldDefinition, GuiPreset, ParseGuiConfigSourceError}, - Config, + yaml::YamlError, }; use rain_orderbook_bindings::{impl_all_wasm_traits, wasm_traits::prelude::*}; use rain_orderbook_common::{ @@ -47,10 +47,12 @@ impl DotrainOrderGui { dotrain: String, ) -> Result { let dotrain_order = DotrainOrder::new(dotrain, None).await?; - let config = dotrain_order.config(); - let gui_config = config.gui.clone().ok_or(GuiError::GuiConfigNotFound)?; + let gui = dotrain_order + .dotrain_yaml() + .get_gui()? + .ok_or(GuiError::GuiConfigNotFound)?; Ok(AvailableDeployments( - gui_config.deployments.values().cloned().collect(), + gui.deployments.values().cloned().collect(), )) } @@ -62,10 +64,12 @@ impl DotrainOrderGui { ) -> Result { let dotrain_order = DotrainOrder::new(dotrain, None).await?; - let config = dotrain_order.config(); - let gui_config = config.gui.clone().ok_or(GuiError::GuiConfigNotFound)?; + let gui = dotrain_order + .dotrain_yaml() + .get_gui()? + .ok_or(GuiError::GuiConfigNotFound)?; - let (_, gui_deployment) = gui_config + let (_, gui_deployment) = gui .deployments .into_iter() .find(|(name, _)| name == &deployment_name) @@ -115,9 +119,12 @@ impl DotrainOrderGui { } fn refresh_gui_deployment(&mut self) -> Result<(), GuiError> { - let config = self.dotrain_order.config(); - let gui_config = config.gui.clone().ok_or(GuiError::GuiConfigNotFound)?; - let (_, gui_deployment) = gui_config + let gui = self + .dotrain_order + .dotrain_yaml() + .get_gui()? + .ok_or(GuiError::GuiConfigNotFound)?; + let (_, gui_deployment) = gui .deployments .into_iter() .find(|(name, _)| name == &self.deployment.key) @@ -126,14 +133,14 @@ impl DotrainOrderGui { Ok(()) } - #[wasm_bindgen(js_name = "getDotrainConfig")] - pub fn get_dotrain_config(&self) -> Config { - self.dotrain_order.config().clone() - } - #[wasm_bindgen(js_name = "getGuiConfig")] - pub fn get_gui_config(&self) -> Gui { - self.dotrain_order.config().gui.clone().unwrap() + pub fn get_gui_config(&self) -> Result { + let gui = self + .dotrain_order + .dotrain_yaml() + .get_gui()? + .ok_or(GuiError::GuiConfigNotFound)?; + Ok(gui) } #[wasm_bindgen(js_name = "getCurrentDeployment")] @@ -216,6 +223,8 @@ pub enum GuiError { SerdeWasmBindgenError(#[from] serde_wasm_bindgen::Error), #[error(transparent)] DotrainOrderCalldataError(#[from] DotrainOrderCalldataError), + #[error(transparent)] + YamlError(#[from] YamlError), } impl From for JsValue { fn from(value: GuiError) -> Self { diff --git a/crates/js_api/src/gui/order_operations.rs b/crates/js_api/src/gui/order_operations.rs index 2a0b754f8..afba904b5 100644 --- a/crates/js_api/src/gui/order_operations.rs +++ b/crates/js_api/src/gui/order_operations.rs @@ -153,21 +153,21 @@ impl DotrainOrderGui { } fn populate_vault_ids(&mut self) -> Result<(), GuiError> { - self.dotrain_order - .populate_vault_ids(&self.deployment.key, None)?; - self.refresh_gui_deployment()?; + // self.dotrain_order + // .populate_vault_ids(&self.deployment.key, None)?; + // self.refresh_gui_deployment()?; Ok(()) } fn update_config_source_bindings(&mut self) -> Result<(), GuiError> { - self.dotrain_order.update_config_source_bindings( - &self.deployment.deployment.scenario.key, - self.field_values - .iter() - .map(|(k, _)| Ok((k.clone(), self.get_field_value(k.clone())?.value.clone()))) - .collect::, GuiError>>()?, - )?; - self.refresh_gui_deployment()?; + // self.dotrain_order.update_config_source_bindings( + // &self.deployment.deployment.scenario.key, + // self.field_values + // .iter() + // .map(|(k, _)| Ok((k.clone(), self.get_field_value(k.clone())?.value.clone()))) + // .collect::, GuiError>>()?, + // )?; + // self.refresh_gui_deployment()?; Ok(()) } @@ -259,12 +259,13 @@ impl DotrainOrderGui { index: u8, vault_id: String, ) -> Result<(), GuiError> { - self.dotrain_order.set_vault_id( - &self.deployment.key, - is_input, - index, - U256::from_str(&vault_id)?, - )?; - self.refresh_gui_deployment() + // self.dotrain_order.set_vault_id( + // &self.deployment.key, + // is_input, + // index, + // U256::from_str(&vault_id)?, + // )?; + // self.refresh_gui_deployment() + Ok(()) } } diff --git a/crates/js_api/src/gui/select_tokens.rs b/crates/js_api/src/gui/select_tokens.rs index 4c9bada76..5b73635c8 100644 --- a/crates/js_api/src/gui/select_tokens.rs +++ b/crates/js_api/src/gui/select_tokens.rs @@ -63,9 +63,9 @@ impl DotrainOrderGui { let token_info = erc20.token_info(None).await?; self.onchain_token_info.insert(address, token_info); - self.dotrain_order - .update_token_address(token_name, address)?; - self.refresh_gui_deployment()?; + // self.dotrain_order + // .update_token_address(token_name, address)?; + // self.refresh_gui_deployment()?; Ok(()) } } diff --git a/crates/js_api/src/gui/state_management.rs b/crates/js_api/src/gui/state_management.rs index e4c930733..cbdd5707a 100644 --- a/crates/js_api/src/gui/state_management.rs +++ b/crates/js_api/src/gui/state_management.rs @@ -3,24 +3,14 @@ use sha2::{Digest, Sha256}; #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] struct SerializedGuiState { - config_hash: String, field_values: BTreeMap, deposits: BTreeMap, } #[wasm_bindgen] impl DotrainOrderGui { - fn compute_config_hash(&self) -> String { - let config = self.get_gui_config(); - let bytes = bincode::serialize(&config).expect("Failed to serialize config"); - let hash = Sha256::digest(&bytes); - format!("{:x}", hash) - } - #[wasm_bindgen(js_name = "serializeState")] pub fn serialize(&self) -> Result { - let config_hash = self.compute_config_hash(); - let mut field_values = BTreeMap::new(); for (k, v) in self.field_values.iter() { let preset = if v.is_preset { @@ -74,7 +64,6 @@ impl DotrainOrderGui { } let state = SerializedGuiState { - config_hash, field_values: field_values.clone(), deposits: deposits.clone(), }; @@ -137,10 +126,6 @@ impl DotrainOrderGui { self.field_values = field_values; self.deposits = deposits; - if state.config_hash != self.compute_config_hash() { - return Err(GuiError::DeserializedConfigMismatch); - } - Ok(()) }