From 1f8db52fe0c1169f8ec141431f1b1b72fffac769 Mon Sep 17 00:00:00 2001 From: Serhii Date: Fri, 13 Dec 2024 21:38:31 +0200 Subject: [PATCH] add transaction success info page --- lib/di.dart | 4 + lib/router.dart | 5 + lib/routes.dart | 1 + lib/src/screens/send/send_page.dart | 148 +++++++----------- .../send/transaction_success_info_page.dart | 32 ++++ 5 files changed, 100 insertions(+), 90 deletions(-) create mode 100644 lib/src/screens/send/transaction_success_info_page.dart diff --git a/lib/di.dart b/lib/di.dart index 6531c411f8..693df0ed3a 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -39,6 +39,7 @@ import 'package:cake_wallet/entities/wallet_manager.dart'; import 'package:cake_wallet/src/screens/buy/buy_sell_options_page.dart'; import 'package:cake_wallet/src/screens/buy/payment_method_options_page.dart'; import 'package:cake_wallet/src/screens/receive/address_list_page.dart'; +import 'package:cake_wallet/src/screens/send/transaction_success_info_page.dart'; import 'package:cake_wallet/src/screens/wallet_list/wallet_list_page.dart'; import 'package:cake_wallet/src/screens/settings/mweb_logs_page.dart'; import 'package:cake_wallet/src/screens/settings/mweb_node_page.dart'; @@ -1175,6 +1176,9 @@ Future setup({ getIt.registerFactoryParam( (seedPhraseLength, _) => PreSeedPage(seedPhraseLength)); + getIt.registerFactoryParam( + (content, _) => TransactionSuccessPage(content: content)); + getIt.registerFactoryParam((trade, _) => TradeDetailsViewModel( tradeForDetails: trade, diff --git a/lib/router.dart b/lib/router.dart index a64369b32a..faba5fd523 100644 --- a/lib/router.dart +++ b/lib/router.dart @@ -69,6 +69,7 @@ import 'package:cake_wallet/src/screens/seed/pre_seed_page.dart'; import 'package:cake_wallet/src/screens/seed/wallet_seed_page.dart'; import 'package:cake_wallet/src/screens/send/send_page.dart'; import 'package:cake_wallet/src/screens/send/send_template_page.dart'; +import 'package:cake_wallet/src/screens/send/transaction_success_info_page.dart'; import 'package:cake_wallet/src/screens/settings/connection_sync_page.dart'; import 'package:cake_wallet/src/screens/settings/desktop_settings/desktop_settings_page.dart'; import 'package:cake_wallet/src/screens/settings/display_settings_page.dart'; @@ -585,6 +586,10 @@ Route createRoute(RouteSettings settings) { return MaterialPageRoute( builder: (_) => getIt.get(param1: settings.arguments as int)); + case Routes.transactionSuccessPage: + return MaterialPageRoute( + builder: (_) => getIt.get(param1: settings.arguments as String)); + case Routes.backup: return CupertinoPageRoute( fullscreenDialog: true, builder: (_) => getIt.get()); diff --git a/lib/routes.dart b/lib/routes.dart index bea118ae0a..c8eb63c268 100644 --- a/lib/routes.dart +++ b/lib/routes.dart @@ -53,6 +53,7 @@ class Routes { static const restoreWalletType = '/restore_wallet_type'; static const restoreWallet = '/restore_wallet'; static const preSeedPage = '/pre_seed_page'; + static const transactionSuccessPage = '/transaction_success_info_page'; static const backup = '/backup'; static const editBackupPassword = '/edit_backup_passowrd'; static const restoreFromBackup = '/restore_from_backup'; diff --git a/lib/src/screens/send/send_page.dart b/lib/src/screens/send/send_page.dart index 4b1227751a..ddf2d7c89b 100644 --- a/lib/src/screens/send/send_page.dart +++ b/lib/src/screens/send/send_page.dart @@ -500,95 +500,6 @@ class SendPage extends BasePage { actionRightButton: () async { Navigator.of(_dialogContext).pop(); sendViewModel.commitTransaction(context); - await showPopUp( - context: context, - builder: (BuildContext _dialogContext) { - return Observer(builder: (_) { - final state = sendViewModel.state; - - if (state is FailureState) { - Navigator.of(_dialogContext).pop(); - } - - if (state is TransactionCommitted) { - newContactAddress = - newContactAddress ?? sendViewModel.newContactAddress(); - - if (sendViewModel.coinTypeToSpendFrom != UnspentCoinType.any) { - newContactAddress = null; - } - - final successMessage = S.of(_dialogContext).send_success( - sendViewModel.selectedCryptoCurrency.toString()); - - final waitMessage = sendViewModel.walletType == WalletType.solana - ? '. ${S.of(_dialogContext).waitFewSecondForTxUpdate}' - : ''; - - final newContactMessage = newContactAddress != null && sendViewModel.showAddressBookPopup - ? '\n${S.of(_dialogContext).add_contact_to_address_book}' - : ''; - - String alertContent = - "$successMessage$waitMessage$newContactMessage"; - - if (newContactMessage.isNotEmpty) { - return AlertWithTwoActions( - alertDialogKey: ValueKey('send_page_sent_dialog_key'), - alertTitle: '', - alertContent: alertContent, - rightButtonText: S.of(_dialogContext).add_contact, - leftButtonText: S.of(_dialogContext).ignor, - alertLeftActionButtonKey: - ValueKey('send_page_sent_dialog_ignore_button_key'), - alertRightActionButtonKey: ValueKey( - 'send_page_sent_dialog_add_contact_button_key'), - actionRightButton: () { - Navigator.of(_dialogContext).pop(); - RequestReviewHandler.requestReview(); - Navigator.of(context).pushNamed( - Routes.addressBookAddContact, - arguments: newContactAddress); - newContactAddress = null; - }, - actionLeftButton: () { - Navigator.of(_dialogContext).pop(); - RequestReviewHandler.requestReview(); - newContactAddress = null; - }); - } else { - if (initialPaymentRequest?.callbackMessage?.isNotEmpty ?? - false) { - alertContent = initialPaymentRequest!.callbackMessage!; - } - return AlertWithOneAction( - alertTitle: '', - alertContent: alertContent, - buttonText: S.of(_dialogContext).ok, - buttonAction: () { - Navigator.of(_dialogContext).pop(); - RequestReviewHandler.requestReview(); - }); - } - } - - return Offstage(); - }); - }); - if (state is TransactionCommitted) { - if (initialPaymentRequest?.callbackUrl?.isNotEmpty ?? false) { - // wait a second so it's not as jarring: - await Future.delayed(Duration(seconds: 1)); - try { - launchUrl( - Uri.parse(initialPaymentRequest!.callbackUrl!), - mode: LaunchMode.externalApplication, - ); - } catch (e) { - printV(e); - } - } - } }, actionLeftButton: () => Navigator.of(_dialogContext).pop()); }); @@ -597,7 +508,64 @@ class SendPage extends BasePage { } if (state is TransactionCommitted) { - WidgetsBinding.instance.addPostFrameCallback((_) { + WidgetsBinding.instance.addPostFrameCallback((_) async { + + final successMessage = S.of(context).send_success( + sendViewModel.selectedCryptoCurrency.toString()); + + final waitMessage = sendViewModel.walletType == WalletType.solana + ? '. ${S.of(context).waitFewSecondForTxUpdate}' + : ''; + + String alertContent = "$successMessage$waitMessage"; + + await Navigator.of(context).pushNamed( + Routes.transactionSuccessPage, + arguments: alertContent + ); + + newContactAddress = newContactAddress ?? sendViewModel.newContactAddress(); + if (sendViewModel.coinTypeToSpendFrom != UnspentCoinType.any) newContactAddress = null; + + if (newContactAddress != null && sendViewModel.showAddressBookPopup) { + await showPopUp( + context: context, + builder: (BuildContext _dialogContext) => AlertWithTwoActions( + alertDialogKey: ValueKey('send_page_sent_dialog_key'), + alertTitle: '', + alertContent: S.of(_dialogContext).add_contact_to_address_book, + rightButtonText: S.of(_dialogContext).add_contact, + leftButtonText: S.of(_dialogContext).ignor, + alertLeftActionButtonKey: ValueKey('send_page_sent_dialog_ignore_button_key'), + alertRightActionButtonKey: + ValueKey('send_page_sent_dialog_add_contact_button_key'), + actionRightButton: () { + Navigator.of(_dialogContext).pop(); + RequestReviewHandler.requestReview(); + Navigator.of(context) + .pushNamed(Routes.addressBookAddContact, arguments: newContactAddress); + newContactAddress = null; + }, + actionLeftButton: () { + Navigator.of(_dialogContext).pop(); + RequestReviewHandler.requestReview(); + newContactAddress = null; + })); + } + + if (initialPaymentRequest?.callbackUrl?.isNotEmpty ?? false) { + // wait a second so it's not as jarring: + await Future.delayed(Duration(seconds: 1)); + try { + launchUrl( + Uri.parse(initialPaymentRequest!.callbackUrl!), + mode: LaunchMode.externalApplication, + ); + } catch (e) { + printV(e); + } + } + sendViewModel.clearOutputs(); }); } diff --git a/lib/src/screens/send/transaction_success_info_page.dart b/lib/src/screens/send/transaction_success_info_page.dart new file mode 100644 index 0000000000..628cc03936 --- /dev/null +++ b/lib/src/screens/send/transaction_success_info_page.dart @@ -0,0 +1,32 @@ +import 'package:cake_wallet/generated/i18n.dart'; +import 'package:cake_wallet/src/screens/Info_page.dart'; +import 'package:flutter/cupertino.dart'; + +class TransactionSuccessPage extends InfoPage { + TransactionSuccessPage({required this.content}) + : super( + imageLightPath: 'assets/images/birthday_cake.png', + imageDarkPath: 'assets/images/birthday_cake.png', + ); + + final String content; + + @override + bool get onWillPop => false; + + @override + String get pageTitle => 'Transaction Sent Successfully'; + + @override + String get pageDescription => content; + + @override + String get buttonText => S.current.ok; + + @override + Key? get buttonKey => ValueKey('transaction_success_info_page_button_key'); + + @override + void Function(BuildContext) get onPressed => + (BuildContext context) => Navigator.of(context).pop(); +}