Skip to content

Commit

Permalink
Merge pull request #1105 from rainlanguage/2024-12-20-dotrain-yaml-gui
Browse files Browse the repository at this point in the history
Implement gui in DotrainYaml
  • Loading branch information
hardyjosh authored Jan 3, 2025
2 parents 13efd23 + 7103ae5 commit 5f8e54c
Show file tree
Hide file tree
Showing 11 changed files with 728 additions and 45 deletions.
8 changes: 4 additions & 4 deletions crates/js_api/src/gui/deposits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl DotrainOrderGui {
.deployment
.deposits
.iter()
.find(|dg| dg.token_name == *token)
.find(|dg| dg.token.key == *token)
.ok_or(GuiError::DepositTokenNotFound(token.clone()))?;
let amount: String = if value.is_preset {
gui_deposit
Expand All @@ -33,7 +33,7 @@ impl DotrainOrderGui {
value.value.clone()
};
Ok(TokenDeposit {
token: gui_deposit.token_name.clone(),
token: gui_deposit.token.key.clone(),
amount,
address: gui_deposit.token.address,
})
Expand All @@ -47,7 +47,7 @@ impl DotrainOrderGui {
.deployment
.deposits
.iter()
.find(|dg| dg.token_name == token)
.find(|dg| dg.token.key == token)
.ok_or(GuiError::DepositTokenNotFound(token.clone()))?;

let value = if let Some(index) = gui_deposit.presets.iter().position(|p| **p == amount) {
Expand Down Expand Up @@ -77,7 +77,7 @@ impl DotrainOrderGui {
.deployment
.deposits
.iter()
.find(|dg| dg.token_name == token)
.find(|dg| dg.token.key == token)
.ok_or(GuiError::DepositTokenNotFound(token.clone()))?;
Ok(gui_deposit.presets.clone())
}
Expand Down
8 changes: 3 additions & 5 deletions crates/js_api/src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl DotrainOrderGui {
}

if let Some(select_tokens) = &select_tokens {
if select_tokens.contains_key(&token.token_name) {
if select_tokens.contains_key(&token.token.key) {
continue;
}
}
Expand All @@ -120,10 +120,8 @@ impl DotrainOrderGui {
let (_, gui_deployment) = gui_config
.deployments
.into_iter()
.find(|(name, _)| name == &self.deployment.deployment_name)
.ok_or(GuiError::DeploymentNotFound(
self.deployment.deployment_name.clone(),
))?;
.find(|(name, _)| name == &self.deployment.key)
.ok_or(GuiError::DeploymentNotFound(self.deployment.key.clone()))?;
self.deployment = gui_deployment.clone();
Ok(())
}
Expand Down
18 changes: 7 additions & 11 deletions crates/js_api/src/gui/order_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,14 @@ impl DotrainOrderGui {

let calldatas = self
.dotrain_order
.generate_approval_calldatas(
&self.deployment.deployment_name,
&owner,
&self.get_deposits_as_map()?,
)
.generate_approval_calldatas(&self.deployment.key, &owner, &self.get_deposits_as_map()?)
.await?;
Ok(ApprovalCalldataResult(calldatas))
}

fn populate_vault_ids(&mut self) -> Result<(), GuiError> {
self.dotrain_order
.populate_vault_ids(&self.deployment.deployment_name, None)?;
.populate_vault_ids(&self.deployment.key, None)?;
self.refresh_gui_deployment()?;
Ok(())
}
Expand Down Expand Up @@ -196,7 +192,7 @@ impl DotrainOrderGui {
.collect::<Result<HashMap<_, _>, GuiError>>()?;
let calldatas = self
.dotrain_order
.generate_deposit_calldatas(&self.deployment.deployment_name, &token_deposits)
.generate_deposit_calldatas(&self.deployment.key, &token_deposits)
.await?;
Ok(DepositCalldataResult(calldatas))
}
Expand All @@ -211,7 +207,7 @@ impl DotrainOrderGui {
self.update_config_source_bindings()?;
let calldata = self
.dotrain_order
.generate_add_order_calldata(&self.deployment.deployment_name)
.generate_add_order_calldata(&self.deployment.key)
.await?;
Ok(AddOrderCalldataResult(calldata))
}
Expand Down Expand Up @@ -239,11 +235,11 @@ impl DotrainOrderGui {
let mut calls = Vec::new();
let deposit_calldatas = self
.dotrain_order
.generate_deposit_calldatas(&self.deployment.deployment_name, &token_deposits)
.generate_deposit_calldatas(&self.deployment.key, &token_deposits)
.await?;
let add_order_calldata = self
.dotrain_order
.generate_add_order_calldata(&self.deployment.deployment_name)
.generate_add_order_calldata(&self.deployment.key)
.await?;

calls.push(Bytes::copy_from_slice(&add_order_calldata));
Expand All @@ -264,7 +260,7 @@ impl DotrainOrderGui {
vault_id: String,
) -> Result<(), GuiError> {
self.dotrain_order.set_vault_id(
&self.deployment.deployment_name,
&self.deployment.key,
is_input,
index,
U256::from_str(&vault_id)?,
Expand Down
2 changes: 1 addition & 1 deletion crates/js_api/src/gui/state_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl DotrainOrderGui {
.deployment
.deposits
.iter()
.find(|dg| dg.token_name == *k)
.find(|dg| dg.token.key == *k)
.ok_or(GuiError::DepositTokenNotFound(k.clone()))?;
let preset = if v.is_preset {
let id = gui_deposit
Expand Down
7 changes: 6 additions & 1 deletion crates/settings/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,12 @@ impl TryFrom<ConfigSource> for Config {
let tokens = item
.tokens
.into_iter()
.map(|(name, token)| Ok((name, Arc::new(token.try_into_token(&networks)?))))
.map(|(name, token)| {
Ok((
name.clone(),
Arc::new(token.try_into_token(&name, &networks)?),
))
})
.collect::<Result<HashMap<String, Arc<Token>>, ParseConfigSourceError>>()?;

let deployers = item
Expand Down
Loading

0 comments on commit 5f8e54c

Please sign in to comment.