Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
hardingjam committed Jan 27, 2025
1 parent 0c1d830 commit 88aafb4
Show file tree
Hide file tree
Showing 59 changed files with 3,301 additions and 574 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/tauri-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ jobs:
- uses: DeterminateSystems/magic-nix-cache-action@v2

- run: ./prep-all.sh
env:
PUBLIC_WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }}

- run: nix develop .#tauri-shell -c ob-tauri-unit-test

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/tauri.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ jobs:
- uses: DeterminateSystems/magic-nix-cache-action@v2

- run: ./prep-all.sh
env:
PUBLIC_WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }}

- run: nix develop .#tauri-shell -c ob-tauri-unit-test

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test-ui-components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
- uses: DeterminateSystems/magic-nix-cache-action@main

- run: ./prep-all.sh
env:
PUBLIC_WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }}

- run: nix develop -c npm run svelte-lint-format-check
working-directory: packages/ui-components
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/test-webapp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@ jobs:
- uses: DeterminateSystems/magic-nix-cache-action@main

- run: ./prep-all.sh
env:
PUBLIC_WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }}

- run: nix develop -c npm run svelte-lint-format-check
working-directory: packages/webapp
env:
PUBLIC_WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }}

- run: nix develop -c npm run test
working-directory: packages/webapp
env:
PUBLIC_WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }}
4 changes: 4 additions & 0 deletions .github/workflows/vercel-preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ jobs:
- uses: DeterminateSystems/magic-nix-cache-action@main

- run: ./prep-all.sh
env:
PUBLIC_WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }}

- run: nix develop .#webapp-shell -c npm run build
working-directory: packages/webapp
env:
PUBLIC_WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }}

- name: Install Vercel CLI
run: npm install --global vercel@canary
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/vercel-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ jobs:
- uses: DeterminateSystems/magic-nix-cache-action@main

- run: ./prep-all.sh
env:
PUBLIC_WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }}

- run: nix develop .#webapp-shell -c npm run build
working-directory: packages/webapp
env:
PUBLIC_WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }}

- name: Install Vercel CLI
run: npm install --global vercel@canary
Expand Down
32 changes: 20 additions & 12 deletions crates/js_api/src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use base64::{engine::general_purpose::URL_SAFE, Engine};
use flate2::{read::GzDecoder, write::GzEncoder, Compression};
use rain_orderbook_app_settings::{
deployment::Deployment,
gui::{Gui, GuiDeployment, GuiFieldDefinition, GuiPreset, ParseGuiConfigSourceError},
gui::{
Gui, GuiDeployment, GuiFieldDefinition, GuiPreset, NameAndDescription,
ParseGuiConfigSourceError,
},
network::Network,
order::Order,
yaml::YamlError,
Expand Down Expand Up @@ -39,11 +42,8 @@ pub struct TokenInfo {
impl_all_wasm_traits!(TokenInfo);

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Tsify)]
pub struct GuiDetails {
name: String,
description: String,
}
impl_all_wasm_traits!(GuiDetails);
pub struct DeploymentDetails(BTreeMap<String, NameAndDescription>);
impl_all_wasm_traits!(DeploymentDetails);

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[wasm_bindgen]
Expand Down Expand Up @@ -87,7 +87,7 @@ impl DotrainOrderGui {
let gui = self
.dotrain_order
.dotrain_yaml()
.get_gui()?
.get_gui(Some(self.selected_deployment.clone()))?
.ok_or(GuiError::GuiConfigNotFound)?;
Ok(gui)
}
Expand Down Expand Up @@ -146,11 +146,19 @@ impl DotrainOrderGui {
Ok(token_info)
}

