Skip to content

feat(ui): auto-submit AddInvoice on saved-LN YES - created enum for settings options#62

Merged
arkanoider merged 5 commits into
mainfrom
feat/addinvoice-autosubmit-settings-enum
May 6, 2026
Merged

feat(ui): auto-submit AddInvoice on saved-LN YES - created enum for settings options#62
arkanoider merged 5 commits into
mainfrom
feat/addinvoice-autosubmit-settings-enum

Conversation

@arkanoider
Copy link
Copy Markdown
Collaborator

@arkanoider arkanoider commented May 6, 2026

Summary

  • Saved Lightning address confirm (ConfirmSavedLnAddressForInvoice): YES (Enter or y) now submits AddInvoice immediately using Settings.ln_address via shared submit_add_invoice (message_handlers.rs), UI goes to WaitingAddInvoice — no second step on the invoice input popup.
  • NO path unchanged: ManualInvoice + NewMessageNotification with empty field (apply_saved_ln_address_invoice_choice).
  • Settings tab: SettingsMenuAction + settings_action_for_index in settings_tab.rs; enter_handlers dispatches by enum instead of raw row indices.

Docs

Updated SETTINGS_ANALYSIS, MESSAGE_FLOW_AND_PROTOCOL, TUI_INTERFACE, buy/sell flow specs, docs/README index line.

Summary by CodeRabbit

  • New Features

    • Confirm-and-auto-submit invoice flow when a saved Lightning address exists (per-order preference to skip repeat prompts)
    • Settings menu: Enter-key now reliably routes actions via centralized menu actions
    • Admin chat: improved persistence, incremental sync and faster UI recovery on startup
  • Documentation

    • Updated docs to describe saved-address invoice flows, Settings behavior, and revised chat/ordering UX

- YES on ConfirmSavedLnAddressForInvoice: submit_add_invoice + WaitingAddInvoice
- NO unchanged: manual invoice popup via apply_saved_ln_address_invoice_choice
- Shared submit_add_invoice for popup Enter and confirm paths (incl. y key)
- Settings tab Enter: SettingsMenuAction + settings_action_for_index
- Docs: auto-submit flow, MESSAGE_FLOW, TUI, buy/sell specs, SETTINGS_ANALYSIS

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

Warning

Rate limit exceeded

@arkanoider has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 33 minutes and 9 seconds before requesting another review.

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5d60c016-6b9d-45d1-a08a-cf2f7eaaad79

📥 Commits

Reviewing files that changed from the base of the PR and between 1396640 and c24cd40.

📒 Files selected for processing (8)
  • docs/MESSAGE_FLOW_AND_PROTOCOL.md
  • docs/SETTINGS_ANALYSIS.md
  • docs/TUI_INTERFACE.md
  • src/ui/key_handler/enter_handlers.rs
  • src/ui/key_handler/message_handlers.rs
  • src/ui/operation_result.rs
  • src/ui/orders.rs
  • src/util/dm_utils/order_ch_mng.rs

Walkthrough

This PR adds a saved Lightning-address confirmation + optional auto-submit path for AddInvoice, extracts invoice submission into submit_add_invoice, and refactors Settings menu routing to a SettingsMenuAction/index mapper. Documentation and TUI flows updated; per-order buyer_invoice_preference cached in AppState.

Changes

AddInvoice Saved-Address + SettingsMenuAction Refactor

Layer / File(s) Summary
Data / Types
src/ui/tabs/settings_tab.rs
Adds public SettingsMenuAction enum, SettingsMenuRow alias, ADMIN_SETTINGS/USER_SETTINGS arrays, and ADMIN_SETTINGS_OPTIONS_COUNT / USER_SETTINGS_OPTIONS_COUNT.
Index → Action Mapping
src/ui/tabs/settings_tab.rs
Adds settings_action_for_index(user_role, idx) -> Option<SettingsMenuAction> and settings_rows(role) to return per-role menu rows.
Core Invoice Submission
src/ui/key_handler/message_handlers.rs
Adds pub fn submit_add_invoice(...) encapsulating validation, waiting-mode toggle, async spawn, and result reporting; replaces duplicated inline logic.
Confirmation Flow
src/ui/key_handler/confirmation.rs
ConfirmSavedLnAddressForInvoice YES path now: validate order_id, load & trim saved LN address from disk, set per-order BuyerInvoicePreference::UseSavedLnAddress, and call submit_add_invoice; NO path preserves manual invoice flow.
Enter-Key Dispatch / Wiring
src/ui/key_handler/enter_handlers.rs
Replaces direct index matches with settings_action_for_index(...) and dispatches SettingsMenuAction variants to existing handlers; imports submit_add_invoice, load_settings_from_disk, BuyerInvoicePreference, and settings helpers. Also delegates AddInvoice handling to submit_add_invoice.
UI State
src/ui/app_state.rs (docs) / code references
Introduces per-order cache usage of AppState.buyer_invoice_preference (tracked in docs; wiring updated to set UseSavedLnAddress).
Documentation
docs/MESSAGE_FLOW_AND_PROTOCOL.md, docs/SETTINGS_ANALYSIS.md, docs/TUI_INTERFACE.md, docs/buy order flow.md, docs/sell order flow.md, docs/README.md
Documented ConfirmSavedLnAddressForInvoice YES/NO branches, auto-submit behavior, buyer_invoice_preference per-order cache, and Settings menu Enter-key routing via SettingsMenuAction/settings_action_for_index.

