# React + Rust WASM Order Book

> Interactive React frontend connected to a compiled Rust zwire WASM engine via WireScope, ReactiveCollection, and @zwire/react/tx.

:::tip[Live preview]
Try this compiled Rust WASM + React order book directly in your browser: **[Open live WASM order book](https://preview.zwire.studiocyf.app/wasm-orderbook/)**
:::

The Rust engine ranks bids in a `ReactiveCollection` and exposes its committed balance, best bid and desk note through `WireScope`. The React client hydrates those values, subscribes through `@zwire/react`, and holds the reservation in a component-owned optimistic layer from `@zwire/react/tx` (`useOptimisticLayer`).

1. Choose **Reserve 150**. The available balance changes from 1,000 to 850 in a TypeScript optimistic layer.
2. Choose **Apply market update**. Rust raises the best bid to 125 and credits 500 in one batch. The displayed balance becomes 1,350 while the reservation is active.
3. Choose **Release reservation**. The balance returns to the new committed value of 1,500.
4. Enter a desk note and choose **Save in Rust**. The acknowledgement reads the value from the Rust engine.

## Run

From the repository root, install the pinned toolchains, the JS dependencies and the matching wasm-bindgen CLI:

```sh
pnpm install --frozen-lockfile --ignore-scripts
(cd rust && rustup target add wasm32-unknown-unknown && cargo install wasm-bindgen-cli --version 0.2.130 --locked)
mise run test:wasm
python3 -m http.server 8080 --bind 127.0.0.1 --directory examples/wasm-orderbook/dist
```

Open `http://127.0.0.1:8080`. The test instantiates the same compiled WASM and bundled React view and drives the four interactions above.
