Skip to content

Commit

Permalink
fix: redirecting after keychain is deleted (#1133)
Browse files Browse the repository at this point in the history
* fix: redirecting after keychain is deleted

* chore: remove unused class
  • Loading branch information
damian-molinski authored Nov 5, 2024
1 parent 8156dcb commit 4c8c0c0
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 47 deletions.
4 changes: 2 additions & 2 deletions catalyst_voices/apps/voices/lib/configs/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ Future<BootstrapArgs> bootstrap() async {
GoRouter.optionURLReflectsImperativeAPIs = true;
setPathUrlStrategy();

await Dependencies.instance.init();

final router = AppRouter.init(
guards: const [
MilestoneGuard(),
Expand All @@ -96,8 +98,6 @@ Future<BootstrapArgs> bootstrap() async {

Bloc.observer = AppBlocObserver();

await Dependencies.instance.init();

return BootstrapArgs(routerConfig: router);
}

Expand Down
34 changes: 21 additions & 13 deletions catalyst_voices/apps/voices/lib/pages/account/account_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import 'package:catalyst_voices/common/ext/account_role_ext.dart';
import 'package:catalyst_voices/pages/account/account_page_header.dart';
import 'package:catalyst_voices/pages/account/delete_keychain_dialog.dart';
import 'package:catalyst_voices/pages/account/keychain_deleted_dialog.dart';
import 'package:catalyst_voices/routes/routes.dart';
import 'package:catalyst_voices/widgets/buttons/voices_icon_button.dart';
import 'package:catalyst_voices/widgets/buttons/voices_text_button.dart';
import 'package:catalyst_voices/widgets/list/bullet_list.dart';
import 'package:catalyst_voices/widgets/modals/voices_dialog.dart';
import 'package:catalyst_voices_assets/catalyst_voices_assets.dart';
import 'package:catalyst_voices_blocs/catalyst_voices_blocs.dart';
import 'package:catalyst_voices_brands/catalyst_voices_brands.dart';
Expand All @@ -16,9 +16,14 @@ import 'package:catalyst_voices_models/catalyst_voices_models.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

final class AccountPage extends StatelessWidget {
final class AccountPage extends StatefulWidget {
const AccountPage({super.key});

@override
State<AccountPage> createState() => _AccountPageState();
}

class _AccountPageState extends State<AccountPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -44,7 +49,7 @@ final class AccountPage extends StatelessWidget {
AccountRole.drep,
],
defaultRole: AccountRole.voter,
onRemoveKeychain: () => unawaited(_removeKeychain(context)),
onRemoveKeychain: () => unawaited(_removeKeychain()),
),
],
),
Expand All @@ -55,19 +60,22 @@ final class AccountPage extends StatelessWidget {
);
}

// Note. probably should redirect somewhere.
Future<void> _removeKeychain(BuildContext context) async {
Future<void> _removeKeychain() async {
final confirmed = await DeleteKeychainDialog.show(context);
if (!confirmed) {
return;
}

if (confirmed && context.mounted) {
unawaited(context.read<SessionCubit>().removeKeychain());
if (mounted) {
await context.read<SessionCubit>().removeKeychain();
}

if (mounted) {
await KeychainDeletedDialog.show(context);
}

await VoicesDialog.show<void>(
context: context,
builder: (context) {
return const KeychainDeletedDialog();
},
);
if (mounted) {
const DiscoveryRoute().go(context);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ import 'package:catalyst_voices_localization/catalyst_voices_localization.dart';
import 'package:flutter/material.dart';

class DeleteKeychainDialog extends StatefulWidget {
const DeleteKeychainDialog({
super.key,
});
const DeleteKeychainDialog._();

static Future<bool> show(BuildContext context) async {
final result = await VoicesDialog.show<bool>(
context: context,
builder: (context) => const DeleteKeychainDialog(),
builder: (context) => const DeleteKeychainDialog._(),
);

return result ?? false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import 'package:catalyst_voices/widgets/buttons/voices_filled_button.dart';
import 'package:catalyst_voices/widgets/modals/voices_desktop_dialog.dart';
import 'package:catalyst_voices/widgets/widgets.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 KeychainDeletedDialog extends StatelessWidget {
const KeychainDeletedDialog({super.key});
const KeychainDeletedDialog._();

static Future<void> show(BuildContext context) {
return VoicesDialog.show<void>(
context: context,
builder: (context) => const KeychainDeletedDialog._(),
);
}

@override
Widget build(BuildContext context) {
Expand Down
12 changes: 7 additions & 5 deletions catalyst_voices/apps/voices/lib/routes/app_router.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

import 'package:catalyst_voices/routes/guards/route_guard.dart';
import 'package:catalyst_voices/routes/routes.dart';
import 'package:catalyst_voices/routes/routing/routes.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
Expand All @@ -13,6 +14,7 @@ abstract final class AppRouter {

static GoRouter init({
List<RouteGuard> guards = const [],
Listenable? refreshListenable,
}) {
return GoRouter(
navigatorKey: _rootNavigatorKey,
Expand All @@ -21,23 +23,23 @@ abstract final class AppRouter {
observers: [
SentryNavigatorObserver(),
],
refreshListenable: refreshListenable,
routes: Routes.routes,
// always true. We're deciding whether to print
// them or not in LoggingService
debugLogDiagnostics: true,
);
}

static FutureOr<String?> _guard(
static Future<String?> _guard(
BuildContext context,
GoRouterState state,
List<RouteGuard> guards,
) async {
for (final guard in guards) {
final redirect = await guard.redirect(context, state);

if (redirect != null) {
return redirect;
final location = await guard.redirect(context, state);
if (location != null) {
return location;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1348,22 +1348,22 @@ abstract class VoicesLocalizations {
/// **'Dark'**
String get themeDark;

/// A title on keychain deleted dialog
/// No description provided for @keychainDeletedDialogTitle.
///
/// In en, this message translates to:
/// **'Catalyst keychain removed'**
String get keychainDeletedDialogTitle;

/// A subtitle on keychain deleted dialog
/// No description provided for @keychainDeletedDialogSubtitle.
///
/// In en, this message translates to:
/// **'Catalyst keychain removed'**
/// **'Your Catalyst Keychain is removed successfully from this device.'**
String get keychainDeletedDialogSubtitle;

/// An info on keychain deleted dialog
/// No description provided for @keychainDeletedDialogInfo.
///
/// In en, this message translates to:
/// **'Catalyst keychain removed'**
/// **'We reverted this device to Catalyst first use.'**
String get keychainDeletedDialogInfo;

/// No description provided for @registrationCompletedTitle.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -717,10 +717,10 @@ class VoicesLocalizationsEn extends VoicesLocalizations {
String get keychainDeletedDialogTitle => 'Catalyst keychain removed';

@override
String get keychainDeletedDialogSubtitle => 'Catalyst keychain removed';
String get keychainDeletedDialogSubtitle => 'Your Catalyst Keychain is removed successfully from this device.';

@override
String get keychainDeletedDialogInfo => 'Catalyst keychain removed';
String get keychainDeletedDialogInfo => 'We reverted this device to Catalyst first use.';

@override
String get registrationCompletedTitle => 'Catalyst account setup';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -717,10 +717,10 @@ class VoicesLocalizationsEs extends VoicesLocalizations {
String get keychainDeletedDialogTitle => 'Catalyst keychain removed';

@override
String get keychainDeletedDialogSubtitle => 'Catalyst keychain removed';
String get keychainDeletedDialogSubtitle => 'Your Catalyst Keychain is removed successfully from this device.';

@override
String get keychainDeletedDialogInfo => 'Catalyst keychain removed';
String get keychainDeletedDialogInfo => 'We reverted this device to Catalyst first use.';

@override
String get registrationCompletedTitle => 'Catalyst account setup';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -812,17 +812,8 @@
"description": "Refers to a dark theme mode."
},
"keychainDeletedDialogTitle": "Catalyst keychain removed",
"@keychainDeletedDialogTitle": {
"description": "A title on keychain deleted dialog"
},
"keychainDeletedDialogSubtitle": "Catalyst keychain removed",
"@keychainDeletedDialogSubtitle": {
"description": "A subtitle on keychain deleted dialog"
},
"keychainDeletedDialogInfo": "Catalyst keychain removed",
"@keychainDeletedDialogInfo": {
"description": "An info on keychain deleted dialog"
},
"keychainDeletedDialogSubtitle": "Your Catalyst Keychain is removed successfully from this device.",
"keychainDeletedDialogInfo": "We reverted this device to Catalyst first use.",
"registrationCompletedTitle": "Catalyst account setup",
"registrationCompletedSubtitle": "Completed!",
"registrationCompletedSummaryHeader": "Summary",
Expand Down

0 comments on commit 4c8c0c0

Please sign in to comment.