Sequence Diagrams

sequenceDiagram
    actor User
    participant UI as EnterHandler/UI
    participant Settings as Settings/Disk
    participant State as AppState
    participant Invoice as InvoiceHandler

    User->>UI: Press Enter on ConfirmSavedLnAddressForInvoice (YES)
    activate UI
    UI->>Settings: load_settings_from_disk()
    activate Settings
    Settings-->>UI: saved_ln_address
    deactivate Settings
    UI->>UI: trim & validate address
    UI->>State: set buyer_invoice_preference = UseSavedLnAddress
    activate State
    State-->>UI: preference recorded
    deactivate State
    UI->>Invoice: submit_add_invoice(order_id, trimmed_address)
    activate Invoice
    Invoice->>Invoice: validate, set WaitingAddInvoice, spawn async task
    Invoice-->>UI: report async result
    deactivate Invoice
    UI-->>User: show WaitingAddInvoice
    deactivate UI
Loading
sequenceDiagram
    actor User
    participant EnterHandler as Enter Handler
    participant SettingsTab as Settings Tab
    participant Handler as Action Handler

    User->>EnterHandler: Press Enter on Settings Menu
    activate EnterHandler
    EnterHandler->>SettingsTab: settings_action_for_index(user_role, idx)
    activate SettingsTab
    SettingsTab-->>EnterHandler: SettingsMenuAction
    deactivate SettingsTab
    alt SwitchMode
        EnterHandler->>Handler: handle_mode_switch()
    else SetBuyerLnAddress
        EnterHandler->>Handler: create_key_input_state(AddLnAddress)
    else ClearBuyerLnAddress
        EnterHandler->>Handler: transition to ConfirmClearLnAddress(true)
    else ViewSeedWords
        EnterHandler->>Handler: spawn_seed_words_task()
    else other
        EnterHandler->>Handler: dispatch relevant handler
    end
    Handler-->>User: action executed
    deactivate EnterHandler
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • MostroP2P/mostrix#59: Adds ln_address support and Settings UI/persistence that this PR reads from disk and auto-submits against.
  • MostroP2P/mostrix#60: LNURL verification and invoice/save flows overlap with the autosubmit and settings-driven invoice behaviors here.
  • MostroP2P/mostrix#61: Implements similar ConfirmSavedLnAddressForInvoice UI mode and buyer_invoice_preference per-order caching referenced by this change.

Suggested reviewers

  • AndreaDiazCorreia
  • Catrya
  • mostronatorcoder

Poem

🐰 A saved address snug in a file,
One Enter and the invoice will fly,
No paste, no repeat, the flow runs with style,
Menus remapped so actions comply,
Hop—autosubmit—watch the UI sigh ⚡

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 72.73% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: auto-submit AddInvoice on saved Lightning address confirmation (YES) and introduction of SettingsMenuAction enum. It directly reflects the primary objectives of the PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/addinvoice-autosubmit-settings-enum

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.

Copy link
Copy Markdown
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

🧹 Nitpick comments (2)
src/ui/key_handler/confirmation.rs (1)

187-209: ⚡ Quick win

Keep this confirmation on the Enter/Esc path only.

This branch duplicates the ConfirmSavedLnAddressForInvoice flow already handled in handle_enter_key and reintroduces y-shortcut behavior for a new confirmation mode. Removing the special case here keeps the flow single-sourced and aligned with the repo’s confirmation model.

