diff --git a/lib/features/order/notfiers/abstract_mostro_notifier.dart b/lib/features/order/notfiers/abstract_mostro_notifier.dart index 1b90c9773..d7e11cc10 100644 --- a/lib/features/order/notfiers/abstract_mostro_notifier.dart +++ b/lib/features/order/notfiers/abstract_mostro_notifier.dart @@ -219,6 +219,17 @@ class AbstractMostroNotifier extends StateNotifier { break; case Action.cantDo: final cantDo = event.getPayload(); + + // Handle specific case of out_of_range_sats_amount + if (cantDo?.cantDoReason == CantDoReason.outOfRangeSatsAmount) { + logger.i('Received out_of_range_sats_amount, cleaning up session for retry'); + + // Clean up temporary session if it exists by requestId + if (event.requestId != null) { + ref.read(sessionNotifierProvider.notifier).cleanupRequestSession(event.requestId!); + } + } + ref.read(notificationProvider.notifier).showInformation( event.action, values: { diff --git a/lib/features/order/notfiers/add_order_notifier.dart b/lib/features/order/notfiers/add_order_notifier.dart index 458029c91..c6eb36fd8 100644 --- a/lib/features/order/notfiers/add_order_notifier.dart +++ b/lib/features/order/notfiers/add_order_notifier.dart @@ -5,6 +5,7 @@ import 'package:mostro_mobile/data/models.dart'; import 'package:mostro_mobile/shared/providers.dart'; import 'package:mostro_mobile/features/order/notfiers/abstract_mostro_notifier.dart'; import 'package:mostro_mobile/features/order/providers/order_notifier_provider.dart'; +import 'package:mostro_mobile/features/order/models/order_state.dart'; import 'package:mostro_mobile/services/mostro_service.dart'; class AddOrderNotifier extends AbstractMostroNotifier { @@ -40,6 +41,12 @@ class AddOrderNotifier extends AbstractMostroNotifier { } } else if (msg.payload is CantDo) { handleEvent(msg); + + // Reset for retry if out_of_range_sats_amount + final cantDo = msg.getPayload(); + if (cantDo?.cantDoReason == CantDoReason.outOfRangeSatsAmount) { + _resetForRetry(); + } } } }, @@ -76,4 +83,23 @@ class AddOrderNotifier extends AbstractMostroNotifier { await mostroService.submitOrder(message); state = state.updateWith(message); } + + /// Reset notifier state for retry after out_of_range_sats_amount error + void _resetForRetry() { + logger.i('Resetting AddOrderNotifier for retry after out_of_range_sats_amount'); + + // Generate new requestId for next attempt + requestId = _requestIdFromOrderId(orderId); + + // Reset state to initial clean state + state = OrderState( + action: Action.newOrder, + status: Status.pending, + order: null, + ); + + // Re-subscribe with new requestId + subscription?.close(); + subscribe(); + } } diff --git a/lib/shared/notifiers/session_notifier.dart b/lib/shared/notifiers/session_notifier.dart index 587eef9f9..6df09e611 100644 --- a/lib/shared/notifiers/session_notifier.dart +++ b/lib/shared/notifiers/session_notifier.dart @@ -160,6 +160,18 @@ class SessionNotifier extends StateNotifier> { state = sessions; } + /// Clean up temporary session by requestId + /// Used when order creation fails and needs retry + void cleanupRequestSession(int requestId) { + final session = _requestIdToSession.remove(requestId); + if (session != null) { + // Remove from state list if it was a temporary session + final updatedSessions = sessions.where((s) => s != session).toList(); + state = updatedSessions; + _logger.d('Cleaned up temporary session for requestId: $requestId'); + } + } + NostrKeyPairs calculateSharedKey( String tradePrivateKey, String counterpartyPublicKey) { try {