Skip to content

Commit

Permalink
feat: exit dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
damian-molinski committed Oct 14, 2024
1 parent f90b055 commit 2652655
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 68 deletions.
45 changes: 38 additions & 7 deletions catalyst_voices/lib/pages/registration/registration_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import 'dart:async';
import 'package:catalyst_voices/common/error_handler.dart';
import 'package:catalyst_voices/dependency/dependencies.dart';
import 'package:catalyst_voices/pages/registration/registration_details_panel.dart';
import 'package:catalyst_voices/pages/registration/registration_exit_confirm_dialog.dart';
import 'package:catalyst_voices/pages/registration/registration_info_panel.dart';
import 'package:catalyst_voices/pages/registration/widgets/exit_confirm_dialog.dart';
import 'package:catalyst_voices/widgets/widgets.dart';
import 'package:catalyst_voices_blocs/catalyst_voices_blocs.dart';
import 'package:catalyst_voices_models/catalyst_voices_models.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

Expand Down Expand Up @@ -54,7 +55,12 @@ class _RegistrationDialogState extends State<RegistrationDialog>
child: PopScope(
canPop: false,
onPopInvokedWithResult: (didPop, result) {
unawaited(_confirmedExit(context, didPop: didPop));
unawaited(
_handlePop(
context,
didPop: didPop,
),
);
},
child: const VoicesTwoPaneDialog(
left: RegistrationInfoPanel(),
Expand All @@ -64,21 +70,46 @@ class _RegistrationDialogState extends State<RegistrationDialog>
);
}

