diff --git a/lib/pages/exchange_view/exchange_step_views/step_4_view.dart b/lib/pages/exchange_view/exchange_step_views/step_4_view.dart index 30d40f008..16eb3923f 100644 --- a/lib/pages/exchange_view/exchange_step_views/step_4_view.dart +++ b/lib/pages/exchange_view/exchange_step_views/step_4_view.dart @@ -579,7 +579,7 @@ class _Step4ViewState extends ConsumerState { time, ]); - final txData = results.last + final txData = results.first as Map; if (!wasCancelled) { diff --git a/lib/pages/wallet_view/wallet_view.dart b/lib/pages/wallet_view/wallet_view.dart index eaea818e9..8d12df5a6 100644 --- a/lib/pages/wallet_view/wallet_view.dart +++ b/lib/pages/wallet_view/wallet_view.dart @@ -44,6 +44,7 @@ import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart'; import 'package:stackwallet/utilities/enums/wallet_balance_toggle_state.dart'; import 'package:stackwallet/utilities/logger.dart'; +import 'package:stackwallet/utilities/show_loading.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/widgets/background.dart'; @@ -260,11 +261,6 @@ class _WalletViewState extends ConsumerState { void _onExchangePressed(BuildContext context) async { final coin = ref.read(managerProvider).coin; - final currency = ExchangeDataLoadingService.instance.isar.currencies - .where() - .tickerEqualToAnyExchangeNameName(coin.ticker) - .findFirstSync(); - if (coin.isTestNet) { await showDialog( context: context, @@ -273,6 +269,15 @@ class _WalletViewState extends ConsumerState { ), ); } else { + final currency = await showLoading( + whileFuture: ExchangeDataLoadingService.instance.isar.currencies + .where() + .tickerEqualToAnyExchangeNameName(coin.ticker) + .findFirst(), + context: context, + message: "Loading...", + ); + if (mounted) { unawaited( Navigator.of(context).pushNamed( diff --git a/lib/utilities/show_loading.dart b/lib/utilities/show_loading.dart new file mode 100644 index 000000000..9e48f7800 --- /dev/null +++ b/lib/utilities/show_loading.dart @@ -0,0 +1,42 @@ +import 'dart:async'; + +import 'package:flutter/material.dart'; +import 'package:stackwallet/utilities/theme/stack_colors.dart'; +import 'package:stackwallet/widgets/custom_loading_overlay.dart'; + +Future showLoading({ + required Future whileFuture, + required BuildContext context, + required String message, + String? subMessage, + bool isDesktop = false, +}) async { + unawaited( + showDialog( + context: context, + barrierDismissible: false, + builder: (_) => WillPopScope( + onWillPop: () async => false, + child: Container( + color: Theme.of(context) + .extension()! + .overlay + .withOpacity(0.6), + child: CustomLoadingOverlay( + message: message, + subMessage: subMessage, + eventBus: null, + ), + ), + ), + ), + ); + + final result = await whileFuture; + + if (context.mounted) { + Navigator.of(context, rootNavigator: isDesktop).pop(); + } + + return result; +}