Skip to content

Commit

Permalink
Merge branch 'main' into feat/config-api
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenj authored Oct 15, 2024
2 parents 0613100 + ba12cd3 commit 939df7e
Show file tree
Hide file tree
Showing 67 changed files with 2,008 additions and 497 deletions.
22 changes: 17 additions & 5 deletions catalyst_voices/lib/app/view/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,34 @@ import 'package:catalyst_voices_blocs/catalyst_voices_blocs.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

final class App extends StatelessWidget {
final class App extends StatefulWidget {
final RouterConfig<Object> routerConfig;

const App({
super.key,
required this.routerConfig,
});

@override
State<App> createState() => _AppState();
}

class _AppState extends State<App> {
/// A singleton bloc that manages the user session.
final SessionBloc _sessionBloc = Dependencies.instance.get();

@override
void initState() {
super.initState();
_sessionBloc.add(const RestoreSessionEvent());
}

@override
Widget build(BuildContext context) {
return MultiBlocProvider(
providers: _multiBlocProviders(),
child: AppContent(
routerConfig: routerConfig,
routerConfig: widget.routerConfig,
),
);
}
Expand All @@ -30,9 +44,7 @@ final class App extends StatelessWidget {
BlocProvider<LoginBloc>(
create: (_) => Dependencies.instance.get<LoginBloc>(),
),
BlocProvider<SessionBloc>(
create: (_) => Dependencies.instance.get<SessionBloc>(),
),
BlocProvider<SessionBloc>.value(value: _sessionBloc),
];
}
}
1 change: 1 addition & 0 deletions catalyst_voices/lib/common/ext/ext.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export 'brand_ext.dart';
export 'space_ext.dart';
export 'string_ext.dart';
9 changes: 9 additions & 0 deletions catalyst_voices/lib/common/ext/string_ext.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
extension StringExt on String {
String capitalize() {
if (isNotEmpty) {
return '${this[0].toUpperCase()}${substring(1).toLowerCase()}';
} else {
return '';
}
}
}
4 changes: 2 additions & 2 deletions catalyst_voices/lib/configs/app_bloc_observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import 'package:catalyst_voices_shared/catalyst_voices_shared.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

final class AppBlocObserver extends BlocObserver {
AppBlocObserver();

final _logger = Logger('AppBlocObserver');

AppBlocObserver();

@override
void onChange(
BlocBase<dynamic> bloc,
Expand Down
14 changes: 13 additions & 1 deletion catalyst_voices/lib/dependency/dependencies.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ final class Dependencies extends DependencyProvider {
authenticationRepository: get(),
),
)
..registerLazySingleton<SessionBloc>(SessionBloc.new)
..registerLazySingleton<SessionBloc>(
() => SessionBloc(get<Keychain>()),
)
// Factory will rebuild it each time needed
..registerFactory<RegistrationCubit>(() {
return RegistrationCubit(
Expand Down Expand Up @@ -59,9 +61,19 @@ final class Dependencies extends DependencyProvider {
);
registerLazySingleton<Downloader>(Downloader.new);
registerLazySingleton<CatalystCardano>(() => CatalystCardano.instance);

registerLazySingleton<KeyDerivation>(KeyDerivation.new);
registerLazySingleton<Keychain>(
() => Keychain(
get<KeyDerivation>(),
get<Vault>(),
),
);
registerLazySingleton<RegistrationService>(
() => RegistrationService(
get<TransactionConfigRepository>(),
get<Keychain>(),
get<KeyDerivation>(),
get<CatalystCardano>(),
),
);
Expand Down
101 changes: 21 additions & 80 deletions catalyst_voices/lib/pages/account/account_page.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import 'dart:async';

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/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';
import 'package:catalyst_voices_localization/catalyst_voices_localization.dart';
import 'package:catalyst_voices_models/catalyst_voices_models.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

final class AccountPage extends StatelessWidget {
const AccountPage({super.key});
Expand All @@ -21,8 +25,9 @@ final class AccountPage extends StatelessWidget {
body: SingleChildScrollView(
padding: const EdgeInsets.all(32),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const _Header(),
const AccountPageHeader(),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Column(
Expand All @@ -39,19 +44,7 @@ final class AccountPage extends StatelessWidget {
AccountRole.drep,
],
defaultRole: AccountRole.voter,
onRemoveKeychain: () async {
final confirmed =
await DeleteKeychainDialog.show(context);
if (confirmed && context.mounted) {
// TODO(Jakub): remove keychain
await VoicesDialog.show<void>(
context: context,
builder: (context) {
return const KeychainDeletedDialog();
},
);
}
},
onRemoveKeychain: () => unawaited(_removeKeychain(context)),
),
],
),
Expand All @@ -61,73 +54,21 @@ final class AccountPage extends StatelessWidget {
),
);
}
}

class _Header extends StatelessWidget {
const _Header();
// Note. probably should redirect somewhere.
Future<void> _removeKeychain(BuildContext context) async {
final confirmed = await DeleteKeychainDialog.show(context);

@override
Widget build(BuildContext context) {
return DecoratedBox(
decoration: BoxDecoration(
image: DecorationImage(
image: CatalystImage.asset(
VoicesAssets.images.accountBg.path,
).image,
fit: BoxFit.cover,
),
),
child: SizedBox(
width: double.infinity,
height: 350,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(
top: 24,
left: 8,
),
child: VoicesIconButton.filled(
onTap: () {
GoRouter.of(context).pop();
},
style: ButtonStyle(
backgroundColor: WidgetStateProperty.all(
Theme.of(context).colors.elevationsOnSurfaceNeutralLv1White,
),
foregroundColor: WidgetStateProperty.all(
Theme.of(context).colors.iconsForeground,
),
),
child: VoicesAssets.icons.arrowNarrowLeft.buildIcon(),
),
),
const Spacer(),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 32),
child: Text(
context.l10n.myAccountProfileKeychain,
style: Theme.of(context).textTheme.displayMedium?.copyWith(
color: Colors.white,
),
),
),
const SizedBox(height: 4),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 32),
child: Text(
context.l10n.yourCatalystKeychainAndRoleRegistration,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: Colors.white,
),
),
),
const SizedBox(height: 48),
],
),
),
);
if (confirmed && context.mounted) {
context.read<SessionBloc>().add(const RemoveKeychainSessionEvent());

await VoicesDialog.show<void>(
context: context,
builder: (context) {
return const KeychainDeletedDialog();
},
);
}
}
}

