Skip to content

feat(restore): differentiate restore outcomes by cant-do reason#588

Open
Catrya wants to merge 3 commits into
mainfrom
restore-errors
Open

feat(restore): differentiate restore outcomes by cant-do reason#588
Catrya wants to merge 3 commits into
mainfrom
restore-errors

Conversation

@Catrya
Copy link
Copy Markdown
Member

@Catrya Catrya commented May 6, 2026

Map cant-do responses from Action.lastTradeIndex to specific user-facing messages instead of a single generic error:

  • not_found: complete restore as new user with informative subtext ("No previous data for this user in this Mostro"). Same green icon as a normal successful restore.
  • invalid_trade_index: show the error overlay with a specific subtext ("Invalid trade index").
  • Any other cant-do reason or timeout: keep the existing generic error message.

Restore behavior (key indices, sessions, navigation) is unchanged. syncTradeIndex remains silent.

Summary by CodeRabbit

  • New Features

    • Restore flow now detects when no prior transaction history exists and completes as a new user, showing a tailored status line and briefly extending the message display.
    • Restore errors for an invalid trade index now surface a specific localized error line.
  • Documentation

    • Added localized restore messages for "no previous data" and "invalid trade index" in English, German, Spanish, French, and Italian.

Map cant-do responses from Action.lastTradeIndex to specific user-facing
messages instead of a single generic error:

- not_found: complete restore as new user with informative subtext
  ("No previous data for this user in this Mostro"). Same green icon
  as a normal successful restore.
- invalid_trade_index: show the error overlay with a specific subtext
  ("Invalid trade index").
- Any other cant-do reason or timeout: keep the existing generic error
  message.

Restore behavior (key indices, sessions, navigation) is unchanged.
syncTradeIndex remains silent.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cba3fd90-8250-4446-84bc-e2a42103b937

📥 Commits

Reviewing files that changed from the base of the PR and between 4202a47 and 9025887.

📒 Files selected for processing (4)
  • lib/l10n/intl_de.arb
  • lib/l10n/intl_es.arb
  • lib/l10n/intl_fr.arb
  • lib/l10n/intl_it.arb
🚧 Files skipped from review as they are similar to previous changes (4)
  • lib/l10n/intl_de.arb
  • lib/l10n/intl_fr.arb
  • lib/l10n/intl_es.arb
  • lib/l10n/intl_it.arb

Walkthrough

The PR adds a noHistoryFound flag through the last-trade-index model, restore state, notifier, manager, and overlay. The manager now parses Mostro cant-do reasons (including invalid_trade_index and notFound), surfaces an invalid_trade_index error, and completes the flow as a new user when no history exists.

Changes

Restore "No History Found" Flow

Layer / File(s) Summary
Data Shape
lib/data/models/last_trade_index_response.dart
LastTradeIndexResponse adds final bool noHistoryFound with constructor default false.
State Model
lib/features/restore/restore_progress_state.dart
RestoreProgressState gains noHistoryFound field, constructor default, and copyWith support.
State Mutation
lib/features/restore/restore_progress_notifier.dart
New completeAsNewUser() marks completed state with noHistoryFound: true, cancels timer, and schedules 5s auto-hide.
Core Logic
lib/features/restore/restore_manager.dart
_extractLastTradeIndex() now inspects Mostro cant-do via _extractCantDoReason(); throws RestoreInvalidTradeIndexException for invalid_trade_index, returns LastTradeIndexResponse(tradeIndex: 0, noHistoryFound: true) for notFound. initRestoreProcess() tracks noHistoryFound, maps RestoreInvalidTradeIndexException to overlay key invalid_trade_index, and calls completeAsNewUser() when appropriate. Also adds RestoreInvalidTradeIndexException type and import for cant_do_reason.dart.
UI Rendering
lib/features/restore/restore_overlay.dart
Overlay renders an italicized, semi-transparent restoreNoPreviousData line when step == completed && noHistoryFound, and an italicized restoreInvalidTradeIndex line when step == error && errorMessage == 'invalid_trade_index'.
Localization
lib/l10n/intl_*.arb
Adds restoreNoPreviousData and restoreInvalidTradeIndex keys across intl_en.arb, intl_de.arb, intl_es.arb, intl_fr.arb, intl_it.arb.

Sequence Diagram

sequenceDiagram
    participant Server as Mostro Server
    participant Manager as RestoreManager
    participant State as RestoreProgressState
    participant Notifier as RestoreProgressNotifier
    participant UI as RestoreOverlay

    Server->>Manager: Respond with cant-do (notFound / invalid_trade_index)
    Manager->>Manager: Call _extractCantDoReason(payload)
    alt cant-do == notFound
        Manager->>Manager: return LastTradeIndexResponse(noHistoryFound: true)
        Manager->>State: set noHistoryFound = true
        State->>Notifier: update state (completed + noHistoryFound)
        Notifier->>UI: emit completed + noHistoryFound
        UI->>UI: show "restore no previous data"
    else cant-do == invalid_trade_index
        Manager->>Manager: throw RestoreInvalidTradeIndexException
        Manager->>Notifier: show error with key "invalid_trade_index"
        UI->>UI: show "restore invalid trade index"
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • MostroP2P/mobile#566: Both PRs modify the restore/last-trade-index flow and cant-do reason handling (including invalid_trade_index) in restore_manager and related restore UI/state.
  • MostroP2P/mobile#355: Earlier changes to the same restore flow files (model, manager, notifier, state).
  • MostroP2P/mobile#440: Modifies restore_manager and completion/wiring related to restore success signaling.

