diff --git a/lib/frost_route_generator.dart b/lib/frost_route_generator.dart index c8b06f916..297adbf04 100644 --- a/lib/frost_route_generator.dart +++ b/lib/frost_route_generator.dart @@ -26,6 +26,12 @@ import 'package:stackwallet/wallets/crypto_currency/intermediate/frost_currency. typedef FrostStepRoute = ({String routeName, String title}); +enum FrostInterruptionDialogType { + walletCreation, + resharing, + transactionCreation; +} + final pFrostCreateCurrentStep = StateProvider.autoDispose((ref) => 1); final pFrostScaffoldArgs = StateProvider< ({ @@ -33,6 +39,7 @@ final pFrostScaffoldArgs = StateProvider< String? walletId, List<FrostStepRoute> stepRoutes, VoidCallback onSuccess, + FrostInterruptionDialogType frostInterruptionDialogType, })?>((ref) => null); abstract class FrostRouteGenerator { diff --git a/lib/pages/add_wallet_views/frost_ms/new/create_new_frost_ms_wallet_view.dart b/lib/pages/add_wallet_views/frost_ms/new/create_new_frost_ms_wallet_view.dart index 4a9af99f6..c3a4ba47c 100644 --- a/lib/pages/add_wallet_views/frost_ms/new/create_new_frost_ms_wallet_view.dart +++ b/lib/pages/add_wallet_views/frost_ms/new/create_new_frost_ms_wallet_view.dart @@ -445,7 +445,9 @@ class _NewFrostMsWalletViewState context: context, ), ); - } + }, + frostInterruptionDialogType: + FrostInterruptionDialogType.walletCreation, ); await Navigator.of(context).pushNamed( diff --git a/lib/pages/add_wallet_views/frost_ms/new/select_new_frost_import_type_view.dart b/lib/pages/add_wallet_views/frost_ms/new/select_new_frost_import_type_view.dart index 1abcc74cd..8b0e4118f 100644 --- a/lib/pages/add_wallet_views/frost_ms/new/select_new_frost_import_type_view.dart +++ b/lib/pages/add_wallet_views/frost_ms/new/select_new_frost_import_type_view.dart @@ -177,7 +177,9 @@ class _SelectNewFrostImportTypeViewState context: context, ), ); - } + }, + frostInterruptionDialogType: + FrostInterruptionDialogType.walletCreation, ); break; @@ -191,7 +193,9 @@ class _SelectNewFrostImportTypeViewState stepRoutes: FrostRouteGenerator.joinReshareStepRoutes, onSuccess: () { // successful completion of steps - } + }, + frostInterruptionDialogType: + FrostInterruptionDialogType.resharing, ); break; } diff --git a/lib/pages/add_wallet_views/frost_ms/reshare/frost_reshare_step_1c.dart b/lib/pages/add_wallet_views/frost_ms/reshare/frost_reshare_step_1c.dart index 9e30f4ab9..6908cf8bd 100644 --- a/lib/pages/add_wallet_views/frost_ms/reshare/frost_reshare_step_1c.dart +++ b/lib/pages/add_wallet_views/frost_ms/reshare/frost_reshare_step_1c.dart @@ -215,6 +215,8 @@ class _FrostReshareStep1cState extends ConsumerState<FrostReshareStep1c> { walletId: wallet.walletId, stepRoutes: data.stepRoutes, onSuccess: data.onSuccess, + frostInterruptionDialogType: + FrostInterruptionDialogType.resharing, ); ref.read(pFrostCreateCurrentStep.state).state = 2; await Navigator.of(context).pushNamed( diff --git a/lib/pages/send_view/frost_ms/frost_send_view.dart b/lib/pages/send_view/frost_ms/frost_send_view.dart index 0dde93687..e0a080a88 100644 --- a/lib/pages/send_view/frost_ms/frost_send_view.dart +++ b/lib/pages/send_view/frost_ms/frost_send_view.dart @@ -139,7 +139,9 @@ class _FrostSendViewState extends ConsumerState<FrostSendView> { // TODO ? ref.read(pFrostScaffoldArgs.state).state = null; - } + }, + frostInterruptionDialogType: + FrostInterruptionDialogType.transactionCreation, ); await Navigator.of(context).pushNamed( diff --git a/lib/pages/settings_views/wallet_settings_view/frost_ms/frost_ms_options_view.dart b/lib/pages/settings_views/wallet_settings_view/frost_ms/frost_ms_options_view.dart index 16eda73fd..f93a069b0 100644 --- a/lib/pages/settings_views/wallet_settings_view/frost_ms/frost_ms_options_view.dart +++ b/lib/pages/settings_views/wallet_settings_view/frost_ms/frost_ms_options_view.dart @@ -164,7 +164,9 @@ class FrostMSWalletOptionsView extends ConsumerWidget { // TODO ref.read(pFrostScaffoldArgs.state).state = null; - } + }, + frostInterruptionDialogType: + FrostInterruptionDialogType.resharing, ); Navigator.of(context).pushNamed( diff --git a/lib/pages/settings_views/wallet_settings_view/frost_ms/initiate_resharing/complete_reshare_config_view.dart b/lib/pages/settings_views/wallet_settings_view/frost_ms/initiate_resharing/complete_reshare_config_view.dart index 6a92b76ed..1b3b9a9fd 100644 --- a/lib/pages/settings_views/wallet_settings_view/frost_ms/initiate_resharing/complete_reshare_config_view.dart +++ b/lib/pages/settings_views/wallet_settings_view/frost_ms/initiate_resharing/complete_reshare_config_view.dart @@ -139,7 +139,8 @@ class _CompleteReshareConfigViewState onSuccess: () { // successful completion of steps // TODO - } + }, + frostInterruptionDialogType: FrostInterruptionDialogType.resharing, ); if (mounted) { diff --git a/lib/pages/wallet_view/wallet_view.dart b/lib/pages/wallet_view/wallet_view.dart index 57c5c977f..c7b30d81c 100644 --- a/lib/pages/wallet_view/wallet_view.dart +++ b/lib/pages/wallet_view/wallet_view.dart @@ -373,7 +373,9 @@ class _WalletViewState extends ConsumerState<WalletView> { // TODO ? ref.read(pFrostScaffoldArgs.state).state = null; - } + }, + frostInterruptionDialogType: + FrostInterruptionDialogType.transactionCreation, ); await Navigator.of(context).pushNamed( diff --git a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/my_wallet.dart b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/my_wallet.dart index 22cf282af..0b7875b34 100644 --- a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/my_wallet.dart +++ b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/my_wallet.dart @@ -107,7 +107,10 @@ class _MyWalletState extends ConsumerState<MyWallet> { ref .read(pFrostScaffoldArgs.state) .state = null; - } + }, + frostInterruptionDialogType: + FrostInterruptionDialogType + .transactionCreation, ); await Navigator.of(context).pushNamed( diff --git a/lib/widgets/dialogs/frost/frost_interruption_dialog.dart b/lib/widgets/dialogs/frost/frost_interruption_dialog.dart deleted file mode 100644 index 4d36456bb..000000000 --- a/lib/widgets/dialogs/frost/frost_interruption_dialog.dart +++ /dev/null @@ -1,70 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:stackwallet/utilities/util.dart'; -import 'package:stackwallet/widgets/desktop/primary_button.dart'; -import 'package:stackwallet/widgets/desktop/secondary_button.dart'; -import 'package:stackwallet/widgets/stack_dialog.dart'; - -enum FrostInterruptionDialogType { - walletCreation, - resharing, - transactionCreation; -} - -class FrostInterruptionDialog extends StatelessWidget { - const FrostInterruptionDialog({ - super.key, - required this.type, - required this.popUntilOnYesRouteName, - this.onNoPressedOverride, - this.onYesPressedOverride, - }); - - final FrostInterruptionDialogType type; - final String popUntilOnYesRouteName; - final VoidCallback? onNoPressedOverride; - final VoidCallback? onYesPressedOverride; - - String get message { - switch (type) { - case FrostInterruptionDialogType.walletCreation: - return "wallet creation"; - case FrostInterruptionDialogType.resharing: - return "resharing"; - case FrostInterruptionDialogType.transactionCreation: - return "transaction signing"; - } - } - - @override - Widget build(BuildContext context) { - return StackDialog( - title: "Cancel $message process", - message: "Are you sure you want to cancel the $message process?", - leftButton: SecondaryButton( - label: "No", - onPressed: onNoPressedOverride ?? - Navigator.of( - context, - rootNavigator: Util.isDesktop, - ).pop, - ), - rightButton: PrimaryButton( - label: "Yes", - onPressed: onYesPressedOverride ?? - () { - // pop dialog - Navigator.of( - context, - rootNavigator: Util.isDesktop, - ).pop(); - - Navigator.of(context).popUntil( - ModalRoute.withName( - popUntilOnYesRouteName, - ), - ); - }, - ), - ); - } -} diff --git a/lib/widgets/frost_scaffold.dart b/lib/widgets/frost_scaffold.dart index 34ab2b922..a5d218dc0 100644 --- a/lib/widgets/frost_scaffold.dart +++ b/lib/widgets/frost_scaffold.dart @@ -7,7 +7,10 @@ import 'package:stackwallet/utilities/util.dart'; import 'package:stackwallet/widgets/background.dart'; import 'package:stackwallet/widgets/conditional_parent.dart'; import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart'; +import 'package:stackwallet/widgets/desktop/primary_button.dart'; +import 'package:stackwallet/widgets/desktop/secondary_button.dart'; import 'package:stackwallet/widgets/progress_bar.dart'; +import 'package:stackwallet/widgets/stack_dialog.dart'; class FrostStepScaffold extends ConsumerStatefulWidget { const FrostStepScaffold({super.key}); @@ -25,18 +28,60 @@ class _FrostScaffoldState extends ConsumerState<FrostStepScaffold> { late final List<FrostStepRoute> _routes; bool _requestPopLock = false; + + String get _message { + switch (ref.read(pFrostScaffoldArgs)!.frostInterruptionDialogType) { + case FrostInterruptionDialogType.walletCreation: + return "wallet creation"; + case FrostInterruptionDialogType.resharing: + return "resharing"; + case FrostInterruptionDialogType.transactionCreation: + return "transaction signing"; + } + } + Future<void> _requestPop(BuildContext context) async { if (_requestPopLock) { return; } _requestPopLock = true; - // TODO: dialog to confirm exit + final resultFuture = showDialog<String?>( + context: context, + barrierDismissible: false, + builder: (context) => StackDialog( + title: "Cancel $_message process", + message: "Are you sure you want to cancel the $_message process?", + leftButton: SecondaryButton( + label: "No", + onPressed: () { + // pop dialog + Navigator.of( + context, + rootNavigator: Util.isDesktop, + ).pop("no"); + }, + ), + rightButton: PrimaryButton( + label: "Yes", + onPressed: () { + // pop dialog + Navigator.of( + context, + rootNavigator: Util.isDesktop, + ).pop("yes"); + }, + ), + ), + ); // make sure to at least delay some time otherwise flutter pops back more than a single route lol... - await Future<void>.delayed(const Duration(milliseconds: 200)); + final minTimeFuture = + Future<void>.delayed(const Duration(milliseconds: 200)); - if (context.mounted) { + final result = await Future.wait<dynamic>([resultFuture, minTimeFuture]); + + if (context.mounted && result[0] == "yes") { Navigator.of(context).pop(); ref.read(pFrostScaffoldArgs.state).state = null; }