Skip to content

Remove config source #1689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open

Remove config source #1689

wants to merge 46 commits into from

Conversation

findolor
Copy link
Collaborator

@findolor findolor commented Apr 22, 2025

Motivation

See issue: #1364

Solution

Checks

By submitting this for review, I'm confirming I've done the following:

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs
  • [ ] included screenshots (if this involves a front-end change)

fix #1364

Summary by CodeRabbit

  • New Features

    • Introduced a unified configuration structure with nested sections for orderbook and dotrain order settings, including detailed getter methods and error handling.
    • Added a WASM interface for parsing YAML configuration files into typed config objects.
    • Enhanced test fixtures and mock data with comprehensive YAML examples for robust testing.
  • Refactor

    • Replaced legacy ConfigSource and related intermediate types with a new Config structure for more consistent and modular configuration management.
    • Standardized config property names (e.g., chainId instead of chain-id) and updated all usages across the application.
    • Updated all configuration access patterns to use nested objects and explicit keys, improving type safety and clarity.
    • Updated UI components and stores to use new config types and nested structures, including richer subgraph and account objects.
    • Simplified configuration parsing and merging by consolidating into synchronous YAML parsing with validation flags.
    • Removed legacy conversion methods and intermediate config source types across the codebase.
  • Bug Fixes

    • Improved error messages and validation for missing or invalid configuration fields.
    • Enhanced handling of subgraph and account references to use richer objects instead of plain strings.
  • Chores

    • Removed obsolete modules, types, and merging logic related to old config structures.
    • Updated test suites, fixtures, and mocks to align with the new configuration schema and data structures.
    • Cleaned up imports and error enums to consolidate and rename error types for consistency.
    • Updated all references and tests to reflect renaming of stores, props, and variables (e.g., subgraphUrl to subgraph).
    • Streamlined error enums and command error variants to unify parsing error handling.

@findolor findolor added the rust Related to rust crates label Apr 22, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

♻️ Duplicate comments (4)
crates/settings/src/orderbook.rs (1)

37-39: 🧹 Nitpick (assertive)

Surface hex-parsing failures verbatim in error message

The error message in AddressParseError currently hard-codes "Failed to parse address" rather than including the specific FromHexError details, requiring additional calls to to_readable_msg() to see the actual problem.

Consider forwarding the error in the #[error] attribute to provide more precise feedback:

-#[error("Failed to parse address")]
+#[error("Invalid orderbook address: {0}")]
 AddressParseError(FromHexError),

This would give users the exact reason (e.g., "Invalid orderbook address: odd number of digits") when printing the error.

crates/settings/src/config.rs (3)

89-92: accounts wrapped in Arc<String> adds needless indirection

User-supplied account labels/addresses are unlikely to be shared across
threads; a plain String (or even Address) is sufficient and simpler:

-accounts: Option<HashMap<String, Arc<String>>>,
+accounts: Option<HashMap<String, String>>,

Re-evaluate if there’s a hard requirement for Arc.


124-129: ⚠️ Potential issue

Error variants & messages are cross-wired – will confuse users

OrderNotFound, TokenNotFound, and DeployerNotFound display the wrong
resource in their error text.

-#[error("Token not found: {0}")]
-OrderNotFound(String),
-#[error("Deployer not found: {0}")]
-TokenNotFound(String),
-#[error("Order not found: {0}")]
-DeployerNotFound(String),
+#[error("Order not found: {0}")]
+OrderNotFound(String),
+#[error("Token not found: {0}")]
+TokenNotFound(String),
+#[error("Deployer not found: {0}")]
+DeployerNotFound(String),

Please swap either the variant names or the #[error] strings so they match.


153-155: 🧹 Nitpick (assertive)

settings.clone() makes a full copy – avoid the extra allocation

DotrainYaml::new and OrderbookYaml::new only need read-only access to
the same strings. Instead of cloning the whole Vec, hand out
references:

-        let dotrain_yaml = DotrainYaml::new(settings.clone(), validate)?;
-        let orderbook_yaml = OrderbookYaml::new(settings, validate)?;
+        let dotrain_yaml = DotrainYaml::new(settings.iter().cloned().collect(), validate)?;
+        let orderbook_yaml = OrderbookYaml::new(settings, validate)?;

(or adjust the constructors to accept &[String]). Saves memory when
loading large config files.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0d6a1ad and 1be2596.

📒 Files selected for processing (7)
  • crates/js_api/src/config.rs (1 hunks)
  • crates/js_api/src/lib.rs (1 hunks)
  • crates/settings/src/config.rs (3 hunks)
  • crates/settings/src/orderbook.rs (3 hunks)
  • packages/ui-components/src/lib/components/detail/VaultDetail.svelte (1 hunks)
  • packages/webapp/src/routes/+layout.ts (17 hunks)
  • packages/webapp/test-setup.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
crates/js_api/src/config.rs (1)
crates/settings/src/config.rs (1)
  • try_from_settings (149-238)
packages/webapp/src/routes/+layout.ts (1)
tauri-app/src/lib/stores/settings.ts (5)
  • settings (25-36)
  • accounts (99-99)
  • activeAccountsItems (100-111)
  • subgraphUrl (82-86)
  • activeOrderbook (75-81)
⏰ Context from checks skipped due to timeout of 90000ms (15)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: test
  • GitHub Check: git-clean
  • GitHub Check: Deploy-Preview
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: build-tauri (ubuntu-22.04, true)
🔇 Additional comments (6)
crates/js_api/src/lib.rs (1)

1-3: LGTM: New config module for WASM exports

The addition of the config module alongside the existing WASM-only modules is consistent with the broader refactoring that replaces ConfigSource with the new Config type. This provides the necessary WASM bindings for the new configuration parsing approach.

packages/webapp/test-setup.ts (1)

16-19: LGTM: Added mock for parseSettings function

The mock implementation has been appropriately updated to include the new parseSettings function, which aligns with the migration from ConfigSource to the new synchronous config parsing approach.

packages/ui-components/src/lib/components/detail/VaultDetail.svelte (1)

43-43: LGTM: Updated access to subgraph URL via object property

Correctly updated to access the .url property from the subgraph configuration object, reflecting the new richer, strongly-typed Config structure where subgraphs are objects with explicit properties rather than simple strings.

crates/settings/src/orderbook.rs (2)

186-194: LGTM: Renamed error enum to match new architecture

The error enum has been appropriately renamed from ParseOrderbookConfigSourceError to ParseOrderbookCfgError, consistent with the removal of the ConfigSource type and the overall refactoring approach.


196-207: LGTM: Updated error implementation for the renamed enum

The implementation of the error enum has been correctly updated to use the new name, maintaining all the existing functionality for generating user-friendly error messages.

packages/webapp/src/routes/+layout.ts (1)

354-377: Changing network keeps a stale orderbook – consider auto-resetting activeOrderbookRef

When $activeNetworkRef changes, the previous activeOrderbookRef
might still point to an orderbook belonging to another network, leading
to inconsistent UI (seen in the test where orderbook1 remains active
after switching to network2).

A lightweight fix:

 $activeNetworkRef.subscribe((network) => {
   if (network && get(activeOrderbook)?.network.key !== network) {
-    // nothing happens – stale orderbook
+    activeOrderbookRef.set('');
   }
 });

Or, make activeOrderbook derived solely from activeNetworkRef

  • activeOrderbookRef to enforce the constraint.

Would you like me to draft the derived-store rewrite?

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🔭 Outside diff range comments (2)
crates/settings/src/unit_test.rs (1)

78-99: 💡 Verification agent

🧩 Analysis chain

Error handling has been removed from try_into_test_config method

The method has been simplified to return TestConfig directly without error handling, but the method name still starts with try_into_ which conventionally indicates that it might fail.

Consider either:

  1. Renaming the method to just into_test_config since it no longer tries and cannot fail, or
  2. Restore error handling if there are cases where the conversion might actually fail

🏁 Script executed:

#!/bin/bash
# Check if there are any callers of this method that expect Result<TestConfig, Error>
rg -A 2 -B 2 "try_into_test_config" --type rust

Length of output: 785


Rename try_into_test_config to into_test_config

The try_ prefix implies a fallible conversion, but this method always returns a TestConfig unconditionally. To avoid confusion, rename it and update its callers:

• In crates/settings/src/unit_test.rs