#[wasm_bindgen(js_name = "getGuiDetails")]
pub fn get_gui_details(&self) -> Result<GuiDetails, GuiError> {
let (name, description) =
Gui::parse_gui_details(self.dotrain_order.dotrain_yaml().documents.clone())?;
Ok(GuiDetails { name, description })
#[wasm_bindgen(js_name = "getStrategyDetails")]
pub async fn get_strategy_details(dotrain: String) -> Result<NameAndDescription, GuiError> {
let dotrain_order = DotrainOrder::new(dotrain, None).await?;
let details = Gui::parse_strategy_details(dotrain_order.dotrain_yaml().documents.clone())?;
Ok(details)
}

#[wasm_bindgen(js_name = "getDeploymentDetails")]
pub async fn get_deployment_details(dotrain: String) -> Result<DeploymentDetails, GuiError> {
let dotrain_order = DotrainOrder::new(dotrain, None).await?;
let deployment_details =
Gui::parse_deployment_details(dotrain_order.dotrain_yaml().documents.clone())?;
Ok(DeploymentDetails(deployment_details.into_iter().collect()))
}
}

Expand Down
23 changes: 15 additions & 8 deletions crates/settings/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use strict_yaml_rust::StrictYaml;
use thiserror::Error;
use typeshare::typeshare;
use yaml::{
context::Context, default_document, require_hash, require_string, YamlError, YamlParsableHash,
context::{Context, GuiContextTrait},
default_document, require_hash, require_string, YamlError, YamlParsableHash,
};