Expand Down
99 changes: 99 additions & 0 deletions catalyst_voices/lib/pages/account/account_page_header.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import 'package:catalyst_voices/routes/routes.dart';
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';
import 'package:go_router/go_router.dart';

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

@override
Widget build(BuildContext context) {
return Container(
constraints: const BoxConstraints.tightFor(height: 350),
decoration: BoxDecoration(
image: DecorationImage(
image: CatalystImage.asset(VoicesAssets.images.accountBg.path).image,
fit: BoxFit.cover,
),
),
child: const Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 24),
Padding(
padding: EdgeInsets.only(left: 8),
child: _BackArrowButton(),
),
Spacer(),
Padding(
padding: EdgeInsets.symmetric(horizontal: 32),
child: _TitleText(),
),
SizedBox(height: 4),
Padding(
padding: EdgeInsets.symmetric(horizontal: 32),
child: _SubtitleText(),
),
SizedBox(height: 48),
],
),
);
}
}

class _TitleText extends StatelessWidget {
const _TitleText();

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

return Text(
context.l10n.myAccountProfileKeychain,
style: theme.textTheme.displayMedium?.copyWith(color: Colors.white),
);
}
}

class _SubtitleText extends StatelessWidget {
const _SubtitleText();

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

return Text(
context.l10n.yourCatalystKeychainAndRoleRegistration,
style: theme.textTheme.titleMedium?.copyWith(color: Colors.white),
);
}
}

class _BackArrowButton extends StatelessWidget {
const _BackArrowButton();

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

final backgroundColor = colors.elevationsOnSurfaceNeutralLv1White;
final foregroundColor = colors.iconsForeground;
return VoicesIconButton.filled(
onTap: () {
if (Navigator.of(context).canPop()) {
Navigator.of(context).pop();
} else {
GoRouter.of(context).go(Routes.initialLocation);
}
},
style: ButtonStyle(
backgroundColor: WidgetStateProperty.all(backgroundColor),
foregroundColor: WidgetStateProperty.all(foregroundColor),
),
child: VoicesAssets.icons.arrowNarrowLeft.buildIcon(),
);
}
}
Loading

0 comments on commit 939df7e

Please sign in to comment.