clear send form on successful send

This commit is contained in:
julian 2024-01-04 12:52:00 -06:00
parent b5cb0b067f
commit 1121949f56
8 changed files with 137 additions and 64 deletions

View file

@ -154,6 +154,9 @@ class _PaynymDetailsPopupState extends ConsumerState<PaynymDetailsPopup> {
routeOnSuccessName: PaynymHomeView.routeName,
isPaynymNotificationTransaction: true,
txData: preparedTx,
onSuccess: () {
// do nothing extra
},
),
),
);

View file

@ -126,6 +126,9 @@ class _PaynymDetailsPopupState extends ConsumerState<DesktopPaynymDetails> {
walletId: widget.walletId,
isPaynymNotificationTransaction: true,
txData: preparedTx,
onSuccess: () {
// do nothing extra
},
onSuccessInsteadOfRouteOnSuccess: () {
Navigator.of(context, rootNavigator: true).pop();
Navigator.of(context, rootNavigator: true).pop();

View file

@ -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<ConfirmTransactionView> createState() =>
@ -205,6 +207,8 @@ class _ConfirmTransactionViewState
unawaited(wallet.refresh());
}
widget.onSuccess.call();
// pop back to wallet
if (mounted) {
if (widget.onSuccessInsteadOfRouteOnSuccess == null) {

View file

@ -762,26 +762,30 @@ class _SendViewState extends ConsumerState<SendView> {
// pop building dialog
Navigator.of(context).pop();
unawaited(Navigator.of(context).push(
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<dynamic>(
unawaited(
showDialog<dynamic>(
context: context,
useSafeArea: false,
barrierDismissible: true,
@ -806,11 +810,27 @@ class _SendViewState extends ConsumerState<SendView> {
),
);
},
));
),
);
}
}
}
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;

View file

@ -507,6 +507,7 @@ class _TokenSendViewState extends ConsumerState<TokenSendView> {
txData: txData,
walletId: walletId,
isTokenTx: true,
onSuccess: clearSendForm,
),
settings: const RouteSettings(
name: ConfirmTransactionView.routeName,
@ -519,7 +520,8 @@ class _TokenSendViewState extends ConsumerState<TokenSendView> {
// pop building dialog
Navigator.of(context).pop();
unawaited(showDialog<dynamic>(
unawaited(
showDialog<dynamic>(
context: context,
useSafeArea: false,
barrierDismissible: true,
@ -544,11 +546,25 @@ class _TokenSendViewState extends ConsumerState<TokenSendView> {
),
);
},
));
),
);
}
}
}
void clearSendForm() {
sendToController.text = "";
cryptoAmountController.text = "";
baseAmountController.text = "";
noteController.text = "";
feeController.text = "";
_address = "";
_addressToggleFlag = false;
if (mounted) {
setState(() {});
}
}
@override
void initState() {
ref.refresh(feeSheetSessionCacheProvider);

View file

@ -435,6 +435,7 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
child: ConfirmTransactionView(
txData: txData,
walletId: walletId,
onSuccess: clearSendForm,
isPaynymTransaction: isPaynymSend,
routeOnSuccessName: DesktopHomeView.routeName,
),
@ -525,6 +526,18 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
}
}
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(

View file

@ -277,6 +277,7 @@ class _DesktopTokenSendState extends ConsumerState<DesktopTokenSend> {
child: ConfirmTransactionView(
txData: txData,
walletId: walletId,
onSuccess: clearSendForm,
isTokenTx: true,
routeOnSuccessName: DesktopHomeView.routeName,
),
@ -366,6 +367,18 @@ class _DesktopTokenSendState extends ConsumerState<DesktopTokenSend> {
}
}
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;

View file

@ -1463,12 +1463,13 @@ class RouteGenerator {
return _routeError("${settings.name} invalid args: ${args.toString()}");
case ConfirmTransactionView.routeName:
if (args is Tuple2<TxData, String>) {
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,