From ed2a637e5e4e6110ff6e9e696661949c17ab00e6 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Tue, 17 Oct 2023 22:17:16 -0500 Subject: [PATCH] hook cancel buttons up to stop fn --- fusiondart | 2 +- .../cashfusion/fusion_progress_view.dart | 22 ++++++++++---- .../cashfusion/desktop_cashfusion_view.dart | 2 +- .../cashfusion/sub_widgets/fusion_dialog.dart | 30 +++++++++++++++---- 4 files changed, 43 insertions(+), 13 deletions(-) diff --git a/fusiondart b/fusiondart index 0d634a48e..1f98575c5 160000 --- a/fusiondart +++ b/fusiondart @@ -1 +1 @@ -Subproject commit 0d634a48e180458456aa6bc822bb82098380d114 +Subproject commit 1f98575c58d5b3144ac6e5e613311307c22e53b2 diff --git a/lib/pages/cashfusion/fusion_progress_view.dart b/lib/pages/cashfusion/fusion_progress_view.dart index 544088b11..e0261e45b 100644 --- a/lib/pages/cashfusion/fusion_progress_view.dart +++ b/lib/pages/cashfusion/fusion_progress_view.dart @@ -9,14 +9,17 @@ */ import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:stackwallet/pages_desktop_specific/cashfusion/sub_widgets/fusion_progress.dart'; +import 'package:stackwallet/providers/global/wallets_provider.dart'; +import 'package:stackwallet/services/mixins/fusion_wallet_interface.dart'; import 'package:stackwallet/themes/stack_colors.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/widgets/background.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; import 'package:stackwallet/widgets/desktop/secondary_button.dart'; -class FusionProgressView extends StatefulWidget { +class FusionProgressView extends ConsumerStatefulWidget { const FusionProgressView({ super.key, required this.walletId, @@ -27,14 +30,13 @@ class FusionProgressView extends StatefulWidget { final String walletId; @override - State createState() => _FusionProgressViewState(); + ConsumerState createState() => _FusionProgressViewState(); } -class _FusionProgressViewState extends State { +class _FusionProgressViewState extends ConsumerState { /// return true on will cancel, false if cancel cancelled Future _requestCancel() async { - // - + // TODO return false; } @@ -88,8 +90,16 @@ class _FusionProgressViewState extends State { // TODO: various button states // tempt only show cancel button SecondaryButton( - label: "Cancel", + label: "Cancela", onPressed: () async { + final fusionWallet = ref + .read(walletsChangeNotifierProvider) + .getManager(widget.walletId) + .wallet as FusionWalletInterface; + + await fusionWallet.stop(); + // TODO should this stop be unawaited? + if (await _requestCancel()) { if (mounted) { Navigator.of(context).pop(); diff --git a/lib/pages_desktop_specific/cashfusion/desktop_cashfusion_view.dart b/lib/pages_desktop_specific/cashfusion/desktop_cashfusion_view.dart index b93548bb4..1c0c22821 100644 --- a/lib/pages_desktop_specific/cashfusion/desktop_cashfusion_view.dart +++ b/lib/pages_desktop_specific/cashfusion/desktop_cashfusion_view.dart @@ -568,7 +568,7 @@ class _DesktopCashFusion extends ConsumerState { context: context, barrierDismissible: false, builder: (context) { - return FusionDialog( + return FusionDialogView( walletId: widget.walletId, ); }, diff --git a/lib/pages_desktop_specific/cashfusion/sub_widgets/fusion_dialog.dart b/lib/pages_desktop_specific/cashfusion/sub_widgets/fusion_dialog.dart index fdc577e96..6e0399232 100644 --- a/lib/pages_desktop_specific/cashfusion/sub_widgets/fusion_dialog.dart +++ b/lib/pages_desktop_specific/cashfusion/sub_widgets/fusion_dialog.dart @@ -1,5 +1,8 @@ import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:stackwallet/pages_desktop_specific/cashfusion/sub_widgets/fusion_progress.dart'; +import 'package:stackwallet/providers/global/wallets_provider.dart'; +import 'package:stackwallet/services/mixins/fusion_wallet_interface.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/widgets/desktop/desktop_dialog.dart'; import 'package:stackwallet/widgets/desktop/desktop_dialog_close_button.dart'; @@ -14,14 +17,19 @@ class CashFusionState { CashFusionState({required this.status, this.info}); } -class FusionDialog extends StatelessWidget { - const FusionDialog({ +class FusionDialogView extends ConsumerStatefulWidget { + const FusionDialogView({ Key? key, required this.walletId, }) : super(key: key); final String walletId; + @override + ConsumerState createState() => _FusionDialogViewState(); +} + +class _FusionDialogViewState extends ConsumerState { @override Widget build(BuildContext context) { return DesktopDialog( @@ -59,7 +67,7 @@ class FusionDialog extends StatelessWidget { height: 20, ), FusionProgress( - walletId: walletId, + walletId: widget.walletId, ), const SizedBox( height: 12, @@ -72,8 +80,20 @@ class FusionDialog extends StatelessWidget { buttonHeight: ButtonHeight.m, enabled: true, label: "Cancel", - onPressed: () { - Navigator.of(context).pop(true); + onPressed: () async { + final fusionWallet = ref + .read(walletsChangeNotifierProvider) + .getManager(widget.walletId) + .wallet as FusionWalletInterface; + + await fusionWallet.stop(); + // TODO should this stop be unawaited? + + // if (await _requestCancel()) { + if (mounted) { + Navigator.of(context).pop(); + } + // } }, ), ],