CAKE-221 | added fiat amount to estimated fee; reworked confirm_sending_alert.dart; applied alert when transaction was committed

OleksandrSobol committed Dec 29, 2020 at 20:48 UTC ac1709bffb1d700318984d801ad9291b1def1ab4
4 files changed +215 -144
lib/src/screens/send/send_page.dart
+52 -97
@@ -313,6 +313,7 @@ class SendPage extends BasePage {
313 child: Row(
314 mainAxisAlignment:
315 MainAxisAlignment.spaceBetween,
316 + crossAxisAlignment: CrossAxisAlignment.start,
317 children: <Widget>[
318 Text(
319 S
@@ -326,23 +327,50 @@ class SendPage extends BasePage {
327 color: Colors.white)),
328 Container(
329 child: Row(
330 + crossAxisAlignment: CrossAxisAlignment.start,
331 children: <Widget>[
330 - Text(
331 - sendViewModel
332 + Column(
333 + mainAxisAlignment: MainAxisAlignment.start,
334 + crossAxisAlignment: CrossAxisAlignment.end,
335 + children: [
336 + Text(
337 + sendViewModel
338 .estimatedFee
339 .toString() +
334 - ' ' +
335 - sendViewModel
340 + ' ' +
341 + sendViewModel
342 .currency.title,
337 - style: TextStyle(
338 - fontSize: 12,
339 - fontWeight:
343 + style: TextStyle(
344 + fontSize: 12,
345 + fontWeight:
346 FontWeight.w600,
341 - //color: Theme.of(context).primaryTextTheme.display2.color,
342 - color:
347 + //color: Theme.of(context).primaryTextTheme.display2.color,
348 + color:
349 Colors.white)),
350 + Padding(
351 + padding:
352 + EdgeInsets.only(top: 5),
353 + child: Text(
354 + sendViewModel
355 + .estimatedFeeFiatAmount
356 + + ' ' +
357 + sendViewModel
358 + .fiat.title,
359 + style: TextStyle(
360 + fontSize: 12,
361 + fontWeight:
362 + FontWeight.w600,
363 + color: Theme
364 + .of(context)
365 + .primaryTextTheme
366 + .headline
367 + .decorationColor))
368 + ),
369 + ],
370 + ),
371 Padding(
372 padding: EdgeInsets.only(
373 + top: 2,
374 left: 5),
375 child: Icon(
376 Icons.arrow_forward_ios,
@@ -596,8 +624,14 @@ class SendPage extends BasePage {
624 amount: S.of(context).send_amount,
625 amountValue:
626 sendViewModel.pendingTransaction.amountFormatted,
627 + fiatAmountValue: sendViewModel.pendingTransactionFiatAmount
628 + + ' ' + sendViewModel.fiat.title,
629 fee: S.of(context).send_fee,
630 feeValue: sendViewModel.pendingTransaction.feeFormatted,
631 + transactionPriority: sendViewModel
632 + .transactionPriority.toString(),
633 + recipientTitle: 'Recipient address',
634 + recipientAddress: sendViewModel.address,
635 rightButtonText: S.of(context).ok,
636 leftButtonText: S.of(context).cancel,
637 actionRightButton: () {
@@ -614,96 +648,17 @@ class SendPage extends BasePage {
648 }
649
650 if (state is TransactionCommitted) {
617 - return Stack(
618 - children: <Widget>[
619 - Container(
620 - color: Theme.of(context).backgroundColor,
621 - child: Center(
622 - child: Image.asset(
623 - 'assets/images/birthday_cake.png'),
624 - ),
625 - ),
626 - Center(
627 - child: Padding(
628 - padding: EdgeInsets.only(
629 - top: 220, left: 24, right: 24),
630 - child: Text(
631 - S.of(context).send_success(
632 - sendViewModel.currency
633 - .toString()),
634 - textAlign: TextAlign.center,
635 - style: TextStyle(
636 - fontSize: 22,
637 - fontWeight: FontWeight.bold,
638 - color: Theme.of(context)
639 - .primaryTextTheme
640 - .title
641 - .color,
642 - decoration: TextDecoration.none,
643 - ),
644 - ),
645 - ),
646 - ),
647 - Positioned(
648 - left: 24,
649 - right: 24,
650 - bottom: 24,
651 - child: PrimaryButton(
652 - onPressed: () =>
653 - Navigator.of(context).pop(),
654 - text: S.of(context).send_got_it,
655 - color: Theme.of(context)
656 - .accentTextTheme
657 - .body2
658 - .color,
659 - textColor: Colors.white))
660 - ],
661 - );
662 - }
663 -
664 - if (state is TransactionCommitting) {
665 - return Stack(
666 - children: <Widget>[
667 - Container(
668 - color: Theme.of(context).backgroundColor,
669 - child: Center(
670 - child: Image.asset(
671 - 'assets/images/birthday_cake.png'),
672 - ),
673 - ),
674 - BackdropFilter(
675 - filter: ImageFilter.blur(
676 - sigmaX: 3.0, sigmaY: 3.0),
677 - child: Container(
678 - decoration: BoxDecoration(
679 - color: Theme.of(context)
680 - .backgroundColor
681 - .withOpacity(0.25)),
682 - child: Center(
683 - child: Padding(
684 - padding: EdgeInsets.only(top: 220),
685 - child: Text(
686 - S.of(context).send_sending,
687 - textAlign: TextAlign.center,
688 - style: TextStyle(
689 - fontSize: 22,
690 - fontWeight: FontWeight.bold,
691 - color: Theme.of(context)
692 - .primaryTextTheme
693 - .title
694 - .color,
695 - decoration: TextDecoration.none,
696 - ),
697 - ),
698 - ),
699 - ),
700 - ),
701 - )
702 - ],
703 - );
651 + return AlertWithOneAction(
652 + alertTitle: '',
653 + alertContent: S.of(context).send_success(
654 + sendViewModel.currency
655 + .toString()),
656 + buttonText: S.of(context).ok,
657 + buttonAction: () =>
658 + Navigator.of(context).pop());
659 }
660
706 - return Container();
661 + return Offstage();
662 });
663 });
664 },
lib/src/screens/send/widgets/confirm_sending_alert.dart
+115 -35
@@ -1,3 +1,4 @@
1 +import 'package:cake_wallet/palette.dart';
2 import 'package:flutter/material.dart';
3 import 'package:cake_wallet/src/widgets/base_alert_dialog.dart';
4
@@ -6,8 +7,12 @@ class ConfirmSendingAlert extends BaseAlertDialog {
7 @required this.alertTitle,
8 @required this.amount,
9 @required this.amountValue,
10 + @required this.fiatAmountValue,
11 @required this.fee,
12 @required this.feeValue,
13 + @required this.transactionPriority,
14 + @required this.recipientTitle,
15 + @required this.recipientAddress,
16 @required this.leftButtonText,
17 @required this.rightButtonText,
18 @required this.actionLeftButton,
@@ -18,8 +23,12 @@ class ConfirmSendingAlert extends BaseAlertDialog {
23 final String alertTitle;
24 final String amount;
25 final String amountValue;
26 + final String fiatAmountValue;
27 final String fee;
28 final String feeValue;
29 + final String transactionPriority;
30 + final String recipientTitle;
31 + final String recipientAddress;
32 final String leftButtonText;
33 final String rightButtonText;
34 final VoidCallback actionLeftButton;
@@ -29,74 +38,145 @@ class ConfirmSendingAlert extends BaseAlertDialog {
38 @override
39 String get titleText => alertTitle;
40
41 + @override
42 + bool get isDividerExists => true;
43 +
44 @override
45 String get leftActionButtonText => leftButtonText;
46 +
47 @override
48 String get rightActionButtonText => rightButtonText;
49 +
50 @override
51 VoidCallback get actionLeft => actionLeftButton;
52 +
53 @override
54 VoidCallback get actionRight => actionRightButton;
55 +
56 @override
57 bool get barrierDismissible => alertBarrierDismissible;
58
59 @override
60 Widget content(BuildContext context) {
61 return Column(
46 - mainAxisSize: MainAxisSize.max,
47 - mainAxisAlignment: MainAxisAlignment.spaceBetween,
62 children: <Widget>[
63 Row(
64 mainAxisSize: MainAxisSize.max,
65 mainAxisAlignment: MainAxisAlignment.spaceBetween,
66 + crossAxisAlignment: CrossAxisAlignment.start,
67 children: <Widget>[
68 Text(
69 amount,
70 style: TextStyle(
71 fontSize: 16,
57 - fontWeight: FontWeight.w600,
72 + fontWeight: FontWeight.normal,
73 fontFamily: 'Lato',
74 color: Theme.of(context).primaryTextTheme.title.color,
75 decoration: TextDecoration.none,
76 ),
77 ),
63 - Text(
64 - amountValue,
65 - style: TextStyle(
66 - fontSize: 16,
67 - fontWeight: FontWeight.w600,
68 - fontFamily: 'Lato',
69 - color: Theme.of(context).primaryTextTheme.title.color,
70 - decoration: TextDecoration.none,
71 - ),
78 + Column(
79 + crossAxisAlignment: CrossAxisAlignment.end,
80 + children: [
81 + Text(
82 + amountValue,
83 + style: TextStyle(
84 + fontSize: 18,
85 + fontWeight: FontWeight.w600,
86 + fontFamily: 'Lato',
87 + color: Theme.of(context).primaryTextTheme.title.color,
88 + decoration: TextDecoration.none,
89 + ),
90 + ),
91 + Text(
92 + fiatAmountValue,
93 + style: TextStyle(
94 + fontSize: 12,
95 + fontWeight: FontWeight.w600,
96 + fontFamily: 'Lato',
97 + color: PaletteDark.pigeonBlue,
98 + decoration: TextDecoration.none,
99 + ),
100 + )
101 + ],
102 )
103 ],
104 ),
75 - Row(
76 - mainAxisSize: MainAxisSize.max,
77 - mainAxisAlignment: MainAxisAlignment.spaceBetween,
78 - children: <Widget>[
79 - Text(
80 - fee,
81 - style: TextStyle(
82 - fontSize: 16,
83 - fontWeight: FontWeight.w600,
84 - fontFamily: 'Lato',
85 - color: Theme.of(context).primaryTextTheme.title.color,
86 - decoration: TextDecoration.none,
105 + Padding(
106 + padding: EdgeInsets.only(top: 16),
107 + child: Row(
108 + mainAxisSize: MainAxisSize.max,
109 + mainAxisAlignment: MainAxisAlignment.spaceBetween,
110 + crossAxisAlignment: CrossAxisAlignment.start,
111 + children: <Widget>[
112 + Text(
113 + fee,
114 + style: TextStyle(
115 + fontSize: 16,
116 + fontWeight: FontWeight.normal,
117 + fontFamily: 'Lato',
118 + color: Theme.of(context).primaryTextTheme.title.color,
119 + decoration: TextDecoration.none,
120 + ),
121 ),
88 - ),
89 - Text(
90 - feeValue,
91 - style: TextStyle(
92 - fontSize: 16,
93 - fontWeight: FontWeight.w600,
94 - fontFamily: 'Lato',
95 - color: Theme.of(context).primaryTextTheme.title.color,
96 - decoration: TextDecoration.none,
122 + Column(
123 + crossAxisAlignment: CrossAxisAlignment.end,
124 + children: [
125 + Text(
126 + feeValue,
127 + style: TextStyle(
128 + fontSize: 18,
129 + fontWeight: FontWeight.w600,
130 + fontFamily: 'Lato',
131 + color: Theme.of(context).primaryTextTheme.title.color,
132 + decoration: TextDecoration.none,
133 + ),
134 + ),
135 + Text(
136 + transactionPriority,
137 + style: TextStyle(
138 + fontSize: 12,
139 + fontWeight: FontWeight.w600,
140 + fontFamily: 'Lato',
141 + color: PaletteDark.pigeonBlue,
142 + decoration: TextDecoration.none,
143 + ),
144 + )
145 + ],
146 + )
147 + ],
148 + )
149 + ),
150 + Padding(
151 + padding: EdgeInsets.fromLTRB(8, 16, 8, 0),
152 + child: Column(
153 + crossAxisAlignment: CrossAxisAlignment.center,
154 + children: [
155 + Text(
156 + recipientTitle,
157 + style: TextStyle(
158 + fontSize: 16,
159 + fontWeight: FontWeight.normal,
160 + fontFamily: 'Lato',
161 + color: Theme.of(context).primaryTextTheme.title.color,
162 + decoration: TextDecoration.none,
163 + ),
164 ),
98 - )
99 - ],
165 + Padding(
166 + padding: EdgeInsets.only(top: 8),
167 + child: Text(
168 + recipientAddress,
169 + style: TextStyle(
170 + fontSize: 12,
171 + fontWeight: FontWeight.w600,
172 + fontFamily: 'Lato',
173 + color: PaletteDark.pigeonBlue,
174 + decoration: TextDecoration.none,
175 + ),
176 + )
177 + )
178 + ],
179 + ),
180 )
181 ],
182 );
lib/src/widgets/base_alert_dialog.dart
+19 -12
@@ -7,6 +7,7 @@ class BaseAlertDialog extends StatelessWidget {
7 String get contentText => '';
8 String get leftActionButtonText => '';
9 String get rightActionButtonText => '';
10 + bool get isDividerExists => false;
11 VoidCallback get actionLeft => () {};
12 VoidCallback get actionRight => () {};
13 bool get barrierDismissible => true;
@@ -127,18 +128,24 @@ class BaseAlertDialog extends StatelessWidget {
128 child: Column(
129 mainAxisSize: MainAxisSize.min,
130 children: <Widget>[
130 - Container(
131 - padding: EdgeInsets.fromLTRB(24, 32, 24, 32),
132 - child: Column(
133 - crossAxisAlignment: CrossAxisAlignment.center,
134 - children: <Widget>[
135 - title(context),
136 - Padding(
137 - padding: EdgeInsets.only(top: 8),
138 - child: content(context),
139 - )
140 - ],
141 - ),
131 + Column(
132 + crossAxisAlignment: CrossAxisAlignment.center,
133 + children: <Widget>[
134 + Padding(
135 + padding: EdgeInsets.fromLTRB(24, 32, 24, 16),
136 + child: title(context),
137 + ),
138 + isDividerExists
139 + ? Container(
140 + height: 1,
141 + color: Theme.of(context).dividerColor,
142 + )
143 + : Offstage(),
144 + Padding(
145 + padding: EdgeInsets.fromLTRB(24, 16, 24, 32),
146 + child: content(context),
147 + )
148 + ],
149 ),
150 Container(
151 height: 1,
lib/view_model/send/send_view_model.dart
+29
@@ -1,4 +1,5 @@
1 import 'package:cake_wallet/entities/balance_display_mode.dart';
2 +import 'package:cake_wallet/entities/calculate_fiat_amount_raw.dart';
3 import 'package:cake_wallet/entities/transaction_description.dart';
4 import 'package:hive/hive.dart';
5 import 'package:intl/intl.dart';
@@ -60,6 +61,34 @@ abstract class SendViewModelBase with Store {
61 double get estimatedFee =>
62 _wallet.calculateEstimatedFee(_settingsStore.transactionPriority);
63
64 + @computed
65 + String get estimatedFeeFiatAmount {
66 + try {
67 + final fiat = calculateFiatAmountRaw(
68 + price: _fiatConversationStore.prices[_wallet.currency],
69 + cryptoAmount: estimatedFee);
70 + return fiat;
71 + } catch (_) {
72 + return '0.00';
73 + }
74 + }
75 +
76 + @computed
77 + String get pendingTransactionFiatAmount {
78 + try {
79 + if (pendingTransaction != null) {
80 + final fiat = calculateFiatAmount(
81 + price: _fiatConversationStore.prices[_wallet.currency],
82 + cryptoAmount: pendingTransaction.amountFormatted);
83 + return fiat;
84 + } else {
85 + return '0.00';
86 + }
87 + } catch (_) {
88 + return '0.00';
89 + }
90 + }
91 +
92 FiatCurrency get fiat => _settingsStore.fiatCurrency;
93
94 TransactionPriority get transactionPriority =>