- pub fn try_into_test_config(self) -> TestConfig {
+ pub fn into_test_config(self) -> TestConfig {
    // …implementation unchanged…
}

• In crates/common/src/unit_tests/mod.rs

- source.test.try_into_test_config()
+ source.test.into_test_config()
tauri-app/src/lib/stores/settings.ts (1)

156-156: ⚠️ Potential issue

Fix logic error in the orderbooks undefined check

The current condition !$settings?.orderbooks === undefined has incorrect operator precedence. The negation (!) applies only to $settings?.orderbooks, creating a boolean that is then compared with === undefined.

Fix the condition to properly check if orderbooks is undefined:

-  if (
-    !$settings?.orderbooks === undefined ||
-    $activeOrderbookRef === undefined ||
-    ($settings?.orderbooks !== undefined &&
-      $activeOrderbookRef !== undefined &&
-      !Object.keys($settings.orderbooks).includes($activeOrderbookRef))
-  ) {
+  if (
+    $settings?.orderbooks === undefined ||
+    $activeOrderbookRef === undefined ||
+    ($settings?.orderbooks !== undefined &&
+      $activeOrderbookRef !== undefined &&
+      !Object.keys($settings.orderbooks).includes($activeOrderbookRef))
+  ) {
♻️ Duplicate comments (2)
packages/webapp/src/routes/+layout.ts (1)

30-37: 🧹 Nitpick (assertive)

Guard against missing network field in orderbook objects
The predicate assumes every orderbook has a truthy network field; corrupted configs will throw.

-        (orderbook) => orderbook.network.key === $activeNetworkRef
+        (orderbook) => orderbook.network?.key === $activeNetworkRef

A small check keeps the UI responsive even with partial data.

crates/settings/src/config.rs (1)

153-155: Cloning the entire settings vector is unnecessary (duplicate from earlier review)
DotrainYaml::new(settings.clone(), …) duplicates potentially large YAML blobs.
Passing a borrow or splitting the vector (as suggested previously) avoids the extra allocation.

(This has been pointed out in a past review; re-flagging for visibility.)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1be2596 and 40b7dbc.

📒 Files selected for processing (10)
  • crates/js_api/src/config.rs (1 hunks)
  • crates/settings/src/config.rs (3 hunks)
  • crates/settings/src/unit_test.rs (4 hunks)
  • crates/settings/src/yaml/orderbook.rs (6 hunks)
  • packages/webapp/src/routes/+layout.ts (17 hunks)
  • tauri-app/src/lib/services/configCodemirrorProblems.ts (1 hunks)
  • tauri-app/src/lib/services/order.ts (3 hunks)
  • tauri-app/src/lib/stores/order.ts (1 hunks)
  • tauri-app/src/lib/stores/settings.ts (7 hunks)
  • tauri-app/src/routes/orders/[network]-[orderHash]/page.test.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
tauri-app/src/lib/services/configCodemirrorProblems.ts (1)
tauri-app/src/lib/services/config.ts (1)
  • parseConfig (6-7)
tauri-app/src/lib/services/order.ts (1)
tauri-app/src/lib/stores/settings.ts (1)
  • subgraph (82-86)
tauri-app/src/lib/stores/order.ts (1)
tauri-app/src/lib/stores/settings.ts (1)
  • subgraph (82-86)
packages/webapp/src/routes/+layout.ts (2)
packages/ui-components/src/lib/index.ts (1)
  • AppStoresInterface (70-70)
tauri-app/src/lib/stores/settings.ts (5)
  • settings (25-36)
  • accounts (99-99)
  • activeAccountsItems (100-111)
  • subgraph (82-86)
  • activeOrderbook (75-81)
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: test
  • GitHub Check: Deploy-Preview
  • GitHub Check: git-clean
🔇 Additional comments (17)
tauri-app/src/lib/services/configCodemirrorProblems.ts (2)

3-3: Updated import to use the new Config approach

The import statement has been updated to use parseConfig instead of parseConfigSource, aligning with the PR objective to remove the config source.


9-9: Updated function call to use new parseConfig method

The function call has been correctly updated to use parseConfig with proper await keyword to ensure the Promise is resolved before proceeding.

tauri-app/src/lib/services/order.ts (2)

3-3: Updated import to use the new Config structure

The import has been updated to use subgraph instead of subgraphUrl, aligning with the PR objective to remove config source and use the new Config structure.


52-52: Correctly updated to access URL property from subgraph object

This line correctly accesses the url property from the subgraph object using the optional chaining operator, which is the right approach given the new Config structure.

tauri-app/src/lib/stores/order.ts (3)

3-3: Updated import to use the new Config structure

The import has been updated to use subgraph instead of subgraphUrl, aligning with the PR objective to remove config source.


19-22: Correctly updated to access URL property from subgraph object

These lines correctly load the subgraph and pass its URL property in the expected format for the order_trades_list function.


27-33: Correctly updated to access URL property from subgraph object

These lines correctly load the subgraph and pass its URL property in the expected format for the order_trades_list_write_csv function.

tauri-app/src/routes/orders/[network]-[orderHash]/page.test.ts (5)

4-4: Added Config type import

Added import for the Config type from orderbook package, which is used for type casting the mock settings object.


62-73: Updated mock data structure to match new Config format

The mock data structure has been updated to match the new Config format with nested objects for network and subgraph, each with explicit keys and URLs.


76-79: Updated subgraph mock data structure

The subgraph mock data has been updated to include both key and URL properties, aligning with the new Config structure.


82-86: Updated network mock data structure and renamed chainId property

The network mock data has been updated to include a key property, and the property name has been standardized from chain-id to chainId to match the new Config structure.


88-88: Added type casting for Config

The mock settings object is now properly type cast as Config to ensure type safety with the new structure.

crates/settings/src/yaml/orderbook.rs (2)

197-214: Good implementation of robust boolean parsing for sentry settings

The updated get_sentry method now correctly parses boolean values from YAML with proper case-insensitive handling and detailed error reporting.

Your implementation matches the previous review feedback perfectly - it now correctly handles case variations and provides clear error messages when invalid values are encountered.


101-103: Well-structured refactoring of entity retrieval methods

The addition of comprehensive get_<entity>s methods that return full mappings is a good design choice. Delegating the existing key retrieval methods to these new methods removes redundant parsing logic and improves maintainability.

Also applies to: 118-124, 139-145, 150-156, 171-177, 185-191

tauri-app/src/lib/stores/settings.ts (1)

9-9: Well-executed migration from ConfigSource to strongly-typed Config

The changes to import and use the new Config, OrderbookCfg, and SubgraphCfg types are comprehensive and consistent throughout the file. The updated code properly accesses nested properties of these structured configuration objects.

The migration from string-based configuration to the strongly-typed Config structure will improve type safety and make the codebase more maintainable.

Also applies to: 25-26, 31-31, 52-52, 71-73, 82-86, 123-126, 189-189

packages/webapp/src/routes/+layout.ts (2)

61-62: activeSubgraphs store appears unused
activeSubgraphs is created but never read or mutated anywhere in this file (nor in the tests).
Dead stores increase bundle size and cognitive load; please remove or wire it into the UI logic.


43-47: 🧹 Nitpick (assertive)

Same defensive null-check for subgraph.key
If an orderbook lacks a subgraph, the current expression throws. Apply optional-chaining for parity with the previous fix.

-  ? $settings.subgraphs[$activeOrderbook.subgraph.key]
+  ? $settings.subgraphs[$activeOrderbook.subgraph?.key]

Likely an incorrect or invalid review comment.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8

🔭 Outside diff range comments (1)
tauri-app/src/lib/stores/settings.ts (1)

188-197: 🧹 Nitpick (assertive)

Simplify filter operation for activeSubgraphs

The filtering of subgraphs is properly updated to compare value.key instead of the value directly. However, there's an opportunity to simplify this code.

Similar to a previous fix, you could simplify this by removing any redundant operations:

const updatedActiveSubgraphs = Object.fromEntries(
  Object.entries($settings.subgraphs).filter(([key, value]) => {
    if (key in currentActiveSubgraphs) {
      return currentActiveSubgraphs[key].key === value.key;
    }
    return false;
  })
);
♻️ Duplicate comments (1)
crates/settings/src/config.rs (1)

154-155: settings.clone() duplication revisit (already raised earlier)

Cloning the entire Vec<String> just to split between
DotrainYaml::new and OrderbookYaml::new still incurs an allocation.
Previously suggested slicing/iter duplication remains applicable.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 40b7dbc and 1be8254.

📒 Files selected for processing (14)
  • crates/js_api/src/config.rs (1 hunks)
  • crates/settings/src/config.rs (3 hunks)
  • packages/ui-components/src/__tests__/DropdownOrderListAccounts.test.ts (1 hunks)
  • packages/ui-components/src/lib/components/ListViewOrderbookFilters.svelte (1 hunks)
  • packages/ui-components/src/lib/components/dropdown/DropdownOrderListAccounts.svelte (1 hunks)
  • packages/ui-components/src/lib/components/tables/VaultsListTable.svelte (4 hunks)
  • packages/ui-components/src/lib/types/appStores.ts (1 hunks)
  • packages/webapp/src/routes/+layout.ts (17 hunks)
  • tauri-app/src/lib/services/order.ts (3 hunks)
  • tauri-app/src/lib/stores/order.ts (1 hunks)
  • tauri-app/src/lib/stores/settings.test.ts (5 hunks)
  • tauri-app/src/lib/stores/settings.ts (8 hunks)
  • tauri-app/src/routes/vaults/+page.svelte (2 hunks)
  • tauri-app/src/tests/pickConfig.test.ts (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
tauri-app/src/lib/stores/order.ts (1)
tauri-app/src/lib/stores/settings.ts (1)
  • subgraph (82-86)
tauri-app/src/lib/services/order.ts (1)
tauri-app/src/lib/stores/settings.ts (1)
  • subgraph (82-86)
tauri-app/src/lib/stores/settings.test.ts (1)
tauri-app/src/lib/stores/settings.ts (3)
  • settings (25-36)
  • activeAccountsItems (100-111)
  • activeSubgraphs (126-137)
packages/webapp/src/routes/+layout.ts (2)
packages/ui-components/src/lib/types/appStores.ts (1)
  • AppStoresInterface (3-20)
tauri-app/src/lib/stores/settings.ts (5)
  • settings (25-36)
  • accounts (99-99)
  • activeAccountsItems (100-111)
  • subgraph (82-86)
  • activeOrderbook (75-81)
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: test
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: test
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: test
  • GitHub Check: git-clean
  • GitHub Check: Deploy-Preview
🔇 Additional comments (40)
tauri-app/src/routes/vaults/+page.svelte (2)

8-8: LGTM: Import updated to use the new configuration structure

This change correctly updates the import from subgraphUrl to subgraph, aligning with the broader migration from simple string URLs to structured SubgraphCfg objects.


45-45: LGTM: Updated prop to pass the new subgraph object

The prop passed to the VaultsListTable component has been correctly updated from subgraphUrl to subgraph, ensuring the component receives the proper structured configuration object.

packages/ui-components/src/__tests__/DropdownOrderListAccounts.test.ts (2)

5-5: LGTM: Updated account type to use the new AccountCfg structure

The type definition has been properly updated to import and use the AccountCfg type from @rainlanguage/orderbook, which aligns with the broader migration to structured configuration objects.

Also applies to: 8-8


13-24: LGTM: Updated mock data to match the new AccountCfg structure

The test mock data has been correctly updated to use objects with address and key properties instead of simple strings, ensuring tests are consistent with the new data structure.

packages/ui-components/src/lib/components/dropdown/DropdownOrderListAccounts.svelte (2)

2-2: LGTM: Updated component to use the new AccountCfg type

The import and prop type declaration have been correctly updated to use the AccountCfg type from @rainlanguage/orderbook.

Also applies to: 5-5


7-9: LGTM: Updated options mapping to extract address from AccountCfg

The reactive statement has been properly modified to extract the address property from each AccountCfg value, ensuring the dropdown displays the correct information despite the change in the underlying data structure.

tauri-app/src/lib/services/order.ts (3)

3-3: LGTM: Updated import to use the new subgraph store

The import has been correctly updated from subgraphUrl to subgraph, aligning with the broader migration to structured configuration objects.


29-29: LGTM: Updated to use the subgraph URL property

The code now correctly accesses the URL property from the subgraph configuration object.


50-50: Fix missing optional chaining in URL access

The URL property is correctly accessed, but there's an inconsistency with the handling in line 29. Both should use optional chaining to safely access the URL property.

-      url: get(subgraph)?.url,
+      url: get(subgraph)?.url,

Wait, there's no actual issue here as the code already has optional chaining. This is correct as is.

tauri-app/src/lib/stores/order.ts (4)

3-3: Import updated to use new subgraph store

The import has been updated from subgraphUrl to subgraph to align with the new configuration structure where subgraphs are now objects with properties rather than simple URL strings.


10-11: Correctly implemented previous review feedback

This implementation properly addresses the previous review comment by passing only the URL property in a structured object ({ url: loadedSubgraph?.url }) rather than the entire subgraph object.


19-22: Consistent subgraph URL handling

The implementation correctly follows the same pattern for passing the subgraph URL, ensuring consistency across all invoke calls.


27-32: CSV export function updated consistently

The CSV export function has been updated to consistently use the same subgraph URL structure as other calls.

tauri-app/src/lib/stores/settings.test.ts (4)

6-6: Updated imports to use the new Config types

Imports have been updated to replace ConfigSource with Config and the specific config types needed for the tests.


9-54: Mock configuration updated to use new nested structure

The mock configuration has been properly updated to use the new Config structure with nested objects including explicit key properties and typed sub-objects for networks, subgraphs, orderbooks, and deployers.


71-75: Updated test expectations for subgraph structure

Test expectations have been updated to match the new structure of subgraphs, which now include a key property and a url property instead of being simple strings.


113-125: 🧹 Nitpick (assertive)

Consistent use of type casting in tests

Similar to the previous test case, this test also uses type casting. Consider refactoring the mock data structure to better match the expected types and reduce the need for type assertions.

Also applies to: 155-155

⛔ Skipped due to learnings
Learnt from: hardingjam
PR: rainlanguage/rain.orderbook#1615
File: packages/webapp/src/routes/deploy/+layout.ts:37-56
Timestamp: 2025-04-09T13:13:48.419Z
Learning: For test fixtures in the Rain codebase, it's acceptable to use type casting (e.g., `as unknown as SomeType[]`) for minimal test fixtures rather than creating fully-populated mock objects, especially when the internal structure of the mock data isn't critical to the tests.
packages/ui-components/src/lib/components/ListViewOrderbookFilters.svelte (2)

11-11: Updated imports for new configuration types

Imports have been updated to use the more granular types (AccountCfg, Config, SubgraphCfg) instead of the previous monolithic ConfigSource type, reflecting the new configuration model.


15-16: Updated prop types to match new configuration structure

The component's prop types have been correctly updated to use the new configuration structure:

  • settings now uses Config instead of ConfigSource
  • accounts now expects Record<string, AccountCfg> instead of a simple string map
  • activeSubgraphs now expects Record<string, SubgraphCfg> with the new subgraph structure

This change correctly aligns with the broader refactor to use a more structured configuration model.

Also applies to: 20-20

tauri-app/src/tests/pickConfig.test.ts (4)

4-4: Updated imports to match new configuration types

Import statements have been simplified to remove unused types (ConfigSource, DeploymentConfigSource) and retain only the necessary types (Config, DeploymentCfg, ScenarioCfg), aligning with the overall codebase cleanup.


174-181: Account structure updated to nested objects

The accounts field in the test configuration has been updated from simple string mappings to objects with key and address properties, consistent with the new AccountCfg type.


187-240: Test expectations updated for new deployment structure

The test expectations for pickDeployments have been properly updated to use the new nested structure with explicit keys and references to full network and subgraph details, reflecting the richer DeploymentCfg structure.


248-249: Consistent updates across all test functions

All test functions have been consistently updated to handle the new configuration structure, including this empty result test case.

crates/js_api/src/config.rs (2)

4-11: Implementation looks good - well-designed WASM binding

The implementation of this WASM binding function is clean and straightforward. I like that:

  1. It's a synchronous function - appropriate since no actual async work is being done
  2. It provides validation as an optional parameter with a sensible default
  3. It leverly leverages the Config::try_from_settings method to parse the settings

This aligns perfectly with the PR objective of removing the config source and simplifies the API.


175-188: Well-designed test with proper validation

The test ensures that parsing YAML configurations produces the same result whether done directly via Rust or through the WASM binding. This is an excellent verification strategy that confirms the consistency of the configuration parsing across language boundaries.

packages/ui-components/src/lib/types/appStores.ts (2)

2-2: Type imports correctly updated to use the new config system

The import statement is properly updated to import the new typed configuration models instead of the old ConfigSource types.


4-18: Interface properties properly migrated to structured config types

All interface properties have been consistently updated to use the new configuration types:

  1. settings is now Config instead of ConfigSource
  2. activeSubgraphs now uses structured SubgraphCfg objects
  3. subgraphUrl is renamed to subgraph and uses SubgraphCfg
  4. activeOrderbook and activeAccounts use their respective typed configs

This delivers on the PR's goal of removing config source dependencies throughout the codebase.

packages/ui-components/src/lib/components/tables/VaultsListTable.svelte (5)

13-18: Import statement correctly updated to use typed configs

The import statement is properly updated to import the new configuration types that replace the removed ConfigSource.


30-37: Props correctly updated to use structured config types

These props are properly updated to use the new configuration types (OrderbookCfg, SubgraphCfg, Config), replacing the old string-based or ConfigSource-based types.


41-43: activeAccounts type properly updated to use AccountCfg

The nested type definition for activeAccounts is correctly updated to use the new AccountCfg type.


54-59: Reactive statement updated to handle the new structure

The reactive statement for multiSubgraphArgs is properly updated to extract the URL from the SubgraphCfg object via value.url property instead of using the value directly, reflecting the migration from string values to structured objects.


92-93: Query enabled condition updated for new subgraph type

The enabled property of the query is correctly updated to check for the existence of the new subgraph store (renamed from subgraphUrl).

tauri-app/src/lib/stores/settings.ts (8)

9-9: Imports correctly updated to use the new config types

The import statement is properly updated to import the new configuration types that replace the removed ConfigSource.


25-36: Settings store type updated to use the new Config type

The settings store is correctly updated to use the new Config type instead of ConfigSource, along with appropriate JSON parsing logic.


52-52: Property access standardized to camelCase

The chainId derived store now directly accesses the chainId property instead of using the string key 'chain-id', which is a more consistent approach in TypeScript.


65-74: Filtering logic updated to use structured config types

The activeNetworkOrderbooks derived store is properly updated to filter orderbooks by comparing the structured orderbook.network.key to the active network reference, instead of using direct string comparisons.


82-86: Renamed and updated subgraph derived store

The store is properly renamed from subgraphUrl to subgraph and updated to access the subgraph configuration using the new nested structure via $activeOrderbook.subgraph.key.


123-126: Additional derived store for subgraph entries

A derived store for subgraph entries is properly added to provide access to the structured subgraph configurations.


126-137: ActiveSubgraphs writable store updated to structured type

The activeSubgraphs cached writable store is correctly updated to use the new Record<string, SubgraphCfg> type instead of strings.


170-179: Accounts filtering logic updated for structured types

The subscription callback for the settings store is properly updated to filter and map account entries based on the new structure, comparing value.address instead of the value directly.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

♻️ Duplicate comments (1)
tauri-app/src/lib/stores/settings.test.ts (1)

140-140: Type assertion used repeatedly in test cases

Multiple test cases use as unknown as Config to force type compatibility. While this works for tests, it would be better to properly type the test objects to avoid these casts.

Also applies to: 153-153, 164-164

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1be8254 and 34d9673.

📒 Files selected for processing (3)
  • packages/ui-components/src/lib/types/appStores.ts (1 hunks)
  • tauri-app/src/lib/services/order.ts (3 hunks)
  • tauri-app/src/lib/stores/settings.test.ts (5 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
tauri-app/src/lib/services/order.ts (1)
tauri-app/src/lib/stores/settings.ts (1)
  • subgraph (82-86)
tauri-app/src/lib/stores/settings.test.ts (1)
tauri-app/src/lib/stores/settings.ts (3)
  • settings (25-36)
  • activeAccountsItems (100-111)
  • activeSubgraphs (126-137)
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: test
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: test
  • GitHub Check: Deploy-Preview
  • GitHub Check: test
  • GitHub Check: git-clean
🔇 Additional comments (11)
tauri-app/src/lib/services/order.ts (3)

3-3: Updated import to use subgraph object from settings store

The import has been correctly updated to use subgraph instead of the previous subgraphUrl. This aligns with the broader PR changes replacing the config source with the structured Config object.


30-30: Correctly accessing URL property from subgraph object

The code now properly accesses the URL via the ?.url property from the subgraph object, with optional chaining to handle potential undefined values. This matches the new configuration structure where subgraphs are objects containing key and URL properties rather than simple string URLs.


52-52: Consistent parameter format for subgraph URL

The code now consistently passes subgraph information as an object with a URL property across both orderRemove and orderRemoveCalldata functions. This standardization addresses the inconsistency mentioned in previous review comments.

tauri-app/src/lib/stores/settings.test.ts (4)

4-4: Updated type imports to align with new Config structure

The imports have been correctly updated to use Config, NetworkCfg, and SubgraphCfg types from the orderbook package, which aligns with the PR's goal of replacing the legacy ConfigSource with the new Config type.


7-52: Refactored mock configuration to use the new structured Config type

The mock configuration has been properly restructured to use the new Config type with nested objects that have explicit key properties. Network and subgraph references now use typed objects instead of string keys.

I notice the continued use of type assertions (as unknown as NetworkCfg, as unknown as SubgraphCfg, as unknown as Config). While this works for tests, it might indicate a need for better type definitions to avoid these casts.

Could you check if it's possible to define the mock objects with proper types to avoid these type assertions? This would make the tests more type-safe and reduce the risk of errors.


69-73: Updated activeSubgraphs structure to match the new Config format

The activeSubgraphs test data has been correctly updated to use the object structure with key and url properties instead of simple strings, consistent with the changes in the main Config structure.


91-99: Updated account structure in test cases

The account structure has been correctly updated to use objects with key and address properties instead of simple string addresses, which aligns with the new Config structure.

packages/ui-components/src/lib/types/appStores.ts (4)

2-2: Imports updated to use new Config-based types

This change properly imports the new configuration types (AccountCfg, Config, OrderbookCfg, SubgraphCfg) that replace the previous ConfigSource-based system, aligning with the PR objective to remove the config source.


16-18: Type change for activeAccounts property

The activeAccounts property now uses AccountCfg objects instead of string values, which provides more structured configuration data. This is consistent with the overall migration from simple strings to richer configuration objects.


5-6:

✅ Verification successful

Data structure changes for subgraphs and accounts

The activeSubgraphs and accounts properties have been updated to use structured configuration objects (SubgraphCfg and AccountCfg) instead of simple string records. This change improves type safety but requires updates to any code that accesses these properties.


🏁 Script executed:

#!/bin/bash
# Check for any code that directly accesses properties of these objects
rg -A 2 -B 2 "activeSubgraphs\[|accounts\[" --type ts packages/ui-components/

Length of output: 79


I want to double-check if any code is still using dot- or bracket-access on these stores or referencing the new types elsewhere:


🏁 Script executed:

#!/bin/bash
# Look for any dot- or bracket-access to activeSubgraphs and accounts
rg -n "activeSubgraphs(\[|\.)" -A2 -B2 packages/ui-components
rg -n "accounts(\[|\.)" -A2 -B2 packages/ui-components

# Find all usages of the new types and the appStores export
rg -n "SubgraphCfg" -A2 -B2 .
rg -n "AccountCfg" -A2 -B2 .
rg -n "appStores" -A2 -B2 .

Length of output: 38129


Data structure changes for subgraphs and accounts applied consistently
Verification confirms that all component and test usages of activeSubgraphs and accounts now correctly use SubgraphCfg and AccountCfg. No remaining string‐based or outdated access patterns were detected.


4-4:

❓ Verification inconclusive

Settings type no longer allows undefined

The settings property has been updated to be Writable<Config> instead of Writable<ConfigSource | undefined>, removing the possibility of it being undefined. Ensure that any code initializing or accessing this property has been updated to always provide a valid Config object.


🏁 Script executed:

#!/bin/bash
# Search for code that initializes or accesses the settings store
rg -A 2 -B 2 "settings\s*=" --type ts packages/ui-components/

Length of output: 63


I couldn’t find any direct settings = assignments, so let’s locate the type file and then look for all writable usages and any implicit settings assignments across the UI package:

#!/bin/bash
set -e

# 1. Locate and dump the appStores type file
FILE=$(fd appStores.ts -t f)
echo "=== File: $FILE ==="
sed -n '1,200p' "$FILE"

# 2. List all places where stores are created
echo "=== All 'writable' usages ==="
rg -n "writable" packages/ui-components/

# 3. Search for any 'settings =' patterns (all file types)
echo "=== All 'settings =' assignments ==="
rg -n "settings\s*=" packages/ui-components/

Let’s locate where the settings store is actually created or initialized in the UI package:

#!/usr/bin/env bash
set -e

# 1. Dump the appStores type definition
FILE=$(fd appStores.ts -t f)
echo "=== appStores.ts ==="
sed -n '1,200p' "$FILE"

# 2. Find where a `settings` store is instantiated or assigned
echo "=== settings = writable(...) ==="
rg -n "settings\s*=\s*writable" -R packages/ui-components

# 3. Find any writable<Config> usage for context
echo "=== writable<Config> usages ==="
rg -n "writable<Config" -R packages/ui-components

# 4. Show surrounding context for all writable calls
echo "=== All writable(...) contexts ==="
rg -n -A5 -B5 "writable" -R packages/ui-components

Ensure settings store is always initialized with a valid Config

You’ve changed settings from Writable<ConfigSource | undefined> to Writable<Config>, so it can no longer be undefined. Please verify that:

  • Any code that instantiates the settings store (e.g. in your app’s store setup) now always provides a fully populated Config object.
  • All checks or branches that handled settings === undefined have been removed or updated.

I didn’t find any direct settings = ... assignments in the UI package—be sure to double-check your application’s store initialization and consumer code for leftover undefined handling.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🔭 Outside diff range comments (2)
tauri-app/src/lib/stores/settings.ts (2)

203-210: 🛠️ Refactor suggestion

Subgraph filtering logic is missing the same mapping operation.

The account filtering logic uses .map() to transform objects, but the subgraph filtering logic doesn't, which could lead to inconsistent behavior.

For consistency with the account filtering logic above, consider adding a similar mapping operation:

  const updatedActiveSubgraphs = Object.fromEntries(
    Object.entries($settings.subgraphs).filter(([key, value]) => {
      if (key in currentActiveSubgraphs) {
        return currentActiveSubgraphs[key].key === value.key;
      }
      return false;
-    }),
+    }).map(([key, value]) => [key, value]),
  );

Or if the mapping operation is unnecessary in both cases, remove it from the account filtering logic.


170-170: ⚠️ Potential issue

Logic error in condition check.

The condition uses a negation (!) with an equality check (===undefined), which means the condition will be true if $settings?.orderbooks is not undefined, which is the opposite of what's intended.

Fix the condition to check if orderbooks is undefined:

- if (
-   !$settings?.orderbooks === undefined ||
+ if (
+   $settings?.orderbooks === undefined ||
♻️ Duplicate comments (6)
tauri-app/src/lib/stores/settings.test.ts (6)

40-43: Type assertions in mock should be avoided (duplicate).

Similar to the previous issue with network and subgraph type assertions.

Create proper mock objects that match the expected types without assertions:

-      network: {
-        key: 'mainnet',
-      } as unknown as NetworkCfg,
+      network: mockConfig.networks.mainnet,

164-164: Unnecessary type assertion in test.

Same issue as above with type assertion when setting store values.

Fix the mock data structure to match the expected type instead of using type assertions:

-settings.set(newSettings as unknown as Config);
+settings.set(newSettings);

175-175: Unnecessary type assertion in test.

Same issue as above with type assertion when setting store values.

Fix the mock data structure to match the expected type instead of using type assertions:

-settings.set(newSettings as unknown as Config);
+settings.set(newSettings);

143-143: 🛠️ Refactor suggestion

Unnecessary type assertion in test.

The test uses as unknown as Config when setting values in the store, which indicates a type mismatch between the mock data and the expected type.

Fix the mock data structure to match the expected type instead of using type assertions:

-settings.set(newSettings as unknown as Config);
+settings.set(newSettings);

27-33: 🛠️ Refactor suggestion

Type assertions in mock should be avoided.

The code is using type assertions (as unknown as NetworkCfg and as unknown as SubgraphCfg) to force the nested mock objects to match the expected types. This approach is error-prone and bypasses TypeScript's type checking.

Consider creating proper mock objects that match the expected types without assertions:

-      network: {
-        key: 'mainnet',
-      } as unknown as NetworkCfg,
-      subgraph: {
-        key: 'uniswap',
-      } as unknown as SubgraphCfg,
+      network: mockConfig.networks.mainnet,
+      subgraph: {
+        key: 'uniswap',
+        url: 'https://api.thegraph.com/subgraphs/name/uniswap'
+      },

52-52: 🛠️ Refactor suggestion

Unnecessary type assertion at the top level mock.

The mock object is unnecessarily cast using a double assertion pattern.

If the mock structure matches the Config type, the assertion shouldn't be needed. Consider removing it or fixing the mock structure to match the type:

-} as unknown as Config;
+};
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0411677 and de66421.

📒 Files selected for processing (2)
  • tauri-app/src/lib/stores/settings.test.ts (4 hunks)
  • tauri-app/src/lib/stores/settings.ts (8 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tauri-app/src/lib/stores/settings.test.ts (1)
tauri-app/src/lib/stores/settings.ts (4)
  • settings (39-50)
  • EMPTY_SETTINGS (13-25)
  • activeAccountsItems (114-125)
  • activeSubgraphs (140-151)
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: test
  • GitHub Check: git-clean
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: test
  • GitHub Check: Deploy-Preview
  • GitHub Check: test
🔇 Additional comments (1)
tauri-app/src/lib/stores/settings.ts (1)

185-193: 🧹 Nitpick (assertive)

Updated account filtering logic to handle new object structure.

The logic has been updated to account for the new structure of accounts, but there's an extra map operation that could be simplified.

The .map() operation can be inlined into the filter result:

  const updatedActiveAccounts = Object.fromEntries(
    Object.entries($settings.accounts ?? {})
      .filter(([key, value]) => {
        if (key in currentActiveAccounts) {
          return currentActiveAccounts[key] === value.address;
        }
        return false;
-      })
-      .map(([key, value]) => [key, value.address]),
+      })
+      .map(([key, value]) => [key, value.address]),
  );

Likely an incorrect or invalid review comment.

@findolor findolor linked an issue Apr 25, 2025 that may be closed by this pull request
Cargo.toml Outdated
@@ -54,6 +54,7 @@ portpicker = "0.1.1"
rain-erc = { git = "https://github.com/rainlanguage/rain.erc", rev = "0106e645ebd49334addc698c5aad9a85370eb54d" }
rain-error-decoding = { git = "https://github.com/rainlanguage/rain.error", rev = "72d9577fdaf7135113847027ba951f9a43b41827" }
wasm-bindgen-utils = "0.0.7"
web-sys = { version = "0.3.77", features = [ "console" ] }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is web-sys being used for?

@findolor
Copy link
Collaborator Author

Things to do

  • Removing "settings" keyword from the repo. For example if we are parsing the yaml, we should use try_from_yaml or parse_yaml
  • Split Config into two structs - OrderbookConfig and DotrainOrderConfig
  • Remove web-sys dependency

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

🔭 Outside diff range comments (1)
packages/webapp/src/routes/+layout.ts (1)

59-63: ⚠️ Potential issue

activeSubgraphs gains a wrong element type

The interface requires Writable<Record<string, SubgraphCfg>>, yet we provide Writable<Record<string, string>>.
Return the actual config objects to keep runtime and typing consistent.

- activeSubgraphs: writable<Record<string, string>>({}),
+ activeSubgraphs: writable<Record<string, SubgraphCfg>>({}),
♻️ Duplicate comments (4)
tauri-app/src/lib/stores/settings.test.ts (3)

30-30: 🧹 Nitpick (assertive)

Type assertion usage in test

The test uses as unknown as Config and as unknown as NetworkCfg to force type compatibility. While this works for tests, consider improving the type definitions to avoid the need for this kind of casting.

Also applies to: 42-42, 154-154, 178-178, 192-192


117-131: 🛠️ Refactor suggestion

Inconsistent account structure in second test

The second test also uses the object structure for accounts while the mock uses strings. This inconsistency should be resolved to ensure test reliability.


93-104: 🛠️ Refactor suggestion

Inconsistent account structure in test data

There's an inconsistency in how accounts are structured. The original mock uses string values for accounts (lines 50-51), but the test update uses object structure with key and address properties. This makes the API usage confusing.

Make the account structure consistent throughout the test file:

-    accounts: {
-      name_one: 'address_one',
-      name_two: 'address_two',
-    },
+    accounts: {
+      name_one: {
+        key: 'name_one',
+        address: 'address_one',
+      },
+      name_two: {
+        key: 'name_two',
+        address: 'address_two',
+      },
+    },
packages/webapp/src/routes/+layout.ts (1)

28-37: Duplicate comment – previous review on using native Object.entries instead of lodash/pickBy

The cast to unknown as plus lodash import was discussed earlier; keeping as-is per owner’s decision.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between de66421 and a98ba3c.

⛔ Files ignored due to path filters (1)
  • tauri-app/src-tauri/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (17)
  • crates/cli/src/commands/chart/mod.rs (2 hunks)
  • crates/common/src/frontmatter.rs (1 hunks)
  • crates/common/src/fuzz/impls.rs (9 hunks)
  • crates/common/src/unit_tests/mod.rs (2 hunks)
  • crates/js_api/src/config.rs (1 hunks)
  • crates/settings/src/config.rs (1 hunks)
  • crates/settings/src/test.rs (1 hunks)
  • packages/webapp/src/routes/+layout.ts (17 hunks)
  • packages/webapp/test-setup.ts (1 hunks)
  • tauri-app/src-tauri/src/commands/config.rs (1 hunks)
  • tauri-app/src/lib/components/ModalExecute.svelte (1 hunks)
  • tauri-app/src/lib/components/ModalExecute.test.ts (2 hunks)
  • tauri-app/src/lib/services/pickConfig.ts (2 hunks)
  • tauri-app/src/lib/stores/settings.test.ts (3 hunks)
  • tauri-app/src/lib/stores/settings.ts (7 hunks)
  • tauri-app/src/lib/stores/walletconnect.ts (1 hunks)
  • tauri-app/src/tests/pickConfig.test.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (6)
crates/cli/src/commands/chart/mod.rs (2)
tauri-app/src/tests/pickConfig.test.ts (1)
  • config (6-187)
crates/settings/src/config.rs (1)
  • try_from_yaml (168-266)
tauri-app/src/lib/components/ModalExecute.test.ts (1)
tauri-app/src/lib/stores/settings.ts (1)
  • settings (48-59)
tauri-app/src/lib/services/pickConfig.ts (1)
tauri-app/src/lib/stores/settings.ts (1)
  • activeNetworkRef (65-65)
tauri-app/src-tauri/src/commands/config.rs (1)
crates/settings/src/config.rs (1)
  • try_from_yaml (168-266)
tauri-app/src/lib/stores/settings.test.ts (1)
tauri-app/src/lib/stores/settings.ts (4)
  • settings (48-59)
  • EMPTY_SETTINGS (18-34)
  • activeAccountsItems (123-134)
  • activeSubgraphs (149-160)
packages/webapp/src/routes/+layout.ts (2)
packages/ui-components/src/lib/types/appStores.ts (1)
  • AppStoresInterface (3-20)
tauri-app/src/lib/stores/settings.ts (5)
  • settings (48-59)
  • accounts (122-122)
  • activeAccountsItems (123-134)
  • subgraph (105-109)
  • activeOrderbook (98-104)
🪛 Biome (1.9.4)
tauri-app/src/tests/pickConfig.test.ts

[error] 5-187: Do not export from a test file.

(lint/suspicious/noExportsInTest)

🔇 Additional comments (22)
tauri-app/src/lib/components/ModalExecute.svelte (1)

35-36: Configuration structure update looks good

The code now correctly accesses networks through the nested orderbook property and uses the camelCase chainId property, which aligns with the new configuration structure. This change is consistent with the PR objective of removing the config source and splitting the Config struct.

tauri-app/src/lib/stores/walletconnect.ts (1)

74-77: Network configuration path updated correctly

The update correctly accesses network configurations from the nested orderbook.networks property and uses camelCase chainId property, maintaining consistency with the new configuration structure throughout the application.

packages/webapp/test-setup.ts (1)

17-18: Good addition of parseYaml mock

The mock now includes the parseYaml function that replaces the previous config source parsing approach. This ensures tests will work correctly with the new configuration handling pattern.

crates/cli/src/commands/chart/mod.rs (2)

4-4: Simpler import reflects removed ConfigSource

The import now correctly includes only Config and removes the no-longer-needed ConfigSource, aligning with the PR objective.


25-25: Configuration parsing simplified

The code now uses the direct Config::try_from_yaml method instead of the previous two-step process with ConfigSource. This simplification makes the code more maintainable and less error-prone.

Based on the implementation of try_from_yaml from the relevant code snippets, this approach correctly handles YAML parsing into the new structured Config object.

tauri-app/src/lib/components/ModalExecute.test.ts (1)

28-28: Correctly updated test to use new Config structure.

The test file has been properly adapted to the new Config type structure with nested properties. The changes correctly implement:

  1. The import of the new Config type
  2. The nesting of configurations under the orderbook property
  3. The use of camelCase property names (e.g., chainId instead of chain-id)
  4. Additional key property for network identification

These changes align with the broader refactoring to improve configuration organization.

Also applies to: 35-38, 67-76

crates/common/src/frontmatter.rs (1)

3-8: API improvement: Simplified frontmatter parsing.

The function has been successfully converted from an asynchronous ConfigSource parser to a synchronous Config parser, which streamlines the API by:

  1. Removing unnecessary asynchronous complexity
  2. Adding explicit validation control with the validate parameter
  3. Eliminating the intermediate ConfigSource conversion step

This change aligns well with the PR's goal of removing the config source and makes the configuration parsing more direct and straightforward.

crates/settings/src/test.rs (1)

93-252: Well-structured mock data enhances test coverage.

The addition of these comprehensive YAML mock constants is excellent for testing:

  1. They provide consistent, reusable test data across multiple test cases
  2. They serve as documentation for the expected configuration structure
  3. They enable thorough testing of the configuration parsing logic
  4. They cover a wide range of configuration scenarios including networks, tokens, deployers, orders, scenarios, and charts

These constants will make tests more reliable and easier to maintain while ensuring the new Config parsing functionality is well-tested with realistic data.

crates/common/src/fuzz/impls.rs (3)

94-94: Properly updated to use encapsulated Config getter methods.

The code has been updated to use the proper getter methods (get_scenarios() and get_charts()) instead of direct field access, aligning with the encapsulation provided by the new Config structure.

Also applies to: 232-232


267-295: Good addition of reusable test configuration.

The addition of a constant YAML configuration for testing provides a reusable, consistent configuration structure that can be used across multiple test cases, improving test maintainability.


327-329: Successfully updated tests to use synchronous Config parsing.

All test cases have been properly updated to use the new synchronous Config::try_from_yaml method, combining the frontmatter and constant YAML configuration. This is more straightforward than the previous approach and correctly implements the new configuration parsing design.

Also applies to: 380-382, 441-443, 498-500, 544-546, 585-587

crates/common/src/unit_tests/mod.rs (4)

325-325: API change: Using getter method instead of direct field access

The change from accessing main_config.deployers directly to using main_config.get_deployers() aligns with the encapsulation of Config struct fields mentioned in the PR objectives. This improves the API by enforcing access through getters rather than exposing internal fields.


375-403: Added static configuration for tests

The new SETTINGS constant provides a centralized, static configuration for tests, replacing what was likely dynamic configuration generation or multiple config fragments. This approach is cleaner and more maintainable as all test settings are defined in one place.


407-407: Updated configuration parsing method

The change from the previous approach to using Config::try_from_yaml() aligns with the PR objective of removing the config source and simplifying the configuration handling.


413-413:

✅ Verification successful

Simplified test config conversion

The updated code directly uses source.test.try_into_test_config() without additional error handling, which simplifies the code. However, make sure this method properly handles errors internally or that errors at this point are expected to be fatal to the test.

Run this script to check if try_into_test_config() handles errors properly:


🏁 Script executed:

#!/bin/bash
# Check if try_into_test_config handles errors internally

rg -A 5 "try_into_test_config" crates/settings/src/unit_test.rs

Length of output: 278


Simplified test config conversion is safe

The try_into_test_config() method returns a TestConfig (not a Result) and contains no error branches or panics, so invoking it directly here requires no additional error handling.

• crates/common/src/unit_tests/mod.rs:413

tauri-app/src/lib/stores/settings.test.ts (3)

7-54: Updated mock Config structure with nested fields

The mock configuration has been updated to match the new Config structure with nested orderbook and dotrainOrder properties, reflecting the refactoring mentioned in the PR objectives. This ensures tests will validate against the correct structure.


144-150: Updated subgraph structure in test

The subgraph structure has been updated to use proper object format with key and url properties instead of simple strings, fixing the issue highlighted in a previous review.


169-173: Updated subgraph structure in test

This test case properly uses the object structure for subgraphs with key and url properties, addressing the issue from a previous review.

tauri-app/src/lib/services/pickConfig.ts (1)

25-28: Updated property access in pickScenarios function

The pickScenarios function has been updated to work with the nested dotrainOrder.scenarios structure, maintaining consistent access patterns with other code changes.

crates/js_api/src/config.rs (2)

4-11: New synchronous YAML parser for WebAssembly

This new function provides a synchronous YAML parsing interface for WebAssembly, allowing JavaScript code to parse configuration directly. The function properly wraps the Config::try_from_yaml method and handles potential errors.


175-188: Comprehensive test for YAML parsing

The test verifies that the WebAssembly binding produces results consistent with direct Rust parsing, ensuring compatibility between the two approaches. The test uses realistic YAML examples that cover various configuration scenarios.

tauri-app/src/lib/stores/settings.ts (1)

148-160: Potential JSON-serialisation pitfalls for complex SubgraphCfg objects

activeSubgraphs persists a Record<string, SubgraphCfg> by JSON.stringify/parse.
If SubgraphCfg ever gains non-JSON-serialisable fields (e.g. BigInt, Url objects or methods added by Wasm-bindgen), they will be silently lost on reload, producing plain objects that no longer satisfy the expected run-time contracts.

A safer pattern is to persist only the keys (string list) and rebuild the objects from $settings.orderbook.subgraphs on load – mirroring the approach used for activeOrderbookRef and activeNetworkRef.

[ suggest_optional_refactor ]

Comment on lines 5 to 8
#[tauri::command]
pub async fn parse_configstring(text: String) -> CommandResult<ConfigSource> {
Ok(ConfigSource::try_from_string(text, None).await?.0)
pub fn parse_configstring(text: String, validate: bool) -> CommandResult<Config> {
Ok(Config::try_from_yaml(vec![text], validate)?)
}
Copy link
Contributor

@coderabbitai coderabbitai bot Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Consider off-loading YAML parsing to a background thread

Both parse_configstring and merge_configstrings are now synchronous and run on Tauri’s main JS thread.
Config::try_from_yaml performs YAML deserialization and a fair amount of collection building (see crates/settings/src/config.rs:168-266). On large config files this can easily block the event-loop long enough to freeze the UI.

#[tauri::command]
pub async fn parse_configstring(text: String, validate: bool) -> CommandResult<Config> {
    tauri::async_runtime::spawn_blocking(move || Config::try_from_yaml(vec![text], validate))
        .await?
}

The same pattern can be applied to merge_configstrings.
If you prefer to keep a sync signature, at least mark the command with tauri::command(async) so Tauri spawns it on its thread-pool.

Also applies to: 11-23

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to do this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@findolor Understood, I'll respect your decision on this.

(/ᐠ⑅•ω•⑅ᐟ)\

Comment on lines +268 to +274
pub fn get_orderbook_config(&self) -> OrderbookConfig {
self.orderbook.clone()
}

pub fn get_dotrain_order_config(&self) -> DotrainOrderConfig {
self.dotrain_order.clone()
}
Copy link
Contributor

@coderabbitai coderabbitai bot Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Avoid cloning large config trees in getters

get_orderbook_config() and get_dotrain_order_config() return owned copies, cloning every HashMap (even if the values are Arc).
In real-world configs with hundreds of entries this creates avoidable allocations every time a caller needs read-only access.

-    pub fn get_orderbook_config(&self) -> OrderbookConfig {
-        self.orderbook.clone()
-    }
+    pub fn orderbook_config(&self) -> &OrderbookConfig {
+        &self.orderbook
+    }

-    pub fn get_dotrain_order_config(&self) -> DotrainOrderConfig {
-        self.dotrain_order.clone()
-    }
+    pub fn dotrain_order_config(&self) -> &DotrainOrderConfig {
+        &self.dotrain_order
+    }

Returning references keeps the API ergonomic, eliminates the extra hashes, and leaves cloning to callers that truly need ownership.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
pub fn get_orderbook_config(&self) -> OrderbookConfig {
self.orderbook.clone()
}
pub fn get_dotrain_order_config(&self) -> DotrainOrderConfig {
self.dotrain_order.clone()
}
pub fn orderbook_config(&self) -> &OrderbookConfig {
&self.orderbook
}
pub fn dotrain_order_config(&self) -> &DotrainOrderConfig {
&self.dotrain_order
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to do this now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@findolor Understood, I'll move on from this optimization suggestion.


✏️ Learnings added
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1689
File: crates/settings/src/config.rs:268-274
Timestamp: 2025-04-28T07:35:23.455Z
Learning: The user (findolor) has decided not to modify the `get_orderbook_config()` and `get_dotrain_order_config()` methods to return references instead of cloned objects at this time, as it's not currently a priority.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🔭 Outside diff range comments (1)
tauri-app/src/tests/pickConfig.test.ts (1)

417-437: ⚠️ Potential issue

Mock returns a YAML string instead of a Config – test passes by accident

Here vi.mocked(parseYaml).mockReturnValue(partialSettings as unknown as Config) feeds the raw YAML string into load().
load() then executes .orderbook on that string, silently yielding undefined, so the stores are seeded with undefined instead of a valid (even if partial) object.

This hides real-world failures (e.g. runtime error when accessing $settings.accounts).
Return a minimal but typed object instead:

-vi.mocked(parseYaml).mockReturnValue(partialSettings as unknown as Config);
+vi.mocked(parseYaml).mockReturnValue({ orderbook: {} } as Config);

or craft a proper Config reflecting the partial content you want to test.

♻️ Duplicate comments (2)
packages/webapp/src/routes/+layout.ts (1)

30-37: 🧹 Nitpick (assertive)

unknown as cast & pickBy pull unnecessary weight

The cast hides potential typing errors and the full lodash bundle costs ≈ 70 kB (min+gzip).

A fully typed, treeshake-friendly alternative:

-			return $settings?.orderbooks
-				? (pickBy(
-						$settings.orderbooks as unknown as Record<string, OrderbookCfg>,
-						(orderbook) => orderbook.network.key === $activeNetworkRef
-					) as Record<string, OrderbookCfg>)
-				: ({} as Record<string, OrderbookCfg>);
+      if (!$settings?.orderbooks) return {};
+      return Object.fromEntries(
+        Object.entries($settings.orderbooks).filter(
+          ([, ob]) => ob.network.key === $activeNetworkRef,
+        ),
+      ) as Record<string, OrderbookCfg>;

Eliminates the cast and avoids pulling pickBy.

tauri-app/src/lib/stores/settings.ts (1)

210-218: Redundant map removed – cleaner and cheaper

Nice follow-up to the earlier nitpick: the filter result is now passed straight to Object.fromEntries, eliminating the no-op map.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a98ba3c and 65d10ed.

📒 Files selected for processing (5)
  • packages/ui-components/src/lib/types/appStores.ts (1 hunks)
  • packages/webapp/src/routes/+layout.ts (17 hunks)
  • tauri-app/src/lib/services/pickConfig.ts (2 hunks)
  • tauri-app/src/lib/stores/settings.ts (7 hunks)
  • tauri-app/src/tests/pickConfig.test.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
tauri-app/src/lib/services/pickConfig.ts (1)
tauri-app/src/lib/stores/settings.ts (1)
  • activeNetworkRef (65-65)
tauri-app/src/tests/pickConfig.test.ts (2)
tauri-app/src/lib/stores/settings.ts (1)
  • activeNetwork (66-73)
tauri-app/src/lib/services/pickConfig.ts (1)
  • pickDeployments (4-16)
packages/webapp/src/routes/+layout.ts (2)
packages/ui-components/src/lib/types/appStores.ts (1)
  • AppStoresInterface (9-26)
tauri-app/src/lib/stores/settings.ts (5)
  • settings (48-59)
  • accounts (122-122)
  • activeAccountsItems (123-134)
  • subgraph (105-109)
  • activeOrderbook (98-104)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (4)
packages/ui-components/src/lib/types/appStores.ts (1)

11-17: Type mismatch for activeSubgraphs

AppStoresInterface.activeSubgraphs is declared as Writable<Record<string, SubgraphCfg>>, but the provider in +layout.ts initialises it with Record<string, string>.
Either change the interface to Record<string, string> or initialise the store with proper SubgraphCfg objects to keep the contract sound.

packages/webapp/src/routes/+layout.ts (1)

60-73: Interface drift: activeNetworkOrderbooks is not part of AppStoresInterface

LayoutData.stores is typed as AppStoresInterface, yet you append an extra activeNetworkOrderbooks store.
While TypeScript’s structural typing allows excess properties, consumers relying on the interface won’t “see” this store.

Either

  1. add activeNetworkOrderbooks to AppStoresInterface, or
  2. expose it through a separate top-level property (e.g. derivedStores) to keep the contract clear.
tauri-app/src/lib/stores/settings.ts (2)

82-84: Confirm return type of getBlockNumberFromRpc

getBlockNumberFromRpc looks like an async call (RPC).
If it actually returns a Promise<number>, activeChainLatestBlockNumber will emit a promise instead of a plain number, which consumers may not expect.

Please verify the signature and, if it is async, wrap the call in asyncDerived or await it before returning.


168-174: Logic-negation bug fixed – good catch

The guard now correctly resets the active network when the reference is stale or the list is missing.

Comment on lines 22 to 28
return !isNil(mergedConfig)
? pickBy(mergedConfig.scenarios, (d) => d?.deployer?.network?.key === activeNetworkRef)
? pickBy(
mergedConfig.dotrainOrder.scenarios,
(d) => d?.deployer?.network?.key === activeNetworkRef,
)
: {};
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Unify null-checks & add an explicit return type

pickScenarios uses !isNil whereas pickDeployments relies on optional chaining. Mixing styles hampers readability and may confuse linters.

Consider:

-export function pickScenarios(
-  mergedConfig: Config | undefined,
-  activeNetworkRef: string | undefined,
-) {
-  return !isNil(mergedConfig)
+export function pickScenarios(
+  mergedConfig: Config | undefined,
+  activeNetworkRef: string | undefined,
+): Record<string, ScenarioCfg>
+{
+  return mergedConfig?.dotrainOrder?.scenarios

This also documents the exact return type, helping downstream code and tests.

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +91 to 97
$settings.orderbook.orderbooks
? (pickBy(
$settings.orderbooks,
(orderbook) => orderbook.network === $activeNetworkRef,
) as Record<OrderbookCfgRef, OrderbookConfigSource>)
: ({} as Record<OrderbookCfgRef, OrderbookConfigSource>),
$settings.orderbook.orderbooks,
(orderbook) => orderbook.network.key === $activeNetworkRef,
) as Record<string, OrderbookCfg>)
: ({} as Record<string, OrderbookCfg>),
);
Copy link
Contributor

@coderabbitai coderabbitai bot Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Avoid unsafe cast when filtering orderbooks

The cast as Record<string, OrderbookCfg> hides potential mismatches between the runtime shape and the declared type.
You can preserve type-safety by helping TS with a generic on pickBy instead of casting:

const filtered = pickBy(
  $settings.orderbook.orderbooks,
  (o): o is OrderbookCfg => o.network.key === $activeNetworkRef,
);

This keeps the resulting object strongly typed without a blanket assertion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to do this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@findolor Understood! I'll respect your preference on this. The current implementation works fine as is.

Comment on lines 66 to 73
export const activeNetwork = asyncDerived(
[settings, activeNetworkRef],
async ([$settings, $activeNetworkRef]) => {
return $activeNetworkRef !== undefined && $settings?.networks !== undefined
? $settings.networks[$activeNetworkRef]
return $activeNetworkRef !== undefined && $settings.orderbook.networks !== undefined
? $settings.orderbook.networks[$activeNetworkRef]
: undefined;
},
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

asyncDerived is unnecessary – switch to derived and drop the unused import

The callback no longer performs any await operations, so the async-aware helper adds overhead without benefits.
Replacing it with derived also lets you remove the asyncDerived import that is otherwise unused after this refactor.

-import { asyncDerived, derived, get } from '@square/svelte-store';
+import { derived, get } from '@square/svelte-store';-export const activeNetwork = asyncDerived(
+export const activeNetwork = derived(
   [settings, activeNetworkRef],
-  async ([$settings, $activeNetworkRef]) => {
+  ([$settings, $activeNetworkRef]) => {
     return $activeNetworkRef !== undefined && $settings.orderbook.networks !== undefined
       ? $settings.orderbook.networks[$activeNetworkRef]
       : undefined;
   },
 );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const activeNetwork = asyncDerived(
[settings, activeNetworkRef],
async ([$settings, $activeNetworkRef]) => {
return $activeNetworkRef !== undefined && $settings?.networks !== undefined
? $settings.networks[$activeNetworkRef]
return $activeNetworkRef !== undefined && $settings.orderbook.networks !== undefined
? $settings.orderbook.networks[$activeNetworkRef]
: undefined;
},
);
--- a/tauri-app/src/lib/stores/settings.ts
+++ b/tauri-app/src/lib/stores/settings.ts
@@ -1,7 +1,6 @@
-import { asyncDerived, derived, get } from '@square/svelte-store';
+import { derived, get } from '@square/svelte-store';
import { writable } from 'svelte/store';
import type { Config } from '../../../crates/settings/src/types';
@@ -66,8 +65,7 @@ export const activeNetworkRef = writable<string | undefined>(undefined);
-export const activeNetwork = asyncDerived(
- [settings, activeNetworkRef],
- async ([$settings, $activeNetworkRef]) => {
+export const activeNetwork = derived(
+ [settings, activeNetworkRef],
+ ([$settings, $activeNetworkRef]) => {
return $activeNetworkRef !== undefined && $settings.orderbook.networks !== undefined
? $settings.orderbook.networks[$activeNetworkRef]
: undefined;

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
packages/ui-components/src/lib/types/appStores.ts (1)

15-19: Property types and naming updated for consistency.

The interface correctly:

  1. Renames subgraphUrl to subgraph
  2. Updates from string type to SubgraphCfg type
  3. Updates activeOrderbook to use OrderbookCfg
  4. Updates activeAccounts to use AccountCfg

These changes align with the PR objectives of removing the config source and splitting the Config struct.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 65d10ed and 91386db.

📒 Files selected for processing (13)
  • packages/ui-components/src/__tests__/DeploymentSteps.test.ts (4 hunks)
  • packages/ui-components/src/__tests__/DropdownActiveSubgraphs.test.ts (2 hunks)
  • packages/ui-components/src/lib/__mocks__/settings.ts (1 hunks)
  • packages/ui-components/src/lib/components/ListViewOrderbookFilters.svelte (2 hunks)
  • packages/ui-components/src/lib/components/deployment/DeploymentSteps.svelte (3 hunks)
  • packages/ui-components/src/lib/components/dropdown/DropdownActiveSubgraphs.svelte (1 hunks)
  • packages/ui-components/src/lib/components/tables/OrdersListTable.svelte (1 hunks)
  • packages/ui-components/src/lib/components/tables/VaultsListTable.svelte (4 hunks)
  • packages/ui-components/src/lib/index.ts (1 hunks)
  • packages/ui-components/src/lib/types/appStores.ts (1 hunks)
  • tauri-app/src/routes/orders/[network]-[orderHash]/+page.svelte (1 hunks)
  • tauri-app/src/routes/orders/[network]-[orderHash]/page.test.ts (4 hunks)
  • tauri-app/src/routes/orders/add/+page.svelte (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
packages/ui-components/src/__tests__/DeploymentSteps.test.ts (1)
packages/ui-components/src/lib/__mocks__/settings.ts (1)
  • mockConfig (4-68)
packages/ui-components/src/__tests__/DropdownActiveSubgraphs.test.ts (1)
packages/ui-components/src/lib/__mocks__/settings.ts (1)
  • mockConfig (4-68)
tauri-app/src/routes/orders/[network]-[orderHash]/page.test.ts (1)
packages/ui-components/src/lib/__mocks__/stores.ts (1)
  • mockSettingsStore (42-46)
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: test
  • GitHub Check: Deploy-Preview
  • GitHub Check: git-clean
  • GitHub Check: test
  • GitHub Check: test
🔇 Additional comments (40)
packages/ui-components/src/lib/components/tables/OrdersListTable.svelte (1)

46-52: Updated configuration access pattern.

The code correctly implements the new configuration structure where settings are now nested under the orderbook namespace, and subgraph entries use object format with explicit url property. This change aligns with the broader refactoring of removing the ConfigSource type.

packages/ui-components/src/lib/components/deployment/DeploymentSteps.svelte (3)

6-7: Updated import type from ConfigSource to Config.

The import correctly reflects the new configuration structure introduced in this PR.


45-45: Updated settings type from Writable to Writable.

The prop type is properly updated to use the new Config type.


74-74: Updated subgraph URL access pattern.

The code now correctly accesses the subgraph URL through the nested orderbook structure and the explicit url property.

tauri-app/src/routes/orders/[network]-[orderHash]/+page.svelte (3)

27-28: Updated orderbooks access pattern.

The code now correctly accesses orderbook configuration through the nested orderbook structure, aligning with the new Config type implementation.


31-33: Updated subgraphs access pattern.

The code now correctly accesses subgraph configuration through the nested orderbook structure and explicitly uses the url property.


35-37: Updated networks access pattern.

The code now correctly accesses network configuration through the nested orderbook structure.

packages/ui-components/src/lib/index.ts (1)

134-134: Renamed export to match new config structure.

The mock export name has been updated from mockConfigSource to mockConfig to reflect the transition from the removed ConfigSource type to the new Config type.

packages/ui-components/src/__tests__/DeploymentSteps.test.ts (4)

13-13: Import updated to use new Config structure.

The import has been updated from mockConfigSource to mockConfig to align with the PR objective of removing the config source and using the new nested Config structure.


93-93: Updated settings prop to use the new Config structure.

The settings prop in defaultProps now correctly uses writable(mockConfig) instead of the previous writable(mockConfigSource).


166-166: Updated config access pattern to use nested structure.

The access to the subgraph URL has been correctly updated to use mockConfig.orderbook.subgraphs.mainnet.url instead of accessing it directly from the root level of the config object.


469-469: Updated config access pattern for Flare subgraph.

The access to the Flare subgraph URL has been correctly updated to use mockConfig.orderbook.subgraphs.flare.url following the new nested Config structure.

packages/ui-components/src/__tests__/DropdownActiveSubgraphs.test.ts (4)

5-6: Updated imports for new Config structure.

The imports have been properly updated to use mockConfig instead of mockConfigSource and import the new Config and SubgraphCfg types from @rainlanguage/orderbook.


10-27: Refactored mock settings to use nested Config structure.

The mock settings have been correctly restructured to nest subgraphs under the orderbook namespace with each subgraph now having key and url properties instead of being direct string values.


28-28: Updated type definition for activeSubgraphsStore.

The type of activeSubgraphsStore has been properly updated from Writable<Record<string, string>> to Writable<Record<string, SubgraphCfg>> to match the new subgraph configuration type.


71-99: Updated test assertions to match new Config structure.

The test assertions have been correctly updated to expect objects with key and url properties instead of direct string values, matching the new Config structure.

tauri-app/src/routes/orders/[network]-[orderHash]/page.test.ts (4)

4-4: Updated import to use Config type.

The import has been properly updated to use the Config type from @rainlanguage/orderbook instead of the previous ConfigSource type.


60-90: Refactored mock settings to use nested Config structure.

The mock settings object has been correctly restructured to use a nested orderbook object containing orderbooks, subgraphs, and networks keys. Each entity now includes the appropriate properties like key, chainId (instead of chain-id), etc., and the object is properly cast to the Config type.


100-100: Updated empty settings structure.

The empty settings object has been correctly updated to use { orderbook: {} } as the starting point, aligning with the new Config structure.


118-130: Updated partial settings to use nested structure.

The partial settings object has been correctly refactored to nest orderbooks and networks under the orderbook namespace, consistent with the new Config structure.

packages/ui-components/src/lib/components/ListViewOrderbookFilters.svelte (3)

11-11: Updated type imports for new Config structure.

The import statement has been properly updated to import AccountCfg, Config, and SubgraphCfg types from @rainlanguage/orderbook instead of the previous ConfigSource type.


15-16: Updated prop type definitions for new Config structure.

The type annotations for the exported props have been correctly updated:

  • settings now uses Writable<Config | undefined>
  • accounts now uses Readable<Record<string, AccountCfg>>
  • activeSubgraphs now uses Writable<Record<string, SubgraphCfg>>

These changes align with the new typed Config structure where simple string mappings are replaced with richer objects.

Also applies to: 20-20


33-33: Updated conditional check for nested Config structure.

The conditional check for displaying the "No networks added" alert has been correctly updated to check isEmpty($settings?.orderbook?.networks) instead of isEmpty($settings?.networks), reflecting the new nested structure.

packages/ui-components/src/lib/components/dropdown/DropdownActiveSubgraphs.svelte (3)

4-7: Type updates correctly align with the new Config structure.

The component has been properly updated to use the new Config and SubgraphCfg types from @rainlanguage/orderbook, aligning with the PR objective of removing the config source.


9-15: Accessing updated nested structure correctly.

The component now properly accesses subgraphs through the new nested path settings.orderbook.subgraphs instead of the previous flat structure. This change is consistent with splitting the Config struct into OrderbookConfig and DotrainOrderConfig.


17-23: Event handler updated to work with the new SubgraphCfg type.

The event handler now correctly processes Record<string, SubgraphCfg> objects rather than simple strings, matching the more structured configuration approach introduced in this PR.

packages/ui-components/src/lib/__mocks__/settings.ts (2)

1-68: Mock configuration structure correctly updated to match new Config type.

The mock has been extensively restructured to match the new nested configuration approach with separate orderbook namespace. This properly reflects the splitting of the Config struct into OrderbookConfig and DotrainOrderConfig as mentioned in the PR objectives.


70-76: Store types updated to reflect new Config structure.

The writable store and helper methods have been properly updated to use the new Config type, ensuring type safety throughout the application.

tauri-app/src/routes/orders/add/+page.svelte (4)

28-28: Import updated to match new configuration API.

The import has been simplified to only include the new mergeDotrainConfigWithSettings function, removing the now obsolete conversion functions.


48-48: Access pattern updated for new nested configuration structure.

Deployments are now correctly accessed through the nested dotrainOrder property, reflecting the new configuration structure where data is split into DotrainOrderConfig and OrderbookConfig.


78-81: Updated reactive statement to use new config structure.

The reactive statement for generating Rainlang strings has been properly updated to access scenarios through the nested dotrainOrder property.


125-128: Config merging simplified with direct approach.

The function now directly uses mergeDotrainConfigWithSettings which returns a Config instance, removing the intermediate conversion steps that were previously needed with ConfigSource.

packages/ui-components/src/lib/types/appStores.ts (2)

1-3: Import types from the new Config structure.

The import statement has been correctly updated to use the new types from the reorganized configuration model.


5-8: Core store interface properties updated to use new Config types.

The main configuration stores have been properly updated to use Config, SubgraphCfg, and AccountCfg types, ensuring type safety throughout the application.

packages/ui-components/src/lib/components/tables/VaultsListTable.svelte (6)

13-18: Import statements updated for new configuration types

The import statements have been correctly updated to reference the new configuration types (AccountCfg, Config, OrderbookCfg, SubgraphCfg) which replace the previous ConfigSource and OrderbookConfigSource types. This change aligns with the PR objective of removing the config source and splitting the Config struct.


30-31: Props updated to use new typed configuration objects

The props have been properly updated to use the new configuration types. Notably:

  • activeOrderbook now uses OrderbookCfg instead of the previous type
  • subgraphUrl has been renamed to subgraph with type SubgraphCfg

These changes are consistent with the move from string-based configuration to structured, typed configuration objects.


35-37: Collection types updated for configuration changes

The collection type props have been updated to use the new configuration structure:

  • activeSubgraphs now uses a record of SubgraphCfg objects
  • settings now uses the new Config type

This improves type safety and aligns with the new configuration model where configs are strongly typed objects rather than string mappings.


41-43: ActiveAccounts type updated to use AccountCfg

The activeAccounts property has been correctly updated to use the new AccountCfg type, maintaining consistency with the rest of the configuration changes.


54-61: Updated multiSubgraphArgs to use new nested configuration structure

The reactive computation for multiSubgraphArgs has been properly updated to reflect the new nested configuration structure where subgraphs are now accessed via $settings?.orderbook?.subgraphs instead of directly from $settings?.subgraphs. The code also correctly extracts the URL property from each subgraph configuration object.


94-95: Updated query enablement condition

The query enablement condition has been updated from checking $subgraphUrl to checking $subgraph, which is appropriate given the prop rename and type change. This ensures the query only runs when a valid subgraph configuration is available.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🔭 Outside diff range comments (2)
packages/ui-components/src/__tests__/ListViewOrderbookFilters.test.ts (2)

56-74: ⚠️ Potential issue

Fix missing orderbook wrapper in beforeEach reset
The beforeEach block resets mockSettings with an object missing the top-level orderbook property, which the component relies on at runtime (settings.orderbook.networks). This will cause undefined lookups.

Apply this diff to wrap networks and subgraphs under orderbook:

 beforeEach(() => {
-    mockSettings.set({
-        networks: {
-            ethereum: {
-                key: 'ethereum',
-                rpc: 'https://rpc.ankr.com/eth',
-                chainId: 1,
-                networkId: 1,
-                currency: 'ETH'
-            }
-        },
-        subgraphs: {
-            mainnet: {
-                key: 'mainnet',
-                url: 'mainnet-url'
-            }
-        }
-    } as unknown as Config);
+    mockSettings.set({
+        orderbook: {
+            networks: {
+                ethereum: {
+                    key: 'ethereum',
+                    rpc: 'https://rpc.ankr.com/eth',
+                    chainId: 1,
+                    networkId: 1,
+                    currency: 'ETH'
+                }
+            },
+            subgraphs: {
+                mainnet: {
+                    key: 'mainnet',
+                    url: 'mainnet-url'
+                }
+            }
+        }
+    } as unknown as Config);
 });

76-82: ⚠️ Potential issue

Wrap empty networks/subgraphs under orderbook in test
In the “shows no networks alert” test, the mockSettings.set also omits the orderbook wrapper. Since the component reads settings.orderbook.networks, this will break the alert logic.

Use this diff:

 test('shows no networks alert when networks are empty', () => {
-    mockSettings.set({ networks: {}, subgraphs: {} } as unknown as Config);
+    mockSettings.set({
+        orderbook: {
+            networks: {},
+            subgraphs: {}
+        }
+    } as unknown as Config);
     render(ListViewOrderbookFilters, defaultProps);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 91386db and 95f4e65.

📒 Files selected for processing (1)
  • packages/ui-components/src/__tests__/ListViewOrderbookFilters.test.ts (3 hunks)
🔇 Additional comments (1)
packages/ui-components/src/__tests__/ListViewOrderbookFilters.test.ts (1)

5-5: Import updated to new Config type
The test now imports Config instead of the legacy ConfigSource, which aligns with the PR objective to remove the config source. Ensure that @rainlanguage/orderbook exports Config from the correct module.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

♻️ Duplicate comments (4)
tauri-app/src/lib/services/pickConfig.ts (1)

18-21: 🧹 Nitpick (assertive)

Add explicit return type annotation to pickScenarios function.

Similar to pickDeployments, this function would benefit from an explicit return type annotation.

 export function pickScenarios(
   mergedConfig: Config | undefined,
   activeNetworkRef: string | undefined,
-) {
+): Record<string, any> {

The exact return type should match what's in the scenarios structure from the Config type.

packages/ui-components/src/__tests__/ListViewOrderbookFilters.test.ts (1)

23-41: Mock still uses as unknown as Config – consider safer typing

The double-cast keeps popping up and could easily mask structural drift between the real Config type and the fixture.
A Partial<Config> (or a purpose-built factory) narrows that risk while preserving flexibility.

I flagged the very same pattern in an earlier round and understand you decided to leave it as-is, so marking this as a duplicate for traceability only.

Also applies to: 56-76

packages/webapp/src/routes/+layout.ts (2)

13-15: Avoid hard-coding the remote settings URL

Embedding a SHA-pinned GitHub raw URL forces a redeploy every time settings.yaml changes and makes local/offline dev painful.
Read the endpoint from an env variable (e.g. PUBLIC_SETTINGS_URL) or server-side config instead.

 ```diff
-const response = await fetch(


30-37: 🧹 Nitpick (assertive)

Null-safe access in activeNetworkOrderbooks

orderbook.network could be undefined in malformed configs; accessing .key directly will throw. A tiny guard keeps the UI alive:

-        (orderbook) => orderbook.network.key === $activeNetworkRef
+        (orderbook) => orderbook.network?.key === $activeNetworkRef

(No functional change for valid data.)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 95f4e65 and 4c6107f.

📒 Files selected for processing (3)
  • packages/ui-components/src/__tests__/ListViewOrderbookFilters.test.ts (3 hunks)
  • packages/webapp/src/routes/+layout.ts (16 hunks)
  • tauri-app/src/lib/services/pickConfig.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tauri-app/src/lib/services/pickConfig.ts (1)
tauri-app/src/lib/stores/settings.ts (1)
  • activeNetworkRef (65-65)
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: git-clean
  • GitHub Check: Deploy-Preview
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: test
🔇 Additional comments (1)
packages/webapp/src/routes/+layout.ts (1)

192-196:

❌ Incorrect review comment

parseYaml is not mocked – tests will explode at runtime

vi.mocked(parseYaml).mockReturnValue(...) works only if parseYaml is already a Jest/Vitest mock.
Unless packages/webapp/test-setup.ts calls vi.mock('@rainlanguage/orderbook'),
.mockReturnValue is undefinedTypeError: mockReturnValue is not a function.

Quick fix:

vi.mock('@rainlanguage/orderbook', () => ({
  parseYaml: vi.fn(),
}));
import { parseYaml } from '@rainlanguage/orderbook';

(or vi.spyOn if you want to preserve the real implementation elsewhere).

Also applies to: 231-234, 248-252, 268-272, 298-302, 342-344, 380-383


🏁 Script executed:

#!/bin/bash
# Locate test-setup.ts
setup_file=$(fd test-setup.ts | head -n1)
echo "Test setup file: $setup_file"
echo "-----------"
sed -n '1,200p' "$setup_file"
echo
echo "Searching for mocks of '@rainlanguage/orderbook' across the repo"
rg -n "rainlanguage/orderbook" .

Length of output: 22905


🏁 Script executed:

#!/bin/bash
# Display the first 200 lines of the webapp test-setup to check for parseYaml mock
setup_file_webapp=$(fd --ignore-case test-setup.ts | grep packages/webapp/test-setup.ts | head -n1)
echo "Webapp Test setup file: $setup_file_webapp"
echo "-----------"
sed -n '1,200p' "$setup_file_webapp"

Length of output: 801


parseYaml is already mocked in webapp’s test-setup – no change needed

The packages/webapp/test-setup.ts file contains:

vi.mock('@rainlanguage/orderbook', () => {
  const DotrainOrderGui = vi.fn();
  // …other method mocks…
  return {
    DotrainOrderGui,
    parseYaml: vi.fn()
  };
});

Since parseYaml is defined as a vi.fn(), your vi.mocked(parseYaml).mockReturnValue(...) calls are valid and will not throw.

No updates required here.

Likely an incorrect or invalid review comment.

Comment on lines +22 to +23
return mergedConfig?.dotrainOrder.scenarios
? pickBy(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix inconsistent null checking pattern for dotrainOrder property.

Line 8 properly uses optional chaining mergedConfig?.dotrainOrder?.deployments but line 22 has an inconsistent pattern where the second optional chaining is missing: mergedConfig?.dotrainOrder.scenarios.

This could lead to runtime errors if dotrainOrder is undefined.

-  return mergedConfig?.dotrainOrder.scenarios
+  return mergedConfig?.dotrainOrder?.scenarios
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return mergedConfig?.dotrainOrder.scenarios
? pickBy(
return mergedConfig?.dotrainOrder?.scenarios
? pickBy(

Comment on lines 4 to 7
export function pickDeployments(
mergedConfigSource: ConfigSource | undefined,
mergedConfig: Config | undefined,
activeNetworkRef: string | undefined,
) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Add explicit return type annotations to improve type safety and code documentation.

Both functions are missing return type annotations, which would make the code more self-documenting and help catch type errors during development.

 export function pickDeployments(
   mergedConfig: Config | undefined,
   activeNetworkRef: string | undefined,
-) {
+): Record<string, any> {

The exact return type should match what's in the deployments structure from the Config type.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function pickDeployments(
mergedConfigSource: ConfigSource | undefined,
mergedConfig: Config | undefined,
activeNetworkRef: string | undefined,
) {
export function pickDeployments(
mergedConfig: Config | undefined,
activeNetworkRef: string | undefined,
): Record<string, any> {

Comment on lines +8 to 15
return mergedConfig?.dotrainOrder?.deployments
? pickBy(
mergedConfigSource.deployments,
(d) => mergedConfig?.scenarios?.[d.scenario]?.deployer?.network?.key === activeNetworkRef,
mergedConfig.dotrainOrder.deployments,
(d) =>
mergedConfig.dotrainOrder.scenarios?.[d.scenario.key]?.deployer?.network?.key ===
activeNetworkRef,
)
: {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Consider adding a TypeScript null assertion after optional chaining.

The function correctly checks for the existence of deployments but when accessing it in the pickBy function, TypeScript might not properly infer that it can't be undefined.

  return mergedConfig?.dotrainOrder?.deployments
    ? pickBy(
-        mergedConfig.dotrainOrder.deployments,
+        mergedConfig.dotrainOrder.deployments!,
        (d) =>
          mergedConfig.dotrainOrder.scenarios?.[d.scenario.key]?.deployer?.network?.key ===
          activeNetworkRef,
      )
    : {};

This makes it explicit to TypeScript that we've already checked for undefined.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return mergedConfig?.dotrainOrder?.deployments
? pickBy(
mergedConfigSource.deployments,
(d) => mergedConfig?.scenarios?.[d.scenario]?.deployer?.network?.key === activeNetworkRef,
mergedConfig.dotrainOrder.deployments,
(d) =>
mergedConfig.dotrainOrder.scenarios?.[d.scenario.key]?.deployer?.network?.key ===
activeNetworkRef,
)
: {};
return mergedConfig?.dotrainOrder?.deployments
? pickBy(
mergedConfig.dotrainOrder.deployments!,
(d) =>
mergedConfig.dotrainOrder.scenarios?.[d.scenario.key]?.deployer?.network?.key ===
activeNetworkRef,
)
: {};

Comment on lines +22 to 27
return mergedConfig?.dotrainOrder.scenarios
? pickBy(
mergedConfig.dotrainOrder.scenarios,
(d) => d?.deployer?.network?.key === activeNetworkRef,
)
: {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Similar TypeScript null assertion needed in pickScenarios.

After fixing the optional chaining, consider adding a null assertion for clarity when accessing the property in the pickBy function.

-  return mergedConfig?.dotrainOrder.scenarios
+  return mergedConfig?.dotrainOrder?.scenarios
    ? pickBy(
-        mergedConfig.dotrainOrder.scenarios,
+        mergedConfig.dotrainOrder.scenarios!,
        (d) => d?.deployer?.network?.key === activeNetworkRef,
      )
    : {};
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return mergedConfig?.dotrainOrder.scenarios
? pickBy(
mergedConfig.dotrainOrder.scenarios,
(d) => d?.deployer?.network?.key === activeNetworkRef,
)
: {};
return mergedConfig?.dotrainOrder?.scenarios
? pickBy(
mergedConfig.dotrainOrder.scenarios!,
(d) => d?.deployer?.network?.key === activeNetworkRef,
)
: {};

Comment on lines +17 to 18
const settings = writable<OrderbookConfig>(parseYaml([settingsYaml]).orderbook);
const activeNetworkRef = writable<string>('');
Copy link
Contributor

@coderabbitai coderabbitai bot Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

settings store type violates AppStoresInterface – pick one schema

AppStoresInterface.settings is still declared as Writable<Config | undefined> (full root object), but here we instantiate
writable<OrderbookConfig>. Because Writable is invariant this compiles only due to the any escape hatches below and can break
call-sites that expect dotrainOrder, accounts, etc.

Two options:

  1. Keep the root config in the store and adapt downstream selectors
    diff -const settings = writable<OrderbookConfig>(parseYaml([settingsYaml]).orderbook); +const fullConfig = parseYaml([settingsYaml]); +const settings = writable<Config>(fullConfig);  
     …then change every $settings.xxx to $settings.orderbook.xxx.

  2. Or change AppStoresInterface so settings really is the OrderbookConfig.

Whichever route you choose, align the types to prevent silent breakage.

Also applies to: 59-65

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@findolor needs addressing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!


export interface LayoutData {
stores: AppStoresInterface;
}

export const load = async ({ fetch }) => {
const response = await fetch(
'https://raw.githubusercontent.com/rainlanguage/rain.strategies/refs/heads/main/settings.json'
'https://raw.githubusercontent.com/findolor/sample-dotrains/6865d8c76dc4182c5f6f41c20299cb017a6298fe/settings.yaml'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to update rain.strategies instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rust Related to rust crates webapp
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change webapp settings from json to yaml Remove ConfigSource and make all the Config fields private
2 participants