Based on learnings: In this repo’s Rust TUI, confirmation dialogs are intentionally simplified: remove/ignore y/n shortcut handling for confirm/cancel and support only Enter (confirm) and Esc (cancel).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/ui/key_handler/confirmation.rs` around lines 187 - 209, This branch
handling UiMode::ConfirmSavedLnAddressForInvoice duplicates the Enter/Esc
confirmation flow and reintroduces 'y' shortcut behavior; remove this
special-case branch from the current key handler (or change it to no-op/return
false) so that ConfirmSavedLnAddressForInvoice is only handled by the
centralized confirmation logic (e.g., handle_enter_key or the existing Enter/Esc
path) and avoid directly calling app.buyer_invoice_preference.insert(...) or
submit_add_invoice(...) here.
src/ui/tabs/settings_tab.rs (1)

23-50: ⚡ Quick win

Use one source of truth for settings rows.

settings_action_for_index, the per-role label lists, and the manual *_SETTINGS_OPTIONS_COUNT constants all encode the same menu separately. The next row insertion/removal can desync what the user sees from what Enter dispatches. Consider defining per-role static arrays of (SettingsMenuAction, label) and deriving both rendering and counts from them.

Also applies to: 52-56, 107-132

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/ui/tabs/settings_tab.rs` around lines 23 - 50, The code currently
duplicates the settings menu in multiple places (settings_action_for_index,
per-role label lists, and *_SETTINGS_OPTIONS_COUNT), risking desync; refactor by
introducing two per-role static arrays (e.g., ADMIN_SETTINGS and USER_SETTINGS)
of tuples (SettingsMenuAction, &'static str) and use them as the single source
of truth: change settings_action_for_index to look up the tuple at idx in the
appropriate array and return the action, derive the label lists from the same
arrays when rendering, and compute the *_SETTINGS_OPTIONS_COUNT constants from
array.len(); also update the other affected locations (the label generation
around lines 52-56 and the menu handling around 107-132) to reference these
arrays instead of hard-coded enums/strings.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/ui/key_handler/enter_handlers.rs`:
- Around line 423-430: The code currently collapses load_settings_from_disk()
errors into an empty address by calling .ok().unwrap_or_default(), so replace
that flow: call load_settings_from_disk() and match on the Result (or use
?/map_err) to surface load errors—if Err, set app.mode =
UiMode::OperationResult(OperationResult::Error(format!("Failed to load settings:
{}", err))) and return/stop further processing; if Ok(s), let trimmed =
s.ln_address.trim().to_string() and then check trimmed.is_empty() to set the "No
saved Lightning address in settings" error as before. Ensure you update the code
around the trimmed variable and the existing UiMode::OperationResult handling to
use the real load error when present.

---

Nitpick comments:
In `@src/ui/key_handler/confirmation.rs`:
- Around line 187-209: This branch handling
UiMode::ConfirmSavedLnAddressForInvoice duplicates the Enter/Esc confirmation
flow and reintroduces 'y' shortcut behavior; remove this special-case branch
from the current key handler (or change it to no-op/return false) so that
ConfirmSavedLnAddressForInvoice is only handled by the centralized confirmation
logic (e.g., handle_enter_key or the existing Enter/Esc path) and avoid directly
calling app.buyer_invoice_preference.insert(...) or submit_add_invoice(...)
here.

In `@src/ui/tabs/settings_tab.rs`:
- Around line 23-50: The code currently duplicates the settings menu in multiple
places (settings_action_for_index, per-role label lists, and
*_SETTINGS_OPTIONS_COUNT), risking desync; refactor by introducing two per-role
static arrays (e.g., ADMIN_SETTINGS and USER_SETTINGS) of tuples
(SettingsMenuAction, &'static str) and use them as the single source of truth:
change settings_action_for_index to look up the tuple at idx in the appropriate
array and return the action, derive the label lists from the same arrays when
rendering, and compute the *_SETTINGS_OPTIONS_COUNT constants from array.len();
also update the other affected locations (the label generation around lines
52-56 and the menu handling around 107-132) to reference these arrays instead of
hard-coded enums/strings.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: af2a8e92-be94-4130-9cf4-60c7cf49c327

📥 Commits

Reviewing files that changed from the base of the PR and between 9b825ba and 6be6da7.

📒 Files selected for processing (10)
  • docs/MESSAGE_FLOW_AND_PROTOCOL.md
  • docs/README.md
  • docs/SETTINGS_ANALYSIS.md
  • docs/TUI_INTERFACE.md
  • docs/buy order flow.md
  • docs/sell order flow.md
  • src/ui/key_handler/confirmation.rs
  • src/ui/key_handler/enter_handlers.rs
  • src/ui/key_handler/message_handlers.rs
  • src/ui/tabs/settings_tab.rs

Comment thread src/ui/key_handler/enter_handlers.rs Outdated
@arkanoider arkanoider changed the title feat(ui): auto-submit AddInvoice on saved-LN YES; SettingsMenuAction feat(ui): auto-submit AddInvoice on saved-LN YES - created enum for settings options May 6, 2026
Copy link
Copy Markdown
Contributor

@mostronatorcoder mostronatorcoder Bot left a comment

Choose a reason for hiding this comment

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

I reviewed this one strictly and I do see a blocker in the current implementation.

The new Settings-menu enum cleanup looks fine, but I am not comfortable approving the saved-LN auto-submit path as it stands.

Blocker

When ConfirmSavedLnAddressForInvoice takes the YES path, the code now writes:

  • buyer_invoice_preference[order_id] = UseSavedLnAddress
  • then immediately calls submit_add_invoice(...)

If submit_add_invoice later fails, that per-order preference remains set.

That matters because present_add_invoice_popup() uses this preference to skip the confirmation step on future AddInvoice openings for the same order and jumps straight to the saved-address path. So after one failed auto-submit, reopening the flow can silently auto-select the saved address again instead of showing the confirmation the user just came from.

In other words, the new preference is persisted before the send outcome is known, and on failure it can leave the UI in a sticky state that no longer matches the user’s last successful action.

I think the preference should only be committed after a successful send, or it should be rolled back on the error path.

Because this changes user-facing behavior in the invoice flow, I am marking this as request changes rather than a nit.

@mostronatorcoder
Copy link
Copy Markdown
Contributor

I re-checked the latest push and I still see the same blocker.

ConfirmSavedLnAddressForInvoice still inserts BuyerInvoicePreference::UseSavedLnAddress before submit_add_invoice(...) completes successfully.

So if the auto-submit fails, the per-order preference is still left behind and present_add_invoice_popup() can keep skipping the confirmation on the next open for that same order.

The settings-menu enum refactor looks cleaner now, but the invoice-flow state bug is still present in the current head, so I cannot switch this to approval yet.

Copy link
Copy Markdown
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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/TUI_INTERFACE.md`:
- Line 234: Update the TUI_INTERFACE.md text for the
ConfirmSavedLnAddressForInvoice flow to remove the stale "n" shortcut: replace
any mention that "NO (Enter or `n`)" selects the manual invoice UI with wording
that NO is selected by choosing NO and pressing Enter (and note that Esc
cancels), and ensure the description still references AddInvoice /
WaitingBuyerInvoice mapping, the UiMode::ConfirmSavedLnAddressForInvoice prompt,
auto-submit via submit_add_invoice when YES+Enter is chosen, and that
BuyerInvoicePreference per order_id is remembered until cancelled or the order
row is torn down.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e444a06f-7c91-492d-b52e-1566ed2a6b1f

📥 Commits

Reviewing files that changed from the base of the PR and between 6be6da7 and 1396640.

📒 Files selected for processing (7)
  • docs/MESSAGE_FLOW_AND_PROTOCOL.md
  • docs/README.md
  • docs/SETTINGS_ANALYSIS.md
  • docs/TUI_INTERFACE.md
  • src/ui/key_handler/confirmation.rs
  • src/ui/key_handler/enter_handlers.rs
  • src/ui/tabs/settings_tab.rs
💤 Files with no reviewable changes (1)
  • src/ui/key_handler/confirmation.rs

Comment thread docs/TUI_INTERFACE.md Outdated
Copy link
Copy Markdown
Contributor

@mostronatorcoder mostronatorcoder Bot left a comment

Choose a reason for hiding this comment

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

Re-checking the latest push: the blocker I raised is fixed now.

What changed correctly:

  • ConfirmSavedLnAddressForInvoice no longer stores UseSavedLnAddress before the send outcome is known
  • the saved-address preference is now recorded only on the successful InvoiceSubmitted path
  • on failure, the preference is not left behind, so the flow will not silently skip the confirmation on the next reopen for that same order

I also re-checked the surrounding pieces:

  • the NO path still keeps the manual invoice flow
  • the settings-menu enum refactor is cleaner and removes the fragile raw-index dispatch
  • the new InvoiceSubmitted normalization in order_ch_mng is coherent with the existing result-handling flow

So from the code side, I am good with this now.

Note: at the time of this re-review, some GitHub build jobs were still in progress on commit c24cd403bd39ea30ec7a33baa811d1e8ace4c718, so this approval is based on the code diff and the checks that had already completed successfully.

@arkanoider arkanoider merged commit b5adb0b into main May 6, 2026
11 checks passed
@arkanoider arkanoider deleted the feat/addinvoice-autosubmit-settings-enum branch May 6, 2026 20:58
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