Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .config/dictionaries/project.dic
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ Utxos
uuidv
varint
Vespr
vers
vite
vitss
vkey
Expand Down
7 changes: 7 additions & 0 deletions catalyst_voices/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ code-generator:

LET gen_code_path = lib/generated/api
LET local_gen_code_path = packages/internal/catalyst_voices_repositories/lib/generated/api/
LET local_gen_db_code_path = packages/internal/catalyst_voices_repositories/test/src/database/migration/catalyst_database/generated/

WORKDIR packages/internal/catalyst_voices_repositories

WORKDIR /frontend

RUN melos l10n
RUN melos build-db-migration
RUN melos build-runner
RUN melos build-runner-repository

Expand All @@ -58,6 +60,11 @@ code-generator:
-o -name "*.drift.dart" \))
SAVE ARTIFACT $generated_file AS LOCAL $generated_file
END

# Save database migration generated files
WORKDIR packages/internal/catalyst_voices_repositories/test/src/database/migration/catalyst_database
SAVE ARTIFACT generated/* AS LOCAL $local_gen_db_code_path
WORKDIR /frontend
ELSE
SAVE ARTIFACT .
END
Expand Down
12 changes: 0 additions & 12 deletions catalyst_voices/apps/voices/lib/app/view/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,9 @@ class _AppState extends State<App> {
BlocProvider<SessionCubit>(
create: (_) => Dependencies.instance.get<SessionCubit>(),
),
BlocProvider<ProposalsCubit>(
create: (_) => Dependencies.instance.get<ProposalsCubit>(),
),
BlocProvider<VotingCubit>(
create: (_) => Dependencies.instance.get<VotingCubit>(),
),
BlocProvider<CampaignBuilderCubit>(
create: (_) => Dependencies.instance.get<CampaignBuilderCubit>(),
),
BlocProvider<WorkspaceBloc>(
create: (context) => Dependencies.instance.get<WorkspaceBloc>(),
),
BlocProvider<DiscoveryCubit>(
create: (context) => Dependencies.instance.get<DiscoveryCubit>(),
),
BlocProvider<CategoryDetailCubit>(
create: (_) => Dependencies.instance.get<CategoryDetailCubit>(),
),
Expand Down
11 changes: 5 additions & 6 deletions catalyst_voices/apps/voices/lib/configs/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,13 @@ Future<BootstrapArgs> bootstrap({
fromTo: DateRange(from: startConfigTimestamp, to: endConfigTimestamp),
);

final runtimeProfiler = CatalystRuntimeProfiler(profiler)..start(at: bootstrapStartTimestamp);

await Dependencies.instance.init(
config: config,
environment: environment,
loggingService: _loggingService,
reportingService: _reportingService,
profiler: profiler,
startupProfiler: startupProfiler,
runtimeProfiler: runtimeProfiler,
);

final router = buildAppRouter(initialLocation: initialLocation);
Expand Down Expand Up @@ -216,14 +213,16 @@ Future<void> registerDependencies({
/// - [CatalystNoopProfiler] for debug mode (no overhead)
CatalystProfiler _createProfiler(AppConfig config) {
if (kProfileMode) {
return CatalystDeveloperProfiler.fromConfig(config.developerProfiler);
return config.profiler.console
? const CatalystProfiler.console()
: CatalystProfiler.developer(config.profiler);
}

if (_shouldUseSentry) {
return const CatalystSentryProfiler();
return const CatalystProfiler.sentry();
}

return const CatalystNoopProfiler();
return const CatalystProfiler.noop();
}

void _debugPrintStressTest() {
Expand Down
30 changes: 19 additions & 11 deletions catalyst_voices/apps/voices/lib/dependency/dependencies.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ final class Dependencies extends DependencyProvider {
required ReportingService reportingService,
CatalystProfiler? profiler,
CatalystStartupProfiler? startupProfiler,
CatalystRuntimeProfiler? runtimeProfiler,
}) async {
DependencyProvider.instance = this;

Expand All @@ -56,9 +55,6 @@ final class Dependencies extends DependencyProvider {
if (startupProfiler != null) {
registerSingleton(startupProfiler);
}
if (runtimeProfiler != null) {
registerSingleton(runtimeProfiler);
}

_registerStorages();
_registerUtils();
Expand Down Expand Up @@ -113,20 +109,18 @@ final class Dependencies extends DependencyProvider {
blockchainConfig: get<AppConfig>().blockchain,
);
})
..registerLazySingleton<ProposalsCubit>(
..registerFactory<ProposalsCubit>(
() => ProposalsCubit(
get<UserService>(),
get<CampaignService>(),
get<ProposalService>(),
),
)
..registerLazySingleton<VotingCubit>(
..registerFactory<VotingCubit>(
() => VotingCubit(
get<UserService>(),
get<CampaignService>(),
get<ProposalService>(),
get<VotingBallotBuilder>(),
get<VotingService>(),
),
)
// TODO(LynxLynxx): add repository for campaign management
Expand Down Expand Up @@ -249,10 +243,11 @@ final class Dependencies extends DependencyProvider {
return BlockchainRepository(get<ApiServices>());
})
..registerLazySingleton<SignedDocumentManager>(() {
final profiler = get<CatalystProfiler>();
return SignedDocumentManager(
brotli: const CatalystBrotliCompressor(),
zstd: const CatalystZstdCompressor(),
profiler: get<CatalystRuntimeProfiler>(),
profiler: profiler is CatalystConsoleProfiler ? profiler : const CatalystNoopProfiler(),
);
})
..registerLazySingleton<DatabaseDraftsDataSource>(() {
Expand All @@ -263,6 +258,7 @@ final class Dependencies extends DependencyProvider {
..registerLazySingleton<DatabaseDocumentsDataSource>(() {
return DatabaseDocumentsDataSource(
get<CatalystDatabase>(),
get<CatalystProfiler>(),
);
})
..registerLazySingleton<DocumentFavoriteSource>(() {
Expand All @@ -276,9 +272,16 @@ final class Dependencies extends DependencyProvider {
get<SignedDocumentManager>(),
);
})
..registerLazySingleton<CampaignRepository>(CampaignRepository.new)
..registerLazySingleton<CampaignRepository>(
() {
return CampaignRepository(
get<DatabaseDocumentsDataSource>(),
);
},
)
..registerLazySingleton<DocumentRepository>(() {
return DocumentRepository(
get<CatalystDatabase>(),
get<DatabaseDraftsDataSource>(),
get<DatabaseDocumentsDataSource>(),
get<CatGatewayDocumentDataSource>(),
Expand Down Expand Up @@ -400,6 +403,7 @@ final class Dependencies extends DependencyProvider {
get<SignerService>(),
get<ActiveCampaignObserver>(),
get<CastedVotesObserver>(),
get<VotingBallotBuilder>(),
);
});
registerLazySingleton<CommentService>(() {
Expand Down Expand Up @@ -520,6 +524,7 @@ final class Dependencies extends DependencyProvider {
get<SyncStatsStorage>(),
get<DocumentsService>(),
get<CampaignService>(),
get<CatalystProfiler>(),
);
},
dispose: (manager) async => manager.dispose(),
Expand All @@ -542,7 +547,10 @@ final class Dependencies extends DependencyProvider {
dispose: (observer) async => observer.dispose(),
);
registerLazySingleton<CastedVotesObserver>(CastedVotesObserverImpl.new);
registerLazySingleton<VotingBallotBuilder>(VotingBallotLocalBuilder.new);
registerLazySingleton<VotingBallotBuilder>(
VotingBallotLocalBuilder.new,
dispose: (builder) => builder.dispose(),
);

// Not a singleton
registerFactory<RegistrationStatusPoller>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ class CardInformation extends StatelessWidget {
padding: padding,
children: [
CategoryProposalsDetailsCard(
categoryId: category.id,
categoryRef: category.ref,
categoryName: category.formattedName,
categoryProposalsCount: category.proposalsCount,
categoryFinalProposalsCount: category.finalProposalsCount,
),
const SizedBox(height: 16),
Offstage(
offstage: !isActiveProposer,
child: CreateProposalCard(
categoryId: category.id,
categoryRef: category.ref,
categoryName: category.formattedName,
categoryDos: category.dos,
categoryDonts: category.donts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CategoryCompactDetailView extends StatelessWidget {
_CategoryBrief(
categoryName: category.formattedName,
categoryDescription: category.description,
categoryRef: category.id,
categoryRef: category.ref,
),
FundsDetailCard(
allFunds: category.availableFunds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class CategoryDetailView extends StatelessWidget {
_CategoryBrief(
categoryName: category.formattedName,
categoryDescription: category.description,
categoryRef: category.id,
categoryRef: category.ref,
image: category.image,
proposalCount: category.proposalsCount,
finalProposalsCount: category.finalProposalsCount,
),
const SizedBox(height: 64),
FundsDetailCard(
Expand All @@ -59,14 +59,14 @@ class _CategoryBrief extends StatelessWidget {
final String categoryDescription;
final SignedDocumentRef categoryRef;
final SvgGenImage image;
final int proposalCount;
final int finalProposalsCount;

const _CategoryBrief({
required this.categoryName,
required this.categoryDescription,
required this.categoryRef,
required this.image,
required this.proposalCount,
required this.finalProposalsCount,
});

@override
Expand Down Expand Up @@ -98,7 +98,7 @@ class _CategoryBrief extends StatelessWidget {
categoryName: categoryName,
categoryDescription: categoryDescription,
categoryRef: categoryRef,
showViewAllButton: proposalCount > 0,
showViewAllButton: finalProposalsCount > 0,
),
),
],
Expand Down
31 changes: 16 additions & 15 deletions catalyst_voices/apps/voices/lib/pages/category/category_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import 'package:flutter/material.dart';
import 'package:skeletonizer/skeletonizer.dart';

class CategoryPage extends StatefulWidget {
final SignedDocumentRef categoryId;
final SignedDocumentRef categoryRef;

const CategoryPage({super.key, required this.categoryId});
const CategoryPage({super.key, required this.categoryRef});

@override
State<CategoryPage> createState() => _CategoryPageState();
Expand Down Expand Up @@ -106,6 +106,8 @@ class _CategoryDetailContent extends StatelessWidget {

@override
Widget build(BuildContext context) {
// TODO(damian-molinski): refactor it into single class object in category_detail_state.dart
// and do not rely on context.select<SessionCubit> here.
return BlocSelector<
CategoryDetailCubit,
CategoryDetailState,
Expand All @@ -114,7 +116,7 @@ class _CategoryDetailContent extends StatelessWidget {
selector: (state) {
return (
show: state.isLoading,
data: state.category ?? CampaignCategoryDetailsViewModel.placeholder(),
data: state.selectedCategoryDetails ?? CampaignCategoryDetailsViewModel.placeholder(),
);
},
builder: (context, state) {
Expand All @@ -139,9 +141,9 @@ class _CategoryDetailContent extends StatelessWidget {
}

class _CategoryDetailError extends StatelessWidget {
final SignedDocumentRef categoryId;
final SignedDocumentRef categoryRef;

const _CategoryDetailError({required this.categoryId});
const _CategoryDetailError({required this.categoryRef});

@override
Widget build(BuildContext context) {
Expand All @@ -165,7 +167,7 @@ class _CategoryDetailError extends StatelessWidget {
? null
: () {
unawaited(
context.read<CategoryDetailCubit>().getCategoryDetail(categoryId),
context.read<CategoryDetailCubit>().getCategoryDetail(categoryRef),
);
},
),
Expand All @@ -187,7 +189,7 @@ class _CategoryPageState extends State<CategoryPage> {
children: [
const _CategoryDetailContent(),
_CategoryDetailError(
categoryId: widget.categoryId,
categoryRef: widget.categoryRef,
),
].constrainedDelegate(),
),
Expand All @@ -198,9 +200,9 @@ class _CategoryPageState extends State<CategoryPage> {
void didUpdateWidget(CategoryPage oldWidget) {
super.didUpdateWidget(oldWidget);

if (widget.categoryId != oldWidget.categoryId) {
if (widget.categoryRef != oldWidget.categoryRef) {
unawaited(
context.read<CategoryDetailCubit>().getCategoryDetail(widget.categoryId),
context.read<CategoryDetailCubit>().getCategoryDetail(widget.categoryRef),
);
}
}
Expand All @@ -215,17 +217,16 @@ class _CategoryPageState extends State<CategoryPage> {
@override
void initState() {
super.initState();
unawaited(context.read<CategoryDetailCubit>().getCategories());
unawaited(
context.read<CategoryDetailCubit>().getCategoryDetail(widget.categoryId),
);
_listenForProposalRef(context.read<CategoryDetailCubit>());
final cubit = context.read<CategoryDetailCubit>()..watchActiveCampaignCategories();
unawaited(cubit.getCategoryDetail(widget.categoryRef));
_listenForProposalRef(cubit);
}

// TODO(damian-molinski): refactor it to signal pattern
void _listenForProposalRef(CategoryDetailCubit cubit) {
// listen for updates
_categoryRefSub = cubit.stream
.map((event) => event.category?.id)
.map((event) => event.selectedCategoryRef)
.distinct()
.listen(_onCategoryRefChanged);
}
Expand Down
Loading