Skip to content

Commit 423fe62

Browse files
Catryagrunch
andauthored
Refactor: flow from waiting to pending status (MostroP2P#327)
* refactor: handle waiting→pending timeouts via direct gift wraps - Replace timeout detection for waiting-buyer-invoice/waiting-payment → pending - Handle via direct gift wraps: Action.canceled (taker) / Action.newOrder (maker) - Remove 38383 event monitoring for timeout scenarios only - Eliminate timeout-specific logic: _checkTimeoutAndCleanup, _subscribeToPublicEvents - Preserve other functionality unchanged * remove cancel * refactor: remove obsolete timeout detection via 38383 events - Remove Action.timeoutReversal enum and all related logic - Remove MostroMessage.createTimeoutReversal() factory method - Clean up FSM transitions and notification handling - Remove timeout detection constants from Config * update documentation, remove timeout detection using 38383 events * fix: detect automatic order cancellation for pending orders via 38383 events - Add selective public event monitoring in OrderNotifier - Detect when Mostro automatically cancels pending orders (pending → canceled) - Delete session to remove expired orders from My Trades - Show cancellation notification to user - Maintain existing gift wrap timeout system unchanged - Only affects maker-created orders that expire automatically * coderabit_suggest * Add mounted checks after async operations * fix: remove mounted check that broke order state synchronization --------- Co-authored-by: grunch <fjcalderon@gmail.com>
1 parent ffa6966 commit 423fe62

File tree

13 files changed

+218
-733
lines changed

13 files changed

+218
-733
lines changed

CLAUDE.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -141,46 +141,46 @@ Spanish: "No hubo respuesta, verifica tu conexión e inténtalo más tarde"
141141
Italian: "Nessuna risposta ricevuta, verifica la tua connessione e riprova più tardi"
142142
```
143143

144-
### Real-Time Timeout Detection
144+
### Gift Wrap-Based Timeout Detection
145145

146146
#### **Detection Mechanism**
147-
- **Monitors**: 38383 public events for status changes
148-
- **Triggers**: When public event shows different status than local state (simplified logic without timestamp comparison)
149-
- **Real-time**: Subscribes to `orderEventsProvider` for instant detection
147+
- **Direct Instructions**: Receives explicit timeout/cancellation instructions from Mostro via encrypted gift wrap messages (kind 1059)
148+
- **No Monitoring Required**: No need to monitor public events or compare timestamps
149+
- **Real-time**: Gift wrap messages delivered through existing SubscriptionManager system
150150
- **Integration**: Works alongside 10-second cleanup for comprehensive protection
151151

152152
#### **Maker Scenario (Order Creator)**
153-
When taker doesn't respond and order returns to pending:
153+
When taker doesn't respond, Mostro sends `Action.newOrder` gift wrap:
154154
- **Session**: Preserved (keeps order in "My Trades")
155-
- **State**: Updated to `Status.pending` with `Action.timeoutReversal`
156-
- **Persistence**: Creates synthetic `MostroMessage.createTimeoutReversal()` stored with unique key
157-
- **Result**: Order remains visible but shows pending status after app restart
155+
- **State**: Updated to `Status.pending` with `Action.newOrder`
156+
- **Persistence**: Real gift wrap message automatically persisted by message storage system
157+
- **Result**: Order remains visible and shows pending status after app restart
158+
- **Notification**: "Your counterpart didn't respond in time"
158159

159160
#### **Taker Scenario (Order Taker)**
160-
When user doesn't respond and order returns to pending:
161+
When user doesn't respond, Mostro sends `Action.canceled` gift wrap:
161162
- **Session**: Deleted completely via `sessionNotifier.deleteSession()`
162-
- **State**: Provider invalidated (`ref.invalidateSelf()`)
163+
- **State**: Provider invalidated and session removed
163164
- **Result**: Order disappears from "My Trades" and reappears in order book for retaking
165+
- **Notification**: "Order was canceled"
164166

165167
### Cancellation Detection & Cleanup
166-
When orders are canceled (status changes to `canceled` in public events):
167-
- **Detection**: Public event monitoring system (independent of timestamps)
168-
- **Session Cleanup**: State-based logic - only deletes session for pending/waiting states
168+
When orders are canceled, Mostro sends `Action.canceled` gift wrap:
169+
- **Detection**: Direct gift wrap instruction processing in `AbstractMostroNotifier.handleEvent()`
170+
- **Session Cleanup**: Universal cancellation handling for both timeout and manual cancellation scenarios
169171
- **Active Orders**: Canceled active orders keep session but update to canceled status
170172
- **UI Behavior**: Pending/waiting orders disappear, active orders show canceled status
171173
- **User Feedback**: Shows cancellation notification
172-
- **Implementation**: `_checkTimeoutAndCleanup()` method in `order_notifier.dart:172-211`
174+
- **Implementation**: Gift wrap handling in `abstract_mostro_notifier.dart`
173175

174176
### Key Implementation
175-
- **Dual Protection**: 10-second cleanup + real-time detection provide comprehensive coverage
176-
- **Race protection**: `_isProcessingTimeout` flag prevents concurrent execution (with proper early return handling)
177-
- **Role detection**: `_isCreatedByUser()` compares session role with order type
177+
- **Dual Protection**: 10-second cleanup + gift wrap instructions provide comprehensive coverage
178+
- **Simplified Logic**: Direct instruction processing eliminates complex event monitoring
178179
- **Timer management**: Static timer storage with proper cleanup on disposal, differentiated keys (`orderId` vs `request:requestId`)
179180
- **Error resilience**: Timeouts and try-catch blocks prevent app hangs
180181
- **Notifications**: Differentiated messages for maker vs taker scenarios
181-
- **Simplified Logic**: Status-based detection without timestamp comparison
182-
- **State-based Rules**: Different session handling based on local order state
183-
- **Timeout Detection**: `public=pending + local=waiting = guaranteed timeout`
182+
- **Direct Communication**: Mostro decides and instructs directly via encrypted messages
183+
- **No Synthetic Messages**: Real gift wrap messages contain all needed information
184184
- **Session Differentiation**: Permanent sessions (orderId) vs temporary sessions (requestId) with appropriate cleanup methods
185185

186186
### Testing Structure
@@ -524,7 +524,7 @@ For complete technical documentation, see `RELAY_SYNC_IMPLEMENTATION.md`.
524524

525525
---
526526

527-
**Last Updated**: September 29, 2025
527+
**Last Updated**: October 8, 2025
528528
**Flutter Version**: Latest stable
529529
**Dart Version**: Latest stable
530530
**Key Dependencies**: Riverpod, GoRouter, flutter_intl, timeago, dart_nostr, logger, shared_preferences

0 commit comments

Comments
 (0)