Skip to content

Commit

Permalink
feat: add recovery to unlock dialog (#1027)
Browse files Browse the repository at this point in the history
Co-authored-by: Damian Molinski <[email protected]>
  • Loading branch information
dtscalac and damian-molinski authored Oct 24, 2024
1 parent 2664e53 commit 8794f72
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 16 deletions.
52 changes: 40 additions & 12 deletions catalyst_voices/lib/pages/account/unlock_keychain_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';

import 'package:catalyst_voices/common/error_handler.dart';
import 'package:catalyst_voices/pages/registration/pictures/unlock_keychain_picture.dart';
import 'package:catalyst_voices/pages/registration/registration_dialog.dart';
import 'package:catalyst_voices/pages/registration/widgets/information_panel.dart';
import 'package:catalyst_voices/pages/registration/widgets/registration_stage_message.dart';
import 'package:catalyst_voices/widgets/widgets.dart';
Expand Down Expand Up @@ -60,6 +61,7 @@ class _UnlockKeychainDialogState extends State<UnlockKeychainDialog>
controller: _passwordController,
error: _error,
onUnlock: _onUnlock,
onRecover: _onRecover,
),
);
}
Expand All @@ -86,17 +88,30 @@ class _UnlockKeychainDialogState extends State<UnlockKeychainDialog>
});
}
}

void _onRecover() {
Navigator.of(context).pop();

unawaited(
RegistrationDialog.show(
context,
step: const RecoverMethodStep(),
),
);
}
}

class _UnlockPasswordPanel extends StatelessWidget {
final TextEditingController controller;
final LocalizedException? error;
final VoidCallback onUnlock;
final VoidCallback onRecover;

const _UnlockPasswordPanel({
required this.controller,
required this.error,
required this.onUnlock,
required this.onRecover,
});

@override
Expand All @@ -117,6 +132,7 @@ class _UnlockPasswordPanel extends StatelessWidget {
const Spacer(),
_Navigation(
onUnlock: onUnlock,
onRecover: onRecover,
),
],
);
Expand Down Expand Up @@ -147,27 +163,39 @@ class _UnlockPassword extends StatelessWidget {

class _Navigation extends StatelessWidget {
final VoidCallback onUnlock;
final VoidCallback onRecover;

const _Navigation({
required this.onUnlock,
required this.onRecover,
});

@override
Widget build(BuildContext context) {
return Row(
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: VoicesOutlinedButton(
onTap: () => Navigator.of(context).pop(),
child: Text(context.l10n.continueAsGuest),
),
VoicesFilledButton(
onTap: onUnlock,
child: Text(context.l10n.confirmPassword),
),
const SizedBox(width: 10),
Expanded(
child: VoicesFilledButton(
onTap: onUnlock,
child: Text(context.l10n.confirmPassword),
),
const SizedBox(height: 10),
Row(
children: [
Expanded(
child: VoicesOutlinedButton(
onTap: onRecover,
child: Text(context.l10n.recoverAccount),
),
),
const SizedBox(width: 10),
Expanded(
child: VoicesTextButton(
onTap: () => Navigator.of(context).pop(),
child: Text(context.l10n.continueAsGuest),
),
),
],
),
],
);
Expand Down
21 changes: 17 additions & 4 deletions catalyst_voices/lib/pages/registration/registration_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class RegistrationDialog extends StatefulWidget {
const RegistrationDialog._();
final RegistrationStep? step;

static Future<void> show(BuildContext context) {
const RegistrationDialog._({
required this.step,
});

static Future<void> show(
BuildContext context, {
RegistrationStep? step,
}) {
return VoicesDialog.show(
context: context,
routeSettings: const RouteSettings(name: '/registration'),
builder: (context) => const RegistrationDialog._(),
builder: (context) => RegistrationDialog._(step: step),
barrierDismissible: false,
);
}
Expand All @@ -34,7 +41,13 @@ class _RegistrationDialogState extends State<RegistrationDialog>
@override
void initState() {
super.initState();
_cubit.recoverProgress();

final step = widget.step;
if (step != null) {
_cubit.goToStep(step);
} else {
_cubit.recoverProgress();
}
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ final class RegistrationCubit extends Cubit<RegistrationState>
return super.close();
}

void goToStep(RegistrationStep step) {
_goToStep(step);
}

void recoverProgress() {
final progress = _progressNotifier.value;
final keychainProgress = progress.keychainProgress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1846,6 +1846,12 @@ abstract class VoicesLocalizations {
/// **'Continue recovery process'**
String get recoveryExitConfirmDialogContinue;

/// Refers to the action label for recovering the user account.
///
/// In en, this message translates to:
/// **'Recover account'**
String get recoverAccount;

/// No description provided for @uploadConfirmDialogSubtitle.
///
/// In en, this message translates to:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,9 @@ class VoicesLocalizationsEn extends VoicesLocalizations {
@override
String get recoveryExitConfirmDialogContinue => 'Continue recovery process';

@override
String get recoverAccount => 'Recover account';

@override
String get uploadConfirmDialogSubtitle => 'SWITCH TO FILE UPLOAD';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,9 @@ class VoicesLocalizationsEs extends VoicesLocalizations {
@override
String get recoveryExitConfirmDialogContinue => 'Continue recovery process';

@override
String get recoverAccount => 'Recover account';

@override
String get uploadConfirmDialogSubtitle => 'SWITCH TO FILE UPLOAD';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,10 @@
"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",
"recoverAccount": "Recover account",
"@recoverAccount": {
"description": "Refers to the action label for recovering the user account."
},
"uploadConfirmDialogSubtitle": "SWITCH TO FILE UPLOAD",
"uploadConfirmDialogContent": "Do you want to cancel manual input, and switch to Catalyst key upload?",
"uploadConfirmDialogYesButton": "Yes, switch to Catalyst key upload",
Expand Down

0 comments on commit 8794f72

Please sign in to comment.