diff --git a/lib/exchange/trade_state.dart b/lib/exchange/trade_state.dart index f63b41e5d..e1c4470b4 100644 --- a/lib/exchange/trade_state.dart +++ b/lib/exchange/trade_state.dart @@ -7,6 +7,7 @@ class TradeState extends EnumerableItem with Serializable { bool operator ==(Object other) => other is TradeState && other.raw == raw; static const pending = TradeState(raw: 'pending', title: 'Pending'); + static const awaiting = TradeState(raw: 'awaiting', title: 'Awaiting'); static const confirming = TradeState(raw: 'confirming', title: 'Confirming'); static const trading = TradeState(raw: 'trading', title: 'Trading'); static const traded = TradeState(raw: 'traded', title: 'Traded'); @@ -134,6 +135,8 @@ class TradeState extends EnumerableItem with Serializable { return success; case 'expired': return expired; + case 'awaiting': + return awaiting; default: throw Exception('Unexpected token: $raw in TradeState deserialize'); } diff --git a/lib/src/screens/exchange_trade/exchange_trade_page.dart b/lib/src/screens/exchange_trade/exchange_trade_page.dart index 277d3c838..f4c8d590f 100644 --- a/lib/src/screens/exchange_trade/exchange_trade_page.dart +++ b/lib/src/screens/exchange_trade/exchange_trade_page.dart @@ -205,6 +205,7 @@ class ExchangeTradeState extends State { ); } + BuildContext? dialogContext; BuildContext? loadingBottomSheetContext; void _setEffects() { @@ -213,7 +214,12 @@ class ExchangeTradeState extends State { } _exchangeStateReaction = reaction((_) => this.widget.exchangeTradeViewModel.sendViewModel.state, - (ExecutionState state) { + (ExecutionState state) async { + + if (dialogContext != null && dialogContext?.mounted == true) { + Navigator.of(dialogContext!).pop(); + } + if (state is! IsExecutingState && loadingBottomSheetContext != null && loadingBottomSheetContext!.mounted) { @@ -237,6 +243,13 @@ class ExchangeTradeState extends State { } if (state is IsExecutingState) { + // wait a bit to avoid showing the loading dialog if transaction is failed + await Future.delayed(const Duration(milliseconds: 300)); + final currentState = widget.exchangeTradeViewModel.sendViewModel.state; + if (currentState is ExecutedSuccessfullyState || currentState is FailureState) { + return; + } + WidgetsBinding.instance.addPostFrameCallback((_) { if (context.mounted) { showModalBottomSheet(