Skip to content

Commit

Permalink
feat(cat-voices): account restored (#997)
Browse files Browse the repository at this point in the history
* feat: account restored panel

* docs: check local keychains

* feat: exit dialog
  • Loading branch information
damian-molinski authored Oct 14, 2024
1 parent f7de3d2 commit ba12cd3
Show file tree
Hide file tree
Showing 14 changed files with 315 additions and 90 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:catalyst_voices/pages/registration/recover/seed_phrase/account_details_panel.dart';
import 'package:catalyst_voices/pages/registration/recover/seed_phrase/restored_panel.dart';
import 'package:catalyst_voices/pages/registration/recover/seed_phrase/seed_phrase_input_panel.dart';
import 'package:catalyst_voices/pages/registration/recover/seed_phrase/seed_phrase_instructions_panel.dart';
import 'package:catalyst_voices/pages/registration/recover/seed_phrase/unlock_password_instructions_panel.dart';
import 'package:catalyst_voices/pages/registration/recover/seed_phrase/unlock_password_panel.dart';
import 'package:catalyst_voices/pages/registration/widgets/placeholder_panel.dart';
import 'package:catalyst_voices_models/catalyst_voices_models.dart';
import 'package:flutter/material.dart';

Expand All @@ -25,7 +25,7 @@ class RecoverSeedPhrasePanel extends StatelessWidget {
RecoverSeedPhraseStage.unlockPasswordInstructions =>
const UnlockPasswordInstructionsPanel(),
RecoverSeedPhraseStage.unlockPassword => const UnlockPasswordPanel(),
RecoverSeedPhraseStage.success => const PlaceholderPanel(),
RecoverSeedPhraseStage.success => const RestoredPanel(),
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import 'package:catalyst_voices/routes/routes.dart';
import 'package:catalyst_voices/widgets/buttons/voices_filled_button.dart';
import 'package:catalyst_voices/widgets/buttons/voices_text_button.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 RestoredPanel extends StatelessWidget {
const RestoredPanel({super.key});

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

final textTheme = theme.textTheme;
final colors = theme.colors;

return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const SizedBox(height: 24),
Text(
context.l10n.recoverySuccessTitle,
style: textTheme.titleLarge?.copyWith(
color: colors.textOnPrimaryLevel1,
),
),
const SizedBox(height: 24),
Text(
context.l10n.recoverySuccessSubtitle,
style: textTheme.bodyMedium?.copyWith(
color: colors.textOnPrimaryLevel0,
),
),
const Spacer(),
const SizedBox(height: 10),
VoicesFilledButton(
onTap: () => _redirectToDashboard(context),
child: Text(context.l10n.recoverySuccessGoToDashboard),
),
const SizedBox(height: 10),
VoicesTextButton(
onTap: () => _redirectToMyAccount(context),
child: Text(context.l10n.recoverySuccessGoAccount),
),
],
);
}

void _redirectToDashboard(BuildContext context) {
Navigator.of(context).pop();
const DiscoveryRoute().go(context);
}

void _redirectToMyAccount(BuildContext context) {
Navigator.of(context).pop();
const AccountRoute().go(context);
}
}
44 changes: 37 additions & 7 deletions catalyst_voices/lib/pages/registration/registration_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ 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';
Expand Down Expand Up @@ -55,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: BlocSelector<RegistrationCubit, RegistrationState, bool>(
selector: (state) => state.step is! AccountCompletedStep,
Expand All @@ -71,21 +76,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
Expand Up @@ -16,7 +16,10 @@ class AccountRoleDialog extends StatelessWidget {
super.key,
});

static Future<void> show(BuildContext context, AccountRole role) async {
static Future<void> show(
BuildContext context, {
required AccountRole role,
}) async {
return VoicesDialog.show<void>(
context: context,
builder: (context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class _BlocRolesChooserContainer extends StatelessWidget {
onLearnMore: (role) async {
await AccountRoleDialog.show(
context,
role,
role: role,
);
},
);
Expand Down
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,
);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ final class RecoverCubit extends Cubit<RecoverStateData>
}
}

// Note. this function will have more sense when we'll implement
// multi account feature. Then we can have multiple keychains and lookup
// those already stored locally.
@override
Future<void> checkLocalKeychains() async {
// TODO(damian-molinski): to be implemented
Expand Down
Loading

0 comments on commit ba12cd3

Please sign in to comment.