Merge pull request #25 from cypherstack/ui-testing

UI testing
This commit is contained in:
julian-CStack 2022-09-01 10:24:05 -06:00 committed by GitHub
commit df34b6e522
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 13 deletions

View file

@ -1,12 +1,17 @@
import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.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/pinpad_views/lock_screen_view.dart';
import 'package:stackwallet/pages/send_view/sub_widgets/sending_transaction_dialog.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/pages/wallet_view/wallet_view.dart';
import 'package:stackwallet/providers/providers.dart'; import 'package:stackwallet/providers/providers.dart';
import 'package:stackwallet/route_generator.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/cfcolors.dart';
import 'package:stackwallet/utilities/enums/coin_enum.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/format.dart';
import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
@ -40,14 +45,14 @@ class _ConfirmTransactionViewState
late final String routeOnSuccessName; late final String routeOnSuccessName;
Future<void> _attemptSend(BuildContext context) async { Future<void> _attemptSend(BuildContext context) async {
showDialog<dynamic>( unawaited(showDialog<dynamic>(
context: context, context: context,
useSafeArea: false, useSafeArea: false,
barrierDismissible: false, barrierDismissible: false,
builder: (context) { builder: (context) {
return const SendingTransactionDialog(); return const SendingTransactionDialog();
}, },
); ));
final note = transactionInfo["note"] as String? ?? ""; final note = transactionInfo["note"] as String? ?? "";
final manager = final manager =
@ -55,10 +60,10 @@ class _ConfirmTransactionViewState
try { try {
final txid = await manager.confirmSend(txData: transactionInfo); final txid = await manager.confirmSend(txData: transactionInfo);
manager.refresh(); unawaited(manager.refresh());
// save note // save note
ref await ref
.read(notesServiceChangeNotifierProvider(walletId)) .read(notesServiceChangeNotifierProvider(walletId))
.editOrAddNote(txid: txid, note: note); .editOrAddNote(txid: txid, note: note);
@ -66,12 +71,26 @@ class _ConfirmTransactionViewState
if (mounted) { if (mounted) {
Navigator.of(context).popUntil(ModalRoute.withName(routeOnSuccessName)); 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) { } catch (e, s) {
debugPrint("$e\n$s"); debugPrint("$e\n$s");
// pop sending dialog // pop sending dialog
Navigator.of(context).pop(); Navigator.of(context).pop();
showDialog<void>( await showDialog<void>(
context: context, context: context,
useSafeArea: false, useSafeArea: false,
barrierDismissible: true, barrierDismissible: true,
@ -316,7 +335,7 @@ class _ConfirmTransactionViewState
); );
if (unlocked is bool && unlocked && mounted) { if (unlocked is bool && unlocked && mounted) {
_attemptSend(context); unawaited(_attemptSend(context));
} }
}, },
child: Text( child: Text(

View file

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:decimal/decimal.dart'; import 'package:decimal/decimal.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
@ -1175,7 +1177,7 @@ class _SendViewState extends ConsumerState<SendView> {
try { try {
bool wasCancelled = false; bool wasCancelled = false;
showDialog<dynamic>( unawaited(showDialog<dynamic>(
context: context, context: context,
useSafeArea: false, useSafeArea: false,
barrierDismissible: false, barrierDismissible: false,
@ -1188,7 +1190,7 @@ class _SendViewState extends ConsumerState<SendView> {
}, },
); );
}, },
); ));
final txData = await manager.prepareSend( final txData = await manager.prepareSend(
address: _address!, address: _address!,
@ -1205,7 +1207,7 @@ class _SendViewState extends ConsumerState<SendView> {
txData["note"] = noteController.text; txData["note"] = noteController.text;
txData["address"] = _address; txData["address"] = _address;
Navigator.of(context).push( unawaited(Navigator.of(context).push(
RouteGenerator.getRoute( RouteGenerator.getRoute(
shouldUseMaterialRoute: RouteGenerator shouldUseMaterialRoute: RouteGenerator
.useMaterialPageRoute, .useMaterialPageRoute,
@ -1219,14 +1221,14 @@ class _SendViewState extends ConsumerState<SendView> {
.routeName, .routeName,
), ),
), ),
); ));
} }
} catch (e) { } catch (e) {
if (mounted) { if (mounted) {
// pop building dialog // pop building dialog
Navigator.of(context).pop(); Navigator.of(context).pop();
showDialog<dynamic>( unawaited(showDialog<dynamic>(
context: context, context: context,
useSafeArea: false, useSafeArea: false,
barrierDismissible: true, barrierDismissible: true,
@ -1258,7 +1260,7 @@ class _SendViewState extends ConsumerState<SendView> {
), ),
); );
}, },
); ));
} }
} }
} }

View file

@ -1,5 +1,5 @@
import 'package:flutter_riverpod/flutter_riverpod.dart'; 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 = final estimatedRateExchangeFormProvider =
ChangeNotifierProvider((ref) => EstimatedRateExchangeFormState()); ChangeNotifierProvider((ref) => EstimatedRateExchangeFormState());

View file

@ -39,6 +39,17 @@ const int MINIMUM_CONFIRMATIONS = 10;
const String GENESIS_HASH_MAINNET = ""; const String GENESIS_HASH_MAINNET = "";
const String GENESIS_HASH_TESTNET = ""; const String GENESIS_HASH_TESTNET = "";
class BadEpicHttpAddressException implements Exception {
final String? message;
BadEpicHttpAddressException({this.message});
@override
String toString() {
return "BadEpicHttpAddressException: $message";
}
}
// isolate // isolate
Map<ReceivePort, Isolate> isolates = {}; Map<ReceivePort, Isolate> isolates = {};
@ -754,6 +765,10 @@ class EpicCashWallet extends CoinServiceAPI {
}, name: walletName); }, name: walletName);
message = await receivePort.first; 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) { if (message is String) {
Logging.instance Logging.instance
.log("this is a string $message", level: LogLevel.Error); .log("this is a string $message", level: LogLevel.Error);
@ -2235,6 +2250,12 @@ class EpicCashWallet extends CoinServiceAPI {
@override @override
bool validateAddress(String address) { bool validateAddress(String address) {
if (address.startsWith("http://") || address.startsWith("https://")) {
if (Uri.tryParse(address) != null) {
return true;
}
}
String validate = validateSendAddress(address); String validate = validateSendAddress(address);
if (int.parse(validate) == 1) { if (int.parse(validate) == 1) {
return true; return true;