Future<void> _confirmedExit(
Future<void> _handlePop(
BuildContext context, {
required bool didPop,
}) async {
if (didPop) {
return;
}

final confirmed = await VoicesQuestionDialog.show(
context,
builder: (_) => const RegistrationExitConfirmDialog(),
);
final state = _cubit.state;
final hasProgress = (state.progress ?? 0.0) > 0.0;
if (!hasProgress) {
Navigator.of(context).pop();
return;
}

final confirmed = await _confirmExit(context, step: state.step);

if (context.mounted && confirmed) {
Navigator.of(context).pop();
}
}

Future<bool> _confirmExit(
BuildContext context, {
required RegistrationStep step,
}) {
if (step.isRegistrationFlow) {
return VoicesQuestionDialog.show(
context,
builder: (_) => const RegistrationExitConfirmDialog(),
);
}

if (step.isRecoverFlow) {
return VoicesQuestionDialog.show(
context,
builder: (_) => const RecoveryExitConfirmDialog(),
);
}

return Future.value(true);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import 'package:catalyst_voices/widgets/widgets.dart';
import 'package:catalyst_voices_assets/catalyst_voices_assets.dart';
import 'package:catalyst_voices_brands/catalyst_voices_brands.dart';
import 'package:catalyst_voices_localization/catalyst_voices_localization.dart';
import 'package:flutter/material.dart';

class RecoveryExitConfirmDialog extends StatelessWidget {
const RecoveryExitConfirmDialog({super.key});

@override
Widget build(BuildContext context) {
return ExitConfirmDialog(
title: context.l10n.warning,
subtitle: context.l10n.recoveryExitConfirmDialogSubtitle,
content: context.l10n.recoveryExitConfirmDialogContent,
positive: context.l10n.recoveryExitConfirmDialogContinue,
negative: context.l10n.cancelAnyways,
);
}
}

class RegistrationExitConfirmDialog extends StatelessWidget {
const RegistrationExitConfirmDialog({super.key});

@override
Widget build(BuildContext context) {
return ExitConfirmDialog(
title: context.l10n.warning,
subtitle: context.l10n.registrationExitConfirmDialogSubtitle,
content: context.l10n.registrationExitConfirmDialogContent,
positive: context.l10n.registrationExitConfirmDialogContinue,
negative: context.l10n.cancelAnyways,
);
}
}

class ExitConfirmDialog extends StatelessWidget {
final String title;
final String subtitle;
final String content;
final String positive;
final String negative;

const ExitConfirmDialog({
super.key,
required this.title,
required this.subtitle,
required this.content,
required this.positive,
required this.negative,
});

@override
Widget build(BuildContext context) {
return VoicesQuestionDialog(
title: Text(title.toUpperCase()),
icon: const _WarningIcon(),
subtitle: Text(subtitle.toUpperCase()),
content: Padding(
padding: const EdgeInsets.only(bottom: 30),
child: Text(content),
),
actions: [
VoicesQuestionActionItem.negative(
positive,
type: VoicesQuestionActionType.filled,
),
VoicesQuestionActionItem.positive(
negative,
type: VoicesQuestionActionType.text,
),
],
);
}
}

class _WarningIcon extends StatelessWidget {
const _WarningIcon();

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final color = theme.colors.iconsError!;

return VoicesAvatar(
border: Border.all(
color: color,
width: 3,
),
icon: VoicesAssets.icons.exclamation.buildIcon(size: 36),
backgroundColor: Colors.transparent,
foregroundColor: color,
radius: 40,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1552,11 +1552,11 @@ abstract class VoicesLocalizations {
/// **'Continue keychain creation'**
String get registrationExitConfirmDialogContinue;

/// No description provided for @registrationExitConfirmDialogCancel.
/// No description provided for @cancelAnyways.
///
/// In en, this message translates to:
/// **'Cancel anyway'**
String get registrationExitConfirmDialogCancel;
String get cancelAnyways;

/// No description provided for @recoverCatalystKeychain.
///
Expand Down Expand Up @@ -1683,6 +1683,24 @@ abstract class VoicesLocalizations {
/// In en, this message translates to:
/// **'Check my account'**
String get recoverySuccessGoAccount;

/// No description provided for @recoveryExitConfirmDialogSubtitle.
///
/// In en, this message translates to:
/// **'12 word keychain restoration incomplete'**
String get recoveryExitConfirmDialogSubtitle;

/// No description provided for @recoveryExitConfirmDialogContent.
///
/// In en, this message translates to:
/// **'Please continue your Catalyst Keychain restoration, if you cancel all input will be lost.'**
String get recoveryExitConfirmDialogContent;

/// No description provided for @recoveryExitConfirmDialogContinue.
///
/// In en, this message translates to:
/// **'Continue recovery process'**
String get recoveryExitConfirmDialogContinue;
}

class _VoicesLocalizationsDelegate extends LocalizationsDelegate<VoicesLocalizations> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ class VoicesLocalizationsEn extends VoicesLocalizations {
String get registrationExitConfirmDialogContinue => 'Continue keychain creation';

@override
String get registrationExitConfirmDialogCancel => 'Cancel anyway';
String get cancelAnyways => 'Cancel anyway';

@override
String get recoverCatalystKeychain => 'Restore Catalyst keychain';
Expand Down Expand Up @@ -882,4 +882,13 @@ class VoicesLocalizationsEn extends VoicesLocalizations {

@override
String get recoverySuccessGoAccount => 'Check my account';

@override
String get recoveryExitConfirmDialogSubtitle => '12 word keychain restoration incomplete';

@override
String get recoveryExitConfirmDialogContent => 'Please continue your Catalyst Keychain restoration, if you cancel all input will be lost.';

@override
String get recoveryExitConfirmDialogContinue => 'Continue recovery process';
}
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ class VoicesLocalizationsEs extends VoicesLocalizations {
String get registrationExitConfirmDialogContinue => 'Continue keychain creation';

@override
String get registrationExitConfirmDialogCancel => 'Cancel anyway';
String get cancelAnyways => 'Cancel anyway';

@override
String get recoverCatalystKeychain => 'Restore Catalyst keychain';
Expand Down Expand Up @@ -882,4 +882,13 @@ class VoicesLocalizationsEs extends VoicesLocalizations {

@override
String get recoverySuccessGoAccount => 'Check my account';

@override
String get recoveryExitConfirmDialogSubtitle => '12 word keychain restoration incomplete';

@override
String get recoveryExitConfirmDialogContent => 'Please continue your Catalyst Keychain restoration, if you cancel all input will be lost.';

@override
String get recoveryExitConfirmDialogContinue => 'Continue recovery process';
}
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@
"registrationExitConfirmDialogSubtitle": "Account creation incomplete!",
"registrationExitConfirmDialogContent": "If attempt to leave without creating your keychain - account creation will be incomplete. \u2028\u2028You are not able to login without \u2028completing your keychain.",
"registrationExitConfirmDialogContinue": "Continue keychain creation",
"registrationExitConfirmDialogCancel": "Cancel anyway",
"cancelAnyways": "Cancel anyway",
"recoverCatalystKeychain": "Restore Catalyst keychain",
"recoverKeychainMethodsTitle": "Restore your Catalyst Keychain",
"recoverKeychainMethodsNoKeychainFound": "No Catalyst Keychain found on this device.",
Expand All @@ -885,5 +885,8 @@
"recoverySuccessTitle": "Congratulations your Catalyst \u2028Keychain is restored!",
"recoverySuccessSubtitle": "You have successfully restored your Catalyst Keychain, and unlocked Catalyst Voices on this device.",
"recoverySuccessGoToDashboard": "Jump into the Discovery space / Dashboard",
"recoverySuccessGoAccount": "Check my account"
"recoverySuccessGoAccount": "Check my account",
"recoveryExitConfirmDialogSubtitle": "12 word keychain restoration incomplete",
"recoveryExitConfirmDialogContent": "Please continue your Catalyst Keychain restoration, if you cancel all input will be lost.",
"recoveryExitConfirmDialogContinue": "Continue recovery process"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import 'package:equatable/equatable.dart';
sealed class RegistrationStep extends Equatable {
const RegistrationStep();

bool get isRegistrationFlow => false;

bool get isRecoverFlow => false;

@override
List<Object?> get props => [];
}
Expand All @@ -26,6 +30,9 @@ final class SeedPhraseRecoverStep extends RegistrationStep {
this.stage = RecoverSeedPhraseStage.seedPhraseInstructions,
});

@override
bool get isRecoverFlow => true;

@override
List<Object?> get props => [stage];
}
Expand All @@ -37,12 +44,18 @@ final class CreateKeychainStep extends RegistrationStep {
this.stage = CreateKeychainStage.splash,
});

@override
bool get isRegistrationFlow => true;

@override
List<Object?> get props => [stage];
}

final class FinishAccountCreationStep extends RegistrationStep {
const FinishAccountCreationStep();

@override
bool get isRegistrationFlow => true;
}

final class WalletLinkStep extends RegistrationStep {
Expand All @@ -52,6 +65,9 @@ final class WalletLinkStep extends RegistrationStep {
this.stage = WalletLinkStage.intro,
});

@override
bool get isRegistrationFlow => true;

@override
List<Object?> get props => [stage];
}
Expand Down

0 comments on commit 2652655

Please sign in to comment.