Skip to content

Commit

Permalink
Merge branch 'main' into feat/norns-endpoints-stub
Browse files Browse the repository at this point in the history
  • Loading branch information
apskhem authored Nov 7, 2024
2 parents 55b4ac1 + ac0ae5b commit 1c8613e
Show file tree
Hide file tree
Showing 27 changed files with 281 additions and 136 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 Expand Up @@ -107,6 +105,7 @@ class _DeleteKeychainDialogState extends State<DeleteKeychainDialog> {
width: 300,
child: VoicesTextField(
controller: _textEditingController,
onFieldSubmitted: _removeKeychain,
decoration: VoicesTextFieldDecoration(
errorText: _errorText,
errorMaxLines: 2,
Expand All @@ -124,7 +123,7 @@ class _DeleteKeychainDialogState extends State<DeleteKeychainDialog> {
children: [
VoicesFilledButton(
backgroundColor: Theme.of(context).colors.iconsError,
onTap: () async => _onRemoveKeychainTap(),
onTap: _removeKeychain,
child: Text(context.l10n.delete),
),
const SizedBox(width: 8),
Expand All @@ -142,14 +141,17 @@ class _DeleteKeychainDialogState extends State<DeleteKeychainDialog> {
);
}

Future<void> _onRemoveKeychainTap() async {
if (_textEditingController.text ==
context.l10n.deleteKeychainDialogRemovingPhrase) {
void _removeKeychain([String? value]) {
if (_isDeleteConfirmed(value ?? _textEditingController.text)) {
Navigator.pop(context, true);
} else {
setState(() {
_errorText = context.l10n.deleteKeychainDialogErrorText;
});
}
}

bool _isDeleteConfirmed(String value) {
return value == context.l10n.deleteKeychainDialogRemovingPhrase;
}
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ final class LoginEmailTextFiled extends StatelessWidget {
return VoicesEmailTextField(
key: emailInputKey,
onChanged: (email) => _onEmailChanged(context, email),
onFieldSubmitted: (email) => _onEmailChanged(context, email),
);
},
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:async';

import 'package:catalyst_voices/pages/registration/recover/bloc_recover_builder.dart';
import 'package:catalyst_voices/pages/registration/widgets/wallet_connection_status.dart';
import 'package:catalyst_voices/pages/registration/widgets/wallet_summary.dart';
Expand Down Expand Up @@ -33,31 +31,20 @@ class AccountDetailsPanel extends StatelessWidget {
style: theme.textTheme.titleMedium?.copyWith(color: textColor),
),
const SizedBox(height: 24),
Expanded(
const Expanded(
child: SingleChildScrollView(
child: _BlocAccountSummery(
onRetry: () => unawaited(_retryAccountRestore(context)),
),
child: _BlocAccountSummery(),
),
),
const SizedBox(height: 24),
const _BlocNavigation(),
],
);
}

Future<void> _retryAccountRestore(BuildContext context) async {
final recover = RegistrationCubit.of(context).recover;
await recover.recoverAccount();
}
}

class _BlocAccountSummery extends StatelessWidget {
final VoidCallback? onRetry;

const _BlocAccountSummery({
this.onRetry,
});
const _BlocAccountSummery();

@override
Widget build(BuildContext context) {
Expand All @@ -71,10 +58,7 @@ class _BlocAccountSummery extends StatelessWidget {
walletSummary: value.walletSummary,
),
Failure<AccountSummaryData, LocalizedException>(:final value) =>
_RecoverAccountFailure(
exception: value,
onRetry: onRetry,
),
_RecoverAccountFailure(exception: value),
_ => const Center(child: VoicesCircularProgressIndicator()),
};
},
Expand Down Expand Up @@ -117,18 +101,19 @@ class _RecoveredAccountSummary extends StatelessWidget {

class _RecoverAccountFailure extends StatelessWidget {
final LocalizedException exception;
final VoidCallback? onRetry;

const _RecoverAccountFailure({
required this.exception,
this.onRetry,
});

@override
Widget build(BuildContext context) {
return VoicesErrorIndicator(
message: exception.message(context),
onRetry: onRetry,
onRetry: () async {
final recover = RegistrationCubit.of(context).recover;
await recover.recoverAccount();
},
);
}
}
Expand Down Expand Up @@ -185,8 +170,12 @@ class _Navigation extends StatelessWidget {
),
const SizedBox(height: 10),
VoicesTextButton(
onTap: () => RegistrationCubit.of(context).previousStep(),
child: Text(context.l10n.back),
onTap: () async {
final cubit = RegistrationCubit.of(context);
await cubit.recover.reset();
cubit.previousStep();
},
child: Text(context.l10n.recoverDifferentKeychain),
),
],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class _UnlockPasswordPanelState extends State<UnlockPasswordPanel> {
),
const SizedBox(height: 22),
_BlocNavigation(
onNextTap: _createKeychain,
onBackTap: _clearPasswordAndGoBack,
),
],
Expand All @@ -74,6 +75,16 @@ class _UnlockPasswordPanelState extends State<UnlockPasswordPanel> {
RegistrationCubit.of(context).recover.setConfirmPassword(confirmPassword);
}

Future<void> _createKeychain() async {
final cubit = RegistrationCubit.of(context);

final success = await cubit.recover.createKeychain();

if (success) {
cubit.nextStep();
}
}

void _clearPasswordAndGoBack() {
final registration = RegistrationCubit.of(context);

Expand Down Expand Up @@ -124,9 +135,11 @@ class _BlocUnlockPasswordForm extends StatelessWidget {
}

class _BlocNavigation extends StatelessWidget {
final VoidCallback onNextTap;
final VoidCallback onBackTap;

const _BlocNavigation({
required this.onNextTap,
required this.onBackTap,
});

Expand All @@ -138,6 +151,7 @@ class _BlocNavigation extends StatelessWidget {
builder: (context, state) {
return RegistrationBackNextNavigation(
isNextEnabled: state,
onNextTap: onNextTap,
onBackTap: onBackTap,
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class RolesSummaryPanel extends StatelessWidget {
onTap: () {
RegistrationCubit.of(context).nextStep();
},
child: Text(context.l10n.walletLinkRoleSummaryButton),
child: Text(context.l10n.reviewRegistrationTransaction),
),
const SizedBox(height: 10),
VoicesTextButton(
Expand Down
2 changes: 2 additions & 0 deletions catalyst_voices/apps/voices/lib/pages/voting/voting_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class _UnlockedHeaderActions extends StatelessWidget {
suffixIcon:
VoicesAssets.icons.arrowTriangleDown.buildIcon(size: 16),
),
onFieldSubmitted: (value) {},
),
),
const SizedBox(width: 16),
Expand All @@ -132,6 +133,7 @@ class _UnlockedHeaderActions extends StatelessWidget {
hintText: 'Search proposals',
prefixIcon: VoicesAssets.icons.search.buildIcon(),
),
onFieldSubmitted: (value) {},
),
),
IconButton(
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 @@ -5,10 +5,12 @@ import 'package:flutter/material.dart';
final class VoicesEmailTextField extends StatelessWidget {
/// Emits new value when widget input changes
final ValueChanged<String>? onChanged;
final ValueChanged<String> onFieldSubmitted;

const VoicesEmailTextField({
super.key,
this.onChanged,
required this.onFieldSubmitted,
});

@override
Expand All @@ -18,6 +20,7 @@ final class VoicesEmailTextField extends StatelessWidget {
keyboardType: TextInputType.emailAddress,
textInputAction: TextInputAction.next,
onChanged: onChanged,
onFieldSubmitted: onFieldSubmitted,
decoration: VoicesTextFieldDecoration(
labelText: l10n.emailLabelText,
hintText: l10n.emailHintText,
Expand Down
Loading

0 comments on commit 1c8613e

Please sign in to comment.