add transaction success info page (#1878)
Serhii committed
Dec 14, 2024 at 01:27 UTC
9a60b0146f08a0f112b0406bafbbbb58b069e111
5 files changed
+100
-90
lib/di.dart
+4
@@ -39,6 +39,7 @@ import 'package:cake_wallet/entities/wallet_manager.dart';
39
import 'package:cake_wallet/src/screens/buy/buy_sell_options_page.dart';
40
import 'package:cake_wallet/src/screens/buy/payment_method_options_page.dart';
41
import 'package:cake_wallet/src/screens/receive/address_list_page.dart';
42
+import 'package:cake_wallet/src/screens/send/transaction_success_info_page.dart';
43
import 'package:cake_wallet/src/screens/wallet_list/wallet_list_page.dart';
44
import 'package:cake_wallet/src/screens/settings/mweb_logs_page.dart';
45
import 'package:cake_wallet/src/screens/settings/mweb_node_page.dart';
@@ -1175,6 +1176,9 @@ Future<void> setup({
1176
getIt.registerFactoryParam<PreSeedPage, int, void>(
1177
(seedPhraseLength, _) => PreSeedPage(seedPhraseLength));
1178
1179
+ getIt.registerFactoryParam<TransactionSuccessPage, String, void>(
1180
+ (content, _) => TransactionSuccessPage(content: content));
1181
+
1182
getIt.registerFactoryParam<TradeDetailsViewModel, Trade, void>((trade, _) =>
1183
TradeDetailsViewModel(
1184
tradeForDetails: trade,
lib/router.dart
+5
@@ -69,6 +69,7 @@ import 'package:cake_wallet/src/screens/seed/pre_seed_page.dart';
69
import 'package:cake_wallet/src/screens/seed/wallet_seed_page.dart';
70
import 'package:cake_wallet/src/screens/send/send_page.dart';
71
import 'package:cake_wallet/src/screens/send/send_template_page.dart';
72
+import 'package:cake_wallet/src/screens/send/transaction_success_info_page.dart';
73
import 'package:cake_wallet/src/screens/settings/connection_sync_page.dart';
74
import 'package:cake_wallet/src/screens/settings/desktop_settings/desktop_settings_page.dart';
75
import 'package:cake_wallet/src/screens/settings/display_settings_page.dart';
@@ -585,6 +586,10 @@ Route<dynamic> createRoute(RouteSettings settings) {
586
return MaterialPageRoute<void>(
587
builder: (_) => getIt.get<PreSeedPage>(param1: settings.arguments as int));
588
589
+ case Routes.transactionSuccessPage:
590
+ return MaterialPageRoute<void>(
591
+ builder: (_) => getIt.get<TransactionSuccessPage>(param1: settings.arguments as String));
592
+
593
case Routes.backup:
594
return CupertinoPageRoute<void>(
595
fullscreenDialog: true, builder: (_) => getIt.get<BackupPage>());
lib/routes.dart
+1
@@ -53,6 +53,7 @@ class Routes {
53
static const restoreWalletType = '/restore_wallet_type';
54
static const restoreWallet = '/restore_wallet';
55
static const preSeedPage = '/pre_seed_page';
56
+ static const transactionSuccessPage = '/transaction_success_info_page';
57
static const backup = '/backup';
58
static const editBackupPassword = '/edit_backup_passowrd';
59
static const restoreFromBackup = '/restore_from_backup';
lib/src/screens/send/send_page.dart
+58
-90
@@ -500,95 +500,6 @@ class SendPage extends BasePage {
500
actionRightButton: () async {
501
Navigator.of(_dialogContext).pop();
502
sendViewModel.commitTransaction(context);
503
- await showPopUp<void>(
504
- context: context,
505
- builder: (BuildContext _dialogContext) {
506
- return Observer(builder: (_) {
507
- final state = sendViewModel.state;
508
-
509
- if (state is FailureState) {
510
- Navigator.of(_dialogContext).pop();
511
- }
512
-
513
- if (state is TransactionCommitted) {
514
- newContactAddress =
515
- newContactAddress ?? sendViewModel.newContactAddress();
516
-
517
- if (sendViewModel.coinTypeToSpendFrom != UnspentCoinType.any) {
518
- newContactAddress = null;
519
- }
520
-
521
- final successMessage = S.of(_dialogContext).send_success(
522
- sendViewModel.selectedCryptoCurrency.toString());
523
-
524
- final waitMessage = sendViewModel.walletType == WalletType.solana
525
- ? '. ${S.of(_dialogContext).waitFewSecondForTxUpdate}'
526
- : '';
527
-
528
- final newContactMessage = newContactAddress != null && sendViewModel.showAddressBookPopup
529
- ? '\n${S.of(_dialogContext).add_contact_to_address_book}'
530
- : '';
531
-
532
- String alertContent =
533
- "$successMessage$waitMessage$newContactMessage";
534
-
535
- if (newContactMessage.isNotEmpty) {
536
- return AlertWithTwoActions(
537
- alertDialogKey: ValueKey('send_page_sent_dialog_key'),
538
- alertTitle: '',
539
- alertContent: alertContent,
540
- rightButtonText: S.of(_dialogContext).add_contact,
541
- leftButtonText: S.of(_dialogContext).ignor,
542
- alertLeftActionButtonKey:
543
- ValueKey('send_page_sent_dialog_ignore_button_key'),
544
- alertRightActionButtonKey: ValueKey(
545
- 'send_page_sent_dialog_add_contact_button_key'),
546
- actionRightButton: () {
547
- Navigator.of(_dialogContext).pop();
548
- RequestReviewHandler.requestReview();
549
- Navigator.of(context).pushNamed(
550
- Routes.addressBookAddContact,
551
- arguments: newContactAddress);
552
- newContactAddress = null;
553
- },
554
- actionLeftButton: () {
555
- Navigator.of(_dialogContext).pop();
556
- RequestReviewHandler.requestReview();
557
- newContactAddress = null;
558
- });
559
- } else {
560
- if (initialPaymentRequest?.callbackMessage?.isNotEmpty ??
561
- false) {
562
- alertContent = initialPaymentRequest!.callbackMessage!;
563
- }
564
- return AlertWithOneAction(
565
- alertTitle: '',
566
- alertContent: alertContent,
567
- buttonText: S.of(_dialogContext).ok,
568
- buttonAction: () {
569
- Navigator.of(_dialogContext).pop();
570
- RequestReviewHandler.requestReview();
571
- });
572
- }
573
- }
574
-
575
- return Offstage();
576
- });
577
- });
578
- if (state is TransactionCommitted) {
579
- if (initialPaymentRequest?.callbackUrl?.isNotEmpty ?? false) {
580
- // wait a second so it's not as jarring:
581
- await Future.delayed(Duration(seconds: 1));
582
- try {
583
- launchUrl(
584
- Uri.parse(initialPaymentRequest!.callbackUrl!),
585
- mode: LaunchMode.externalApplication,
586
- );
587
- } catch (e) {
588
- printV(e);
589
- }
590
- }
591
- }
503
},
504
actionLeftButton: () => Navigator.of(_dialogContext).pop());
505
});
@@ -597,7 +508,64 @@ class SendPage extends BasePage {
508
}
509
510
if (state is TransactionCommitted) {
600
- WidgetsBinding.instance.addPostFrameCallback((_) {
511
+ WidgetsBinding.instance.addPostFrameCallback((_) async {
512
+
513
+ final successMessage = S.of(context).send_success(
514
+ sendViewModel.selectedCryptoCurrency.toString());
515
+
516
+ final waitMessage = sendViewModel.walletType == WalletType.solana
517
+ ? '. ${S.of(context).waitFewSecondForTxUpdate}'
518
+ : '';
519
+
520
+ String alertContent = "$successMessage$waitMessage";
521
+
522
+ await Navigator.of(context).pushNamed(
523
+ Routes.transactionSuccessPage,
524
+ arguments: alertContent
525
+ );
526
+
527
+ newContactAddress = newContactAddress ?? sendViewModel.newContactAddress();
528
+ if (sendViewModel.coinTypeToSpendFrom != UnspentCoinType.any) newContactAddress = null;
529
+
530
+ if (newContactAddress != null && sendViewModel.showAddressBookPopup) {
531
+ await showPopUp<void>(
532
+ context: context,
533
+ builder: (BuildContext _dialogContext) => AlertWithTwoActions(
534
+ alertDialogKey: ValueKey('send_page_sent_dialog_key'),
535
+ alertTitle: '',
536
+ alertContent: S.of(_dialogContext).add_contact_to_address_book,
537
+ rightButtonText: S.of(_dialogContext).add_contact,
538
+ leftButtonText: S.of(_dialogContext).ignor,
539
+ alertLeftActionButtonKey: ValueKey('send_page_sent_dialog_ignore_button_key'),
540
+ alertRightActionButtonKey:
541
+ ValueKey('send_page_sent_dialog_add_contact_button_key'),
542
+ actionRightButton: () {
543
+ Navigator.of(_dialogContext).pop();
544
+ RequestReviewHandler.requestReview();
545
+ Navigator.of(context)
546
+ .pushNamed(Routes.addressBookAddContact, arguments: newContactAddress);
547
+ newContactAddress = null;
548
+ },
549
+ actionLeftButton: () {
550
+ Navigator.of(_dialogContext).pop();
551
+ RequestReviewHandler.requestReview();
552
+ newContactAddress = null;
553
+ }));
554
+ }
555
+
556
+ if (initialPaymentRequest?.callbackUrl?.isNotEmpty ?? false) {
557
+ // wait a second so it's not as jarring:
558
+ await Future.delayed(Duration(seconds: 1));
559
+ try {
560
+ launchUrl(
561
+ Uri.parse(initialPaymentRequest!.callbackUrl!),
562
+ mode: LaunchMode.externalApplication,
563
+ );
564
+ } catch (e) {
565
+ printV(e);
566
+ }
567
+ }
568
+
569
sendViewModel.clearOutputs();
570
});
571
}
lib/src/screens/send/transaction_success_info_page.dart
new
+32
@@ -0,0 +1,32 @@
1
+import 'package:cake_wallet/generated/i18n.dart';
2
+import 'package:cake_wallet/src/screens/Info_page.dart';
3
+import 'package:flutter/cupertino.dart';
4
+
5
+class TransactionSuccessPage extends InfoPage {
6
+ TransactionSuccessPage({required this.content})
7
+ : super(
8
+ imageLightPath: 'assets/images/birthday_cake.png',
9
+ imageDarkPath: 'assets/images/birthday_cake.png',
10
+ );
11
+
12
+ final String content;
13
+
14
+ @override
15
+ bool get onWillPop => false;
16
+
17
+ @override
18
+ String get pageTitle => 'Transaction Sent Successfully';
19
+
20
+ @override
21
+ String get pageDescription => content;
22
+
23
+ @override
24
+ String get buttonText => S.current.ok;
25
+
26
+ @override
27
+ Key? get buttonKey => ValueKey('transaction_success_info_page_button_key');
28
+
29
+ @override
30
+ void Function(BuildContext) get onPressed =>
31
+ (BuildContext context) => Navigator.of(context).pop();
32
+}