#[cfg(target_family = "wasm")]
Expand Down Expand Up @@ -59,28 +60,34 @@ impl YamlParsableHash for Deployment {
) -> Result<HashMap<String, Self>, YamlError> {
let mut deployments = HashMap::new();

let orders = Order::parse_all_from_yaml(documents.clone(), context)?;

for document in &documents {
let document_read = document.read().map_err(|_| YamlError::ReadLockError)?;

if let Ok(deployments_hash) = require_hash(&document_read, Some("deployments"), None) {
for (key_yaml, deployment_yaml) in deployments_hash {
let deployment_key = key_yaml.as_str().unwrap_or_default().to_string();

if let Some(context) = context {
if let Some(current_deployment) = context.get_current_deployment() {
if current_deployment != &deployment_key {
continue;
}
}
}

let mut context = Context::from_context(context);

let order_key = require_string(
deployment_yaml,
Some("order"),
Some(format!(
"order string missing in deployment: {deployment_key}"
)),
)?;
let order = orders
.get(&order_key)
.ok_or_else(|| YamlError::KeyNotFound(order_key.clone()))?
.clone();
context.add_current_order(order_key.clone());

let mut context = Context::new();
let order =
Order::parse_from_yaml(documents.clone(), &order_key, Some(&context))?;
context.add_order(Arc::new(order.clone()));

let scenario = Scenario::parse_from_yaml(
Expand Down
79 changes: 72 additions & 7 deletions crates/settings/src/gui.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::{
yaml::{
context::Context, default_document, get_hash_value, optional_hash, optional_string,
optional_vec, require_string, require_vec, YamlError, YamlParsableHash, YamlParseableValue,
context::{Context, GuiContextTrait},
default_document, get_hash_value, optional_hash, optional_string, optional_vec,
require_string, require_vec, YamlError, YamlParsableHash, YamlParseableValue,
},
Deployment, Token, TokenRef,
};
Expand Down Expand Up @@ -248,6 +249,15 @@ pub struct Gui {
#[cfg(target_family = "wasm")]
impl_all_wasm_traits!(Gui);

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[cfg_attr(target_family = "wasm", derive(Tsify))]
pub struct NameAndDescription {
pub name: String,
pub description: String,
}
#[cfg(target_family = "wasm")]
impl_all_wasm_traits!(NameAndDescription);

impl Gui {
pub fn parse_deployment_keys(
documents: Vec<Arc<RwLock<StrictYaml>>>,
Expand Down Expand Up @@ -309,9 +319,9 @@ impl Gui {
Ok(None)
}

pub fn parse_gui_details(
pub fn parse_strategy_details(
documents: Vec<Arc<RwLock<StrictYaml>>>,
) -> Result<(String, String), YamlError> {
) -> Result<NameAndDescription, YamlError> {
for document in documents {
let document_read = document.read().map_err(|_| YamlError::ReadLockError)?;

Expand All @@ -332,12 +342,59 @@ impl Gui {
Some("description field must be a string in gui".to_string()),
)?;

return Ok((name, description));
return Ok(NameAndDescription { name, description });
}
}
Err(YamlError::ParseError("gui details not found".to_string()))
}

pub fn parse_deployment_details(
documents: Vec<Arc<RwLock<StrictYaml>>>,
) -> Result<HashMap<String, NameAndDescription>, YamlError> {
let mut deployment_details = HashMap::new();

for document in documents {
let document_read = document.read().map_err(|_| YamlError::ReadLockError)?;

if let Some(gui) = optional_hash(&document_read, "gui") {
let deployments = gui
.get(&StrictYaml::String("deployments".to_string()))
.ok_or(YamlError::ParseError(
"deployments field missing in gui".to_string(),
))?
.as_hash()
.ok_or(YamlError::ParseError(
"deployments field must be a map in gui".to_string(),
))?;

for (key_yaml, deployment_yaml) in deployments {
let deployment_key = key_yaml.as_str().unwrap_or_default().to_string();

let name = require_string(
deployment_yaml,
Some("name"),
Some(format!(
"name string missing in gui deployment: {deployment_key}"
)),
)?;

let description = require_string(
deployment_yaml,
Some("description"),
Some(format!(
"description string missing in gui deployment: {deployment_key}"
)),
)?;

deployment_details
.insert(deployment_key, NameAndDescription { name, description });
}
}
}

Ok(deployment_details)
}

pub fn parse_field_presets(
documents: Vec<Arc<RwLock<StrictYaml>>>,
deployment_key: &str,
Expand Down Expand Up @@ -421,7 +478,7 @@ impl YamlParseableValue for Gui {

fn parse_from_yaml_optional(
documents: Vec<Arc<RwLock<StrictYaml>>>,
_: Option<&Context>,
context: Option<&Context>,
) -> Result<Option<Self>, YamlError> {
let mut gui_res: Option<Gui> = None;
let mut gui_deployments_res: HashMap<String, GuiDeployment> = HashMap::new();
Expand Down Expand Up @@ -469,7 +526,15 @@ impl YamlParseableValue for Gui {
for (deployment_name, deployment_yaml) in deployments {
let deployment_name = deployment_name.as_str().unwrap_or_default().to_string();

let mut context = Context::new();
if let Some(context) = context {
if let Some(current_deployment) = context.get_current_deployment() {
if current_deployment != &deployment_name {
continue;
}
}
}

let mut context = Context::from_context(context);

let select_tokens = match optional_vec(deployment_yaml, "select-tokens") {
Some(tokens) => Some(
Expand Down
10 changes: 9 additions & 1 deletion crates/settings/src/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use strict_yaml_rust::StrictYaml;
use thiserror::Error;
use typeshare::typeshare;
use yaml::{
context::{Context, SelectTokensContext},
context::{Context, GuiContextTrait, SelectTokensContext},
default_document, optional_string, require_hash, require_string, require_vec, YamlError,
YamlParsableHash,
};
Expand Down Expand Up @@ -367,6 +367,14 @@ impl YamlParsableHash for Order {
for (key_yaml, order_yaml) in orders_hash {
let order_key = key_yaml.as_str().unwrap_or_default().to_string();

if let Some(context) = context {
if let Some(current_order) = context.get_current_order() {
if current_order != &order_key {
continue;
}
}
}

let mut network: Option<Arc<Network>> = None;

let deployer = match optional_string(order_yaml, "deployer") {
Expand Down
Loading

0 comments on commit 88aafb4

Please sign in to comment.