frost flow interruption dialog

This commit is contained in:
julian 2024-05-01 14:50:12 -06:00
parent 48e05919d5
commit ccca53f3d8
11 changed files with 81 additions and 81 deletions
lib
frost_route_generator.dart
pages
pages_desktop_specific/my_stack_view/wallet_view/sub_widgets
widgets

View file

@ -26,6 +26,12 @@ import 'package:stackwallet/wallets/crypto_currency/intermediate/frost_currency.
typedef FrostStepRoute = ({String routeName, String title}); typedef FrostStepRoute = ({String routeName, String title});
enum FrostInterruptionDialogType {
walletCreation,
resharing,
transactionCreation;
}
final pFrostCreateCurrentStep = StateProvider.autoDispose((ref) => 1); final pFrostCreateCurrentStep = StateProvider.autoDispose((ref) => 1);
final pFrostScaffoldArgs = StateProvider< final pFrostScaffoldArgs = StateProvider<
({ ({
@ -33,6 +39,7 @@ final pFrostScaffoldArgs = StateProvider<
String? walletId, String? walletId,
List<FrostStepRoute> stepRoutes, List<FrostStepRoute> stepRoutes,
VoidCallback onSuccess, VoidCallback onSuccess,
FrostInterruptionDialogType frostInterruptionDialogType,
})?>((ref) => null); })?>((ref) => null);
abstract class FrostRouteGenerator { abstract class FrostRouteGenerator {

View file

@ -445,7 +445,9 @@ class _NewFrostMsWalletViewState
context: context, context: context,
), ),
); );
} },
frostInterruptionDialogType:
FrostInterruptionDialogType.walletCreation,
); );
await Navigator.of(context).pushNamed( await Navigator.of(context).pushNamed(

View file

@ -177,7 +177,9 @@ class _SelectNewFrostImportTypeViewState
context: context, context: context,
), ),
); );
} },
frostInterruptionDialogType:
FrostInterruptionDialogType.walletCreation,
); );
break; break;
@ -191,7 +193,9 @@ class _SelectNewFrostImportTypeViewState
stepRoutes: FrostRouteGenerator.joinReshareStepRoutes, stepRoutes: FrostRouteGenerator.joinReshareStepRoutes,
onSuccess: () { onSuccess: () {
// successful completion of steps // successful completion of steps
} },
frostInterruptionDialogType:
FrostInterruptionDialogType.resharing,
); );
break; break;
} }

View file

@ -215,6 +215,8 @@ class _FrostReshareStep1cState extends ConsumerState<FrostReshareStep1c> {
walletId: wallet.walletId, walletId: wallet.walletId,
stepRoutes: data.stepRoutes, stepRoutes: data.stepRoutes,
onSuccess: data.onSuccess, onSuccess: data.onSuccess,
frostInterruptionDialogType:
FrostInterruptionDialogType.resharing,
); );
ref.read(pFrostCreateCurrentStep.state).state = 2; ref.read(pFrostCreateCurrentStep.state).state = 2;
await Navigator.of(context).pushNamed( await Navigator.of(context).pushNamed(

View file

@ -139,7 +139,9 @@ class _FrostSendViewState extends ConsumerState<FrostSendView> {
// TODO ? // TODO ?
ref.read(pFrostScaffoldArgs.state).state = null; ref.read(pFrostScaffoldArgs.state).state = null;
} },
frostInterruptionDialogType:
FrostInterruptionDialogType.transactionCreation,
); );
await Navigator.of(context).pushNamed( await Navigator.of(context).pushNamed(

View file

@ -164,7 +164,9 @@ class FrostMSWalletOptionsView extends ConsumerWidget {
// TODO // TODO
ref.read(pFrostScaffoldArgs.state).state = null; ref.read(pFrostScaffoldArgs.state).state = null;
} },
frostInterruptionDialogType:
FrostInterruptionDialogType.resharing,
); );
Navigator.of(context).pushNamed( Navigator.of(context).pushNamed(

View file

@ -139,7 +139,8 @@ class _CompleteReshareConfigViewState
onSuccess: () { onSuccess: () {
// successful completion of steps // successful completion of steps
// TODO // TODO
} },
frostInterruptionDialogType: FrostInterruptionDialogType.resharing,
); );
if (mounted) { if (mounted) {

View file

@ -373,7 +373,9 @@ class _WalletViewState extends ConsumerState<WalletView> {
// TODO ? // TODO ?
ref.read(pFrostScaffoldArgs.state).state = null; ref.read(pFrostScaffoldArgs.state).state = null;
} },
frostInterruptionDialogType:
FrostInterruptionDialogType.transactionCreation,
); );
await Navigator.of(context).pushNamed( await Navigator.of(context).pushNamed(

View file

@ -107,7 +107,10 @@ class _MyWalletState extends ConsumerState<MyWallet> {
ref ref
.read(pFrostScaffoldArgs.state) .read(pFrostScaffoldArgs.state)
.state = null; .state = null;
} },
frostInterruptionDialogType:
FrostInterruptionDialogType
.transactionCreation,
); );
await Navigator.of(context).pushNamed( await Navigator.of(context).pushNamed(

View file

@ -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,
),
);
},
),
);
}
}

View file

@ -7,7 +7,10 @@ import 'package:stackwallet/utilities/util.dart';
import 'package:stackwallet/widgets/background.dart'; import 'package:stackwallet/widgets/background.dart';
import 'package:stackwallet/widgets/conditional_parent.dart'; import 'package:stackwallet/widgets/conditional_parent.dart';
import 'package:stackwallet/widgets/custom_buttons/blue_text_button.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/progress_bar.dart';
import 'package:stackwallet/widgets/stack_dialog.dart';
class FrostStepScaffold extends ConsumerStatefulWidget { class FrostStepScaffold extends ConsumerStatefulWidget {
const FrostStepScaffold({super.key}); const FrostStepScaffold({super.key});
@ -25,18 +28,60 @@ class _FrostScaffoldState extends ConsumerState<FrostStepScaffold> {
late final List<FrostStepRoute> _routes; late final List<FrostStepRoute> _routes;
bool _requestPopLock = false; 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 { Future<void> _requestPop(BuildContext context) async {
if (_requestPopLock) { if (_requestPopLock) {
return; return;
} }
_requestPopLock = true; _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... // 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(); Navigator.of(context).pop();
ref.read(pFrostScaffoldArgs.state).state = null; ref.read(pFrostScaffoldArgs.state).state = null;
} }