Skip to content

Extract RaindexOrderBuilder from js_api into common crate #2471

@findolor

Description

@findolor

Summary

crates/js_api/src/gui/ (~7,850 lines across 7 files) contains the order-building state machine, validation, and transaction generation logic. ~90% is platform-agnostic business logic trapped in the WASM-only crate. Rename from gui to raindex_order_builder to reflect its actual purpose.

What needs to move

Current file New module Lines Core % Description
gui/mod.rs raindex_order_builder 2,120 ~85% RaindexOrderBuilder state machine, config, deployment management
gui/order_operations.rs raindex_order_builder::calldata 1,215 ~95% Transaction calldata (approvals, deposits, addOrder, multicall)
gui/field_values.rs raindex_order_builder::fields 1,008 ~90% Field value parsing, presets, get/set/unset
gui/select_tokens.rs raindex_order_builder::tokens 1,036 ~85% Token selection, RPC metadata fetching
gui/state_management.rs raindex_order_builder::state 950 ~100% Serialize/restore state (gzip+base64+SHA256)
gui/deposits.rs raindex_order_builder::deposits 710 ~95% Deposit state tracking, preset detection
gui/validation.rs raindex_order_builder::validation 703 ~100% Number/string/boolean constraint checking

Key renames

  • DotrainOrderGuiRaindexOrderBuilder
  • GuiErrorRaindexOrderBuilderError
  • gui/raindex_order_builder/

What stays in js_api

Thin WASM wrappers for each module:

  • #[wasm_bindgen] on a WASM-facing struct
  • #[wasm_export] on all public methods
  • js_sys::Function state update callback binding
  • Error-to-JsValue conversions

Proposed approach

  1. Create common::raindex_order_builder module with core RaindexOrderBuilder struct
  2. Replace js_sys::Function callback with generic Rust callback trait/closure
  3. Keep js_api::gui (or rename to js_api::order_builder) as thin WASM wrappers
  4. Ensure RaindexOrderBuilder is usable from CLI and tests without WASM

Benefits

  • CLI can use the same order-building/validation logic
  • Tests can verify state machine without WASM target
  • Server-side tooling can reuse field validation and calldata generation
  • Clear separation: core logic vs platform bindings
  • Name reflects actual purpose (builder, not GUI)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions