Skip to content

First merge of a big block of code to star develop#21

Merged
arkanoider merged 23 commits into
mainfrom
develop
Dec 3, 2025
Merged

First merge of a big block of code to star develop#21
arkanoider merged 23 commits into
mainfrom
develop

Conversation

@arkanoider

@arkanoider arkanoider commented Dec 3, 2025

Copy link
Copy Markdown
Collaborator

@grunch , @Catrya , @AndreaDiazCorreia ,

this is the first merge of a big block of code for new mostro tui client called MostriX, what is inside:

  • basic tabs for commands needed for order flow: creation, order taking, messages.
  • Use of ratatui beta version for tui interface

This is totally not usable at the moment and completely in develop.

Summary by CodeRabbit

  • New Features

    • Tabbed navigation interface (Orders, Trades, Messages, Settings, Create Order)
    • Keyboard-driven order management with confirmation workflows
    • Invoice handling and Lightning payment support
    • Message notifications for order updates
    • Multi-relay Nostr connectivity
  • Improvements

    • Enhanced UI with modal popups and status indicators
    • Better Nostr key configuration
    • Improved order database persistence
  • Chores

    • Added VSCode debugging configuration
    • Updated dependencies (ratatui, mostro-core, nostr-sdk)

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Dec 3, 2025

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

This PR introduces a comprehensive UI module with tabbed navigation and keyboard event handling, restructures the application to use polling-based order fetching with background tasks, updates database schema to support trade key management, adds dependency upgrades, and implements direct message utilities for Nostr-based order communication.

Changes

Cohort / File(s) Summary
Configuration & Debugging
.vscode/launch.json, Cargo.toml, settings.toml, src/settings.rs
Adds VS Code debug configurations for LLDB, upgrades dependencies (ratatui, mostro-core, nostr-sdk), adds base64/uuid/reqwest/lightning-invoice/lnurl-rs, introduces nsec\_privkey and pow settings, expands relays list, adds Default derive to Settings struct.
Database & Schema
src/db.rs
Adds trade\_keys, counterparty\_pubkey, buyer\_invoice columns to orders table; removes buyer\_trade\_pubkey and seller\_trade\_pubkey; implements database file creation guard.
Data Models
src/models.rs
Expands User with async DB methods (save, get, update\_last\_trade\_index, get\_identity\_keys, derive\_trade\_keys); restructures Order with new fields (trade\_keys, counterparty\_pubkey, buyer\_invoice, request\_id) and implements async persistence methods (insert\_db, update\_db, get\_by\_id, new).
Application Core
src/main.rs
Exports ui and util modules, publicizes SETTINGS, rearchitects main flow to use polling-based order fetching via util functions, introduces background tasks for order fetches and message listening, refactors event loop to handle async results and UI state transitions.
UI Module Core
src/ui/mod.rs
Introduces complete UI state management: Tab enum, UiMode state machine, FormState, TakeOrderState, AppState, OrderResult, MessageNotification structures; defines PRIMARY\_COLOR and BACKGROUND\_COLOR constants; implements ui\_draw rendering function.
UI Components
src/ui/key_handler.rs, src/ui/order_confirm.rs, src/ui/order_form.rs, src/ui/order_result.rs, src/ui/order_take.rs, src/ui/orders_tab.rs, src/ui/status.rs, src/ui/tab_content.rs, src/ui/tabs.rs, src/ui/waiting.rs
Implements keyboard event routing (handle\_key\_event with Enter, Esc, char input dispatch), renders modals for order confirmation/results/taking, builds orders list view, messages tab, form inputs, tab bar, status bar with notification blinking, and waiting spinner.
Utility Modules
src/util/mod.rs, src/util/db_utils.rs, src/util/dm_utils.rs, src/util/filters.rs, src/util/order_utils.rs, src/util/types.rs
Adds order persistence (save\_order), Nostr DM creation/sending/parsing with GiftWrap support (send\_dm, wait\_for\_dm, parse\_dm\_events), background listener for order messages (listen\_for\_order\_messages), event filtering (create\_filter), order parsing/fetching/creation/taking workflows (fetch\_events\_list, send\_new\_order, take\_order, execute\_add\_invoice), and shared types (ListKind, Event, CantDoReason descriptions).

Sequence Diagram

sequenceDiagram
    participant User as User (TUI)
    participant MainLoop as Main Event Loop
    participant BGTask as Background Tasks
    participant Client as Nostr Client
    participant DB as Database
    participant Mostro as Mostro Relay

    rect rgb(177, 204, 51, 0.1)
    note over MainLoop: Initialization
    MainLoop->>DB: Initialize pool & schema
    MainLoop->>Client: Configure with identity keys
    MainLoop->>Client: Add relays & connect()
    MainLoop->>BGTask: Spawn fetch_events task
    MainLoop->>BGTask: Spawn listen_for_order_messages task
    end

    rect rgb(177, 204, 51, 0.1)
    note over MainLoop: Main UI Loop
    User->>MainLoop: KeyEvent (e.g., Enter to create order)
    MainLoop->>MainLoop: Route via key_handler
    MainLoop->>MainLoop: Update AppState/UiMode
    MainLoop->>MainLoop: Call ui_draw → Render frame
    end

    rect rgb(177, 204, 51, 0.1)
    note over BGTask: Background Order Fetch
    BGTask->>Client: fetch_events_list(Orders, Pending)
    Client->>Mostro: Subscribe & query events
    Mostro-->>Client: SmallOrder events
    Client-->>BGTask: Events received
    BGTask->>MainLoop: Send via order_result_tx channel
    end

    rect rgb(177, 204, 51, 0.1)
    note over MainLoop: Create/Send New Order
    User->>MainLoop: Fill form & press Enter
    MainLoop->>MainLoop: Validate & construct Order
    MainLoop->>Client: send_dm(take\\_order payload)
    Client->>Mostro: Send PrivateDirectMessage/GiftWrap
    Mostro-->>Client: Response event
    MainLoop->>DB: Order::new() → persist to DB
    MainLoop->>MainLoop: Show OrderResult popup
    end

    rect rgb(177, 204, 51, 0.1)
    note over BGTask: Message Listener
    BGTask->>DB: Get active_order_trade_indices
    loop Every 5s
        BGTask->>Client: Fetch GiftWrap events for trade keys
        Client->>Mostro: Query recent events
        Mostro-->>Client: GiftWrap/DM events
        BGTask->>BGTask: Decrypt & parse DMs
        BGTask->>MainLoop: Send MessageNotification via channel
    end
    end

    rect rgb(177, 204, 51, 0.1)
    note over MainLoop: Handle Message Notification
    MainLoop->>User: Show NewMessageNotification popup
    User->>MainLoop: Enter invoice (AddInvoice action)
    MainLoop->>Client: execute_add\\_invoice → send\\_dm
    Client->>Mostro: Send AddInvoice payload
    Mostro-->>MainLoop: Ack/response
    MainLoop->>DB: Update order state
    MainLoop->>MainLoop: Close popup, return to Orders tab
    end
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120+ minutes

Areas requiring detailed attention:

  • src/ui/key_handler.rs — Complex state machine with 20+ handler functions managing multiple UiMode transitions, async task spawning, and channel coordination; requires careful trace of control flow across modes (CreatingOrder → ConfirmingOrder → WaitingForMostro, etc.).
  • src/models.rs — Significant database schema changes (removed buyer/seller\_trade\_pubkey, added trade\_keys/counterparty\_pubkey/buyer\_invoice) with new async persistence methods (insert\_db, update\_db); verify SQL migration logic and foreign key integrity.
  • src/util/dm_utils.rs — Non-trivial cryptographic operations (GiftWrap creation with optional signing, conversation key derivation, payload encryption/decryption); background listener spawned as tokio task with periodic polling and deduplication logic.
  • src/main.rs — Architectural refactoring from event-driven to polling-based with background tasks; replaced on-struct parsing with utility-based flows; verify channel coordination between main loop and background tasks, error propagation, and graceful shutdown.
  • src/ui/mod.rs — Large UI state machine definition with 9 UiMode variants and multiple shared state structures (Arc<Mutex<...>>); verify state consistency and locking patterns.
  • src/util/order_utils.rs — End-to-end order workflows (send\_new\_order, take\_order, execute\_add\_invoice) with form validation, payload construction, DM exchange, and DB persistence; complex error handling and Mostro response parsing.
  • Database schema migrations — Verify that db.rs schema creation handles the new columns correctly and doesn't break backward compatibility.

Possibly related PRs

  • Improve settings #20 — Updates Settings struct and settings.toml with configuration fields; shares settings-driven architecture and relay/currency configuration patterns with this PR.

Poem

🐰 Hops of joy! A grand refactor done,
Keyboards dance, orders fetch as one,
Trade keys blend with messages so keen,
Tabs and modals grace the bustling screen!
From relays to DB, the flow runs true—
A UI garden, polished fresh and new! 🌸

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch develop

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between def538c and d008e71.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (24)
  • .vscode/launch.json (1 hunks)
  • Cargo.toml (2 hunks)
  • settings.toml (1 hunks)
  • src/db.rs (5 hunks)
  • src/main.rs (5 hunks)
  • src/models.rs (4 hunks)
  • src/settings.rs (2 hunks)
  • src/ui/key_handler.rs (1 hunks)
  • src/ui/mod.rs (1 hunks)
  • src/ui/order_confirm.rs (1 hunks)
  • src/ui/order_form.rs (1 hunks)
  • src/ui/order_result.rs (1 hunks)
  • src/ui/order_take.rs (1 hunks)
  • src/ui/orders_tab.rs (1 hunks)
  • src/ui/status.rs (1 hunks)
  • src/ui/tab_content.rs (1 hunks)
  • src/ui/tabs.rs (1 hunks)
  • src/ui/waiting.rs (1 hunks)
  • src/util/db_utils.rs (1 hunks)
  • src/util/dm_utils.rs (1 hunks)
  • src/util/filters.rs (1 hunks)
  • src/util/mod.rs (1 hunks)
  • src/util/order_utils.rs (1 hunks)
  • src/util/types.rs (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@arkanoider arkanoider merged commit 201a0b5 into main Dec 3, 2025
1 check was pending
@coderabbitai coderabbitai Bot mentioned this pull request Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant