From 1121949f564bb545189bf6c2fa8820c30b07a26c Mon Sep 17 00:00:00 2001 From: julian Date: Thu, 4 Jan 2024 12:52:00 -0600 Subject: [PATCH] clear send form on successful send --- .../paynym/dialogs/paynym_details_popup.dart | 3 + .../subwidgets/desktop_paynym_details.dart | 3 + .../send_view/confirm_transaction_view.dart | 4 + lib/pages/send_view/send_view.dart | 92 +++++++++++-------- lib/pages/send_view/token_send_view.dart | 66 ++++++++----- .../wallet_view/sub_widgets/desktop_send.dart | 13 +++ .../sub_widgets/desktop_token_send.dart | 13 +++ lib/route_generator.dart | 7 +- 8 files changed, 137 insertions(+), 64 deletions(-) diff --git a/lib/pages/paynym/dialogs/paynym_details_popup.dart b/lib/pages/paynym/dialogs/paynym_details_popup.dart index 6158e6ba5..f5f970d38 100644 --- a/lib/pages/paynym/dialogs/paynym_details_popup.dart +++ b/lib/pages/paynym/dialogs/paynym_details_popup.dart @@ -154,6 +154,9 @@ class _PaynymDetailsPopupState extends ConsumerState { routeOnSuccessName: PaynymHomeView.routeName, isPaynymNotificationTransaction: true, txData: preparedTx, + onSuccess: () { + // do nothing extra + }, ), ), ); diff --git a/lib/pages/paynym/subwidgets/desktop_paynym_details.dart b/lib/pages/paynym/subwidgets/desktop_paynym_details.dart index 768dbbfc8..2c31b3534 100644 --- a/lib/pages/paynym/subwidgets/desktop_paynym_details.dart +++ b/lib/pages/paynym/subwidgets/desktop_paynym_details.dart @@ -126,6 +126,9 @@ class _PaynymDetailsPopupState extends ConsumerState { walletId: widget.walletId, isPaynymNotificationTransaction: true, txData: preparedTx, + onSuccess: () { + // do nothing extra + }, onSuccessInsteadOfRouteOnSuccess: () { Navigator.of(context, rootNavigator: true).pop(); Navigator.of(context, rootNavigator: true).pop(); diff --git a/lib/pages/send_view/confirm_transaction_view.dart b/lib/pages/send_view/confirm_transaction_view.dart index 1fe6078d9..c23a9dc14 100644 --- a/lib/pages/send_view/confirm_transaction_view.dart +++ b/lib/pages/send_view/confirm_transaction_view.dart @@ -58,6 +58,7 @@ class ConfirmTransactionView extends ConsumerStatefulWidget { Key? key, required this.txData, required this.walletId, + required this.onSuccess, this.routeOnSuccessName = WalletView.routeName, this.isTradeTransaction = false, this.isPaynymTransaction = false, @@ -76,6 +77,7 @@ class ConfirmTransactionView extends ConsumerStatefulWidget { final bool isPaynymNotificationTransaction; final bool isTokenTx; final VoidCallback? onSuccessInsteadOfRouteOnSuccess; + final VoidCallback onSuccess; @override ConsumerState createState() => @@ -205,6 +207,8 @@ class _ConfirmTransactionViewState unawaited(wallet.refresh()); } + widget.onSuccess.call(); + // pop back to wallet if (mounted) { if (widget.onSuccessInsteadOfRouteOnSuccess == null) { diff --git a/lib/pages/send_view/send_view.dart b/lib/pages/send_view/send_view.dart index ea82e5b65..f752ce4b4 100644 --- a/lib/pages/send_view/send_view.dart +++ b/lib/pages/send_view/send_view.dart @@ -762,55 +762,75 @@ class _SendViewState extends ConsumerState { // pop building dialog Navigator.of(context).pop(); - unawaited(Navigator.of(context).push( - RouteGenerator.getRoute( - shouldUseMaterialRoute: RouteGenerator.useMaterialPageRoute, - builder: (_) => ConfirmTransactionView( - txData: txData, - walletId: walletId, - isPaynymTransaction: isPaynymSend, - ), - settings: const RouteSettings( - name: ConfirmTransactionView.routeName, + unawaited( + Navigator.of(context).push( + RouteGenerator.getRoute( + shouldUseMaterialRoute: RouteGenerator.useMaterialPageRoute, + builder: (_) => ConfirmTransactionView( + txData: txData, + walletId: walletId, + isPaynymTransaction: isPaynymSend, + onSuccess: clearSendForm, + ), + settings: const RouteSettings( + name: ConfirmTransactionView.routeName, + ), ), ), - )); + ); } } catch (e) { if (mounted) { // pop building dialog Navigator.of(context).pop(); - unawaited(showDialog( - context: context, - useSafeArea: false, - barrierDismissible: true, - builder: (context) { - return StackDialog( - title: "Transaction failed", - message: e.toString(), - rightButton: TextButton( - style: Theme.of(context) - .extension()! - .getSecondaryEnabledButtonStyle(context), - child: Text( - "Ok", - style: STextStyles.button(context).copyWith( - color: Theme.of(context) - .extension()! - .accentColorDark), + unawaited( + showDialog( + context: context, + useSafeArea: false, + barrierDismissible: true, + builder: (context) { + return StackDialog( + title: "Transaction failed", + message: e.toString(), + rightButton: TextButton( + style: Theme.of(context) + .extension()! + .getSecondaryEnabledButtonStyle(context), + child: Text( + "Ok", + style: STextStyles.button(context).copyWith( + color: Theme.of(context) + .extension()! + .accentColorDark), + ), + onPressed: () { + Navigator.of(context).pop(); + }, ), - onPressed: () { - Navigator.of(context).pop(); - }, - ), - ); - }, - )); + ); + }, + ), + ); } } } + void clearSendForm() { + sendToController.text = ""; + cryptoAmountController.text = ""; + baseAmountController.text = ""; + noteController.text = ""; + onChainNoteController.text = ""; + feeController.text = ""; + memoController.text = ""; + _address = ""; + _addressToggleFlag = false; + if (mounted) { + setState(() {}); + } + } + bool get isPaynymSend => widget.accountLite != null; bool isCustomFee = false; diff --git a/lib/pages/send_view/token_send_view.dart b/lib/pages/send_view/token_send_view.dart index c1ea39345..4ba5ff920 100644 --- a/lib/pages/send_view/token_send_view.dart +++ b/lib/pages/send_view/token_send_view.dart @@ -507,6 +507,7 @@ class _TokenSendViewState extends ConsumerState { txData: txData, walletId: walletId, isTokenTx: true, + onSuccess: clearSendForm, ), settings: const RouteSettings( name: ConfirmTransactionView.routeName, @@ -519,36 +520,51 @@ class _TokenSendViewState extends ConsumerState { // pop building dialog Navigator.of(context).pop(); - unawaited(showDialog( - context: context, - useSafeArea: false, - barrierDismissible: true, - builder: (context) { - return StackDialog( - title: "Transaction failed", - message: e.toString(), - rightButton: TextButton( - style: Theme.of(context) - .extension()! - .getSecondaryEnabledButtonStyle(context), - child: Text( - "Ok", - style: STextStyles.button(context).copyWith( - color: Theme.of(context) - .extension()! - .accentColorDark), + unawaited( + showDialog( + context: context, + useSafeArea: false, + barrierDismissible: true, + builder: (context) { + return StackDialog( + title: "Transaction failed", + message: e.toString(), + rightButton: TextButton( + style: Theme.of(context) + .extension()! + .getSecondaryEnabledButtonStyle(context), + child: Text( + "Ok", + style: STextStyles.button(context).copyWith( + color: Theme.of(context) + .extension()! + .accentColorDark), + ), + onPressed: () { + Navigator.of(context).pop(); + }, ), - onPressed: () { - Navigator.of(context).pop(); - }, - ), - ); - }, - )); + ); + }, + ), + ); } } } + void clearSendForm() { + sendToController.text = ""; + cryptoAmountController.text = ""; + baseAmountController.text = ""; + noteController.text = ""; + feeController.text = ""; + _address = ""; + _addressToggleFlag = false; + if (mounted) { + setState(() {}); + } + } + @override void initState() { ref.refresh(feeSheetSessionCacheProvider); diff --git a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dart b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dart index d638c8690..2884c9d1a 100644 --- a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dart +++ b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dart @@ -435,6 +435,7 @@ class _DesktopSendState extends ConsumerState { child: ConfirmTransactionView( txData: txData, walletId: walletId, + onSuccess: clearSendForm, isPaynymTransaction: isPaynymSend, routeOnSuccessName: DesktopHomeView.routeName, ), @@ -525,6 +526,18 @@ class _DesktopSendState extends ConsumerState { } } + void clearSendForm() { + sendToController.text = ""; + cryptoAmountController.text = ""; + baseAmountController.text = ""; + memoController.text = ""; + _address = ""; + _addressToggleFlag = false; + if (mounted) { + setState(() {}); + } + } + void _cryptoAmountChanged() async { if (!_cryptoAmountChangeLock) { final cryptoAmount = ref.read(pAmountFormatter(coin)).tryParse( diff --git a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_token_send.dart b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_token_send.dart index 0a127dbac..06229a757 100644 --- a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_token_send.dart +++ b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_token_send.dart @@ -277,6 +277,7 @@ class _DesktopTokenSendState extends ConsumerState { child: ConfirmTransactionView( txData: txData, walletId: walletId, + onSuccess: clearSendForm, isTokenTx: true, routeOnSuccessName: DesktopHomeView.routeName, ), @@ -366,6 +367,18 @@ class _DesktopTokenSendState extends ConsumerState { } } + void clearSendForm() { + sendToController.text = ""; + cryptoAmountController.text = ""; + baseAmountController.text = ""; + nonceController.text = ""; + _address = ""; + _addressToggleFlag = false; + if (mounted) { + setState(() {}); + } + } + void _cryptoAmountChanged() async { if (!_cryptoAmountChangeLock) { final String cryptoAmount = cryptoAmountController.text; diff --git a/lib/route_generator.dart b/lib/route_generator.dart index 11c8f6237..5b8f1943d 100644 --- a/lib/route_generator.dart +++ b/lib/route_generator.dart @@ -1463,12 +1463,13 @@ class RouteGenerator { return _routeError("${settings.name} invalid args: ${args.toString()}"); case ConfirmTransactionView.routeName: - if (args is Tuple2) { + if (args is (TxData, String, VoidCallback)) { return getRoute( shouldUseMaterialRoute: useMaterialPageRoute, builder: (_) => ConfirmTransactionView( - txData: args.item1, - walletId: args.item2, + txData: args.$1, + walletId: args.$2, + onSuccess: args.$3, ), settings: RouteSettings( name: settings.name,