Suggested reviewers

  • BraCR10
  • grunch
  • mostronator

"🐰 I hopped through logs and parsed the sky,
If history's gone, a fresh start's nigh.
No trades found — I'll whisper so clear,
Invalid index? I'll flag it here.
Hooray — restores sing in every tongue!"

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately and concisely describes the main change: implementing differentiation of restore outcomes based on cant-do reason types, which is the core objective of this changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 restore-errors

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.

@Catrya
Copy link
Copy Markdown
Member Author

Catrya commented May 6, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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: 3

🧹 Nitpick comments (1)
lib/features/restore/restore_manager.dart (1)

965-970: ⚡ Quick win

Use typed restore error codes instead of raw string literals.

'invalid_trade_index' and 'restore_error' are string-coupled with UI checks; a typo silently changes behavior. Consider a small shared enum/const set for restore error codes.

🤖 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 `@lib/features/restore/restore_manager.dart` around lines 965 - 970, Replace
the raw string literals used for restore error keys with a typed set (enum or
const) and update usage in restore_manager.dart: define a RestoreErrorCode
(e.g., invalidTradeIndex, genericRestoreError) and use it when computing
errorKey instead of 'invalid_trade_index'/'restore_error'; update the call site
restoreProgressProvider.notifier.showError to accept the typed RestoreErrorCode
(or map the enum to the existing string inside a single conversion helper) and
adjust any UI overlay mapping to use the new enum/const values so typos no
longer silently change behavior (refer to RestoreInvalidTradeIndexException,
errorKey, and restoreProgressProvider.notifier.showError).
🤖 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 `@lib/l10n/intl_fr.arb`:
- Line 1249: Update the French translation for the key restoreInvalidTradeIndex
in lib/l10n/intl_fr.arb by replacing the English word "trade" with the French
term "échange" (e.g., change the value to "Index d'échange invalide") so it
matches existing French terminology; ensure you only modify the string value for
restoreInvalidTradeIndex and preserve JSON/ARB syntax and quoting.

In `@lib/l10n/intl_it.arb`:
- Line 1290: The translation for the key restoreInvalidTradeIndex uses "Indice
di trade non valido"; update the value to use the app's consistent Italian
terminology by replacing it with "Indice di scambio non valido" so it matches
other entries using "indice di scambio" (key: restoreInvalidTradeIndex).

---

Nitpick comments:
In `@lib/features/restore/restore_manager.dart`:
- Around line 965-970: Replace the raw string literals used for restore error
keys with a typed set (enum or const) and update usage in restore_manager.dart:
define a RestoreErrorCode (e.g., invalidTradeIndex, genericRestoreError) and use
it when computing errorKey instead of 'invalid_trade_index'/'restore_error';
update the call site restoreProgressProvider.notifier.showError to accept the
typed RestoreErrorCode (or map the enum to the existing string inside a single
conversion helper) and adjust any UI overlay mapping to use the new enum/const
values so typos no longer silently change behavior (refer to
RestoreInvalidTradeIndexException, errorKey, and
restoreProgressProvider.notifier.showError).
🪄 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: 9d370874-99b1-4fd9-91a9-c83d8ab07aef

📥 Commits

Reviewing files that changed from the base of the PR and between b8bbee9 and 91da205.

📒 Files selected for processing (10)
  • lib/data/models/last_trade_index_response.dart
  • lib/features/restore/restore_manager.dart
  • lib/features/restore/restore_overlay.dart
  • lib/features/restore/restore_progress_notifier.dart
  • lib/features/restore/restore_progress_state.dart
  • lib/l10n/intl_de.arb
  • lib/l10n/intl_en.arb
  • lib/l10n/intl_es.arb
  • lib/l10n/intl_fr.arb
  • lib/l10n/intl_it.arb

Comment thread lib/features/restore/restore_manager.dart Outdated
Comment thread lib/l10n/intl_fr.arb Outdated
Comment thread lib/l10n/intl_it.arb Outdated
@Catrya
Copy link
Copy Markdown
Member Author

Catrya commented May 7, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Member

@BraCR10 BraCR10 left a comment

Choose a reason for hiding this comment

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

tACK

While I was testing, I noticed an unusual behavior. However, I think it is outside the scope of this PR.

First, I created an order in one Mostro instance. Then, I connected to another node where my user did not have any orders. Finally, I tried to reconnect to the original Mostro instance where my orders existed.

I tried more than three times and it did not work. However, after each failed restore attempt while reconnecting to the instance, I manually refreshed the user, and the restore worked properly afterwards.

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.

2 participants