fix: bottom sheet stuck on swap (#2211)

Serhii committed Apr 17, 2025 at 06:14 UTC b2d4698cdf51c33540ad88b98e5070ee5c353af0
2 files changed +17 -1
lib/exchange/trade_state.dart
+3
@@ -7,6 +7,7 @@ class TradeState extends EnumerableItem<String> with Serializable<String> {
7 bool operator ==(Object other) => other is TradeState && other.raw == raw;
8
9 static const pending = TradeState(raw: 'pending', title: 'Pending');
10 + static const awaiting = TradeState(raw: 'awaiting', title: 'Awaiting');
11 static const confirming = TradeState(raw: 'confirming', title: 'Confirming');
12 static const trading = TradeState(raw: 'trading', title: 'Trading');
13 static const traded = TradeState(raw: 'traded', title: 'Traded');
@@ -134,6 +135,8 @@ class TradeState extends EnumerableItem<String> with Serializable<String> {
135 return success;
136 case 'expired':
137 return expired;
138 + case 'awaiting':
139 + return awaiting;
140 default:
141 throw Exception('Unexpected token: $raw in TradeState deserialize');
142 }
lib/src/screens/exchange_trade/exchange_trade_page.dart
+14 -1
@@ -205,6 +205,7 @@ class ExchangeTradeState extends State<ExchangeTradeForm> {
205 );
206 }
207
208 + BuildContext? dialogContext;
209 BuildContext? loadingBottomSheetContext;
210
211 void _setEffects() {
@@ -213,7 +214,12 @@ class ExchangeTradeState extends State<ExchangeTradeForm> {
214 }
215
216 _exchangeStateReaction = reaction((_) => this.widget.exchangeTradeViewModel.sendViewModel.state,
216 - (ExecutionState state) {
217 + (ExecutionState state) async {
218 +
219 + if (dialogContext != null && dialogContext?.mounted == true) {
220 + Navigator.of(dialogContext!).pop();
221 + }
222 +
223 if (state is! IsExecutingState &&
224 loadingBottomSheetContext != null &&
225 loadingBottomSheetContext!.mounted) {
@@ -237,6 +243,13 @@ class ExchangeTradeState extends State<ExchangeTradeForm> {
243 }
244
245 if (state is IsExecutingState) {
246 + // wait a bit to avoid showing the loading dialog if transaction is failed
247 + await Future.delayed(const Duration(milliseconds: 300));
248 + final currentState = widget.exchangeTradeViewModel.sendViewModel.state;
249 + if (currentState is ExecutedSuccessfullyState || currentState is FailureState) {
250 + return;
251 + }
252 +
253 WidgetsBinding.instance.addPostFrameCallback((_) {
254 if (context.mounted) {
255 showModalBottomSheet<void>(