diff --git a/lib/models/exchange/exchange_form_state.dart b/lib/models/exchange/estimated_rate_exchange_form_state.dart similarity index 100% rename from lib/models/exchange/exchange_form_state.dart rename to lib/models/exchange/estimated_rate_exchange_form_state.dart diff --git a/lib/pages/send_view/confirm_transaction_view.dart b/lib/pages/send_view/confirm_transaction_view.dart index 82422ab3c..86da5452e 100644 --- a/lib/pages/send_view/confirm_transaction_view.dart +++ b/lib/pages/send_view/confirm_transaction_view.dart @@ -1,12 +1,17 @@ +import 'dart:async'; + import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:stackwallet/notifications/show_flush_bar.dart'; import 'package:stackwallet/pages/pinpad_views/lock_screen_view.dart'; import 'package:stackwallet/pages/send_view/sub_widgets/sending_transaction_dialog.dart'; import 'package:stackwallet/pages/wallet_view/wallet_view.dart'; import 'package:stackwallet/providers/providers.dart'; import 'package:stackwallet/route_generator.dart'; +import 'package:stackwallet/services/coins/epiccash/epiccash_wallet.dart'; import 'package:stackwallet/utilities/cfcolors.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; +import 'package:stackwallet/utilities/enums/flush_bar_type.dart'; import 'package:stackwallet/utilities/format.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; @@ -40,14 +45,14 @@ class _ConfirmTransactionViewState late final String routeOnSuccessName; Future _attemptSend(BuildContext context) async { - showDialog( + unawaited(showDialog( context: context, useSafeArea: false, barrierDismissible: false, builder: (context) { return const SendingTransactionDialog(); }, - ); + )); final note = transactionInfo["note"] as String? ?? ""; final manager = @@ -55,10 +60,10 @@ class _ConfirmTransactionViewState try { final txid = await manager.confirmSend(txData: transactionInfo); - manager.refresh(); + unawaited(manager.refresh()); // save note - ref + await ref .read(notesServiceChangeNotifierProvider(walletId)) .editOrAddNote(txid: txid, note: note); @@ -66,12 +71,26 @@ class _ConfirmTransactionViewState if (mounted) { Navigator.of(context).popUntil(ModalRoute.withName(routeOnSuccessName)); } + } on BadEpicHttpAddressException catch (_) { + if (mounted) { + // pop building dialog + Navigator.of(context).pop(); + unawaited( + showFloatingFlushBar( + type: FlushBarType.warning, + message: + "Connection failed. Please check the address and try again.", + context: context, + ), + ); + return; + } } catch (e, s) { debugPrint("$e\n$s"); // pop sending dialog Navigator.of(context).pop(); - showDialog( + await showDialog( context: context, useSafeArea: false, barrierDismissible: true, @@ -316,7 +335,7 @@ class _ConfirmTransactionViewState ); if (unlocked is bool && unlocked && mounted) { - _attemptSend(context); + unawaited(_attemptSend(context)); } }, child: Text( diff --git a/lib/pages/send_view/send_view.dart b/lib/pages/send_view/send_view.dart index 89a3b7c7b..191f12a15 100644 --- a/lib/pages/send_view/send_view.dart +++ b/lib/pages/send_view/send_view.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:decimal/decimal.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -1175,7 +1177,7 @@ class _SendViewState extends ConsumerState { try { bool wasCancelled = false; - showDialog( + unawaited(showDialog( context: context, useSafeArea: false, barrierDismissible: false, @@ -1188,7 +1190,7 @@ class _SendViewState extends ConsumerState { }, ); }, - ); + )); final txData = await manager.prepareSend( address: _address!, @@ -1205,7 +1207,7 @@ class _SendViewState extends ConsumerState { txData["note"] = noteController.text; txData["address"] = _address; - Navigator.of(context).push( + unawaited(Navigator.of(context).push( RouteGenerator.getRoute( shouldUseMaterialRoute: RouteGenerator .useMaterialPageRoute, @@ -1219,14 +1221,14 @@ class _SendViewState extends ConsumerState { .routeName, ), ), - ); + )); } } catch (e) { if (mounted) { // pop building dialog Navigator.of(context).pop(); - showDialog( + unawaited(showDialog( context: context, useSafeArea: false, barrierDismissible: true, @@ -1258,7 +1260,7 @@ class _SendViewState extends ConsumerState { ), ); }, - ); + )); } } } diff --git a/lib/providers/exchange/estimate_rate_exchange_form_provider.dart b/lib/providers/exchange/estimate_rate_exchange_form_provider.dart index e6f0a92b2..9a59cb734 100644 --- a/lib/providers/exchange/estimate_rate_exchange_form_provider.dart +++ b/lib/providers/exchange/estimate_rate_exchange_form_provider.dart @@ -1,5 +1,5 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:stackwallet/models/exchange/exchange_form_state.dart'; +import 'package:stackwallet/models/exchange/estimated_rate_exchange_form_state.dart'; final estimatedRateExchangeFormProvider = ChangeNotifierProvider((ref) => EstimatedRateExchangeFormState()); diff --git a/lib/services/coins/epiccash/epiccash_wallet.dart b/lib/services/coins/epiccash/epiccash_wallet.dart index 64f775c49..a6a69df66 100644 --- a/lib/services/coins/epiccash/epiccash_wallet.dart +++ b/lib/services/coins/epiccash/epiccash_wallet.dart @@ -39,6 +39,17 @@ const int MINIMUM_CONFIRMATIONS = 10; const String GENESIS_HASH_MAINNET = ""; const String GENESIS_HASH_TESTNET = ""; +class BadEpicHttpAddressException implements Exception { + final String? message; + + BadEpicHttpAddressException({this.message}); + + @override + String toString() { + return "BadEpicHttpAddressException: $message"; + } +} + // isolate Map isolates = {}; @@ -754,6 +765,10 @@ class EpicCashWallet extends CoinServiceAPI { }, name: walletName); message = await receivePort.first; + + // TODO: throw BadEpicHttpAddressException in the case where a send fails due to bad http address + // throw BadEpicHttpAddressException(); + if (message is String) { Logging.instance .log("this is a string $message", level: LogLevel.Error); @@ -2235,6 +2250,12 @@ class EpicCashWallet extends CoinServiceAPI { @override bool validateAddress(String address) { + if (address.startsWith("http://") || address.startsWith("https://")) { + if (Uri.tryParse(address) != null) { + return true; + } + } + String validate = validateSendAddress(address); if (int.parse(validate) == 1) { return true;