Skip to content

Commit

Permalink
Merge pull request #366 from hypha-dao/feat/implement-proposal-public…
Browse files Browse the repository at this point in the history
…ation

feat: implement proposal publication
  • Loading branch information
n13 authored Nov 19, 2024
2 parents cb5f8a6 + d3447f9 commit ed4ea92
Show file tree
Hide file tree
Showing 24 changed files with 630 additions and 286 deletions.
6 changes: 5 additions & 1 deletion lib/core/di/bloc_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ void _registerBlocsModule() {
));

_registerFactoryWithParams<ProposalCreationBloc, List<DaoData>, void>(
(daos, _) => ProposalCreationBloc(daos),
(daos, _) => ProposalCreationBloc(
daos,
_getIt<PublishProposalUseCase>(),
_getIt<ErrorHandlerManager>(),
),
);
}
1 change: 1 addition & 0 deletions lib/core/di/di_setup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import 'package:hypha_wallet/ui/profile/usecases/set_bio_use_case.dart';
import 'package:hypha_wallet/ui/profile/usecases/set_image_use_case.dart';
import 'package:hypha_wallet/ui/profile/usecases/set_name_use_case.dart';
import 'package:hypha_wallet/ui/proposals/creation/interactor/proposal_creation_bloc.dart';
import 'package:hypha_wallet/ui/proposals/creation/usecases/publish_proposal_use_case.dart';
import 'package:hypha_wallet/ui/proposals/details/usecases/get_proposal_details_use_case.dart';
import 'package:hypha_wallet/ui/proposals/filter/interactor/filter_proposals_bloc.dart';
import 'package:hypha_wallet/ui/proposals/filter/usecases/aggregate_dao_proposal_counts_use_case.dart';
Expand Down
2 changes: 2 additions & 0 deletions lib/core/di/usecases_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,6 @@ void _registerUseCasesModule() {
_registerFactory(() => GetProposalDetailsUseCase(_getIt<AuthRepository>(), _getIt<ProposalRepository>()));

_registerFactory(() => AggregateDaoProposalCountsUseCase());

_registerFactory(() => PublishProposalUseCase(_getIt<AuthRepository>(), _getIt<EOSService>(), _getIt<RemoteConfigService>()));
}
12 changes: 12 additions & 0 deletions lib/core/extension/proposal_creation_model_extension.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:hypha_wallet/core/network/models/proposal_creation_model.dart';

extension ProposalCreationModelExtension on ProposalCreationModel {
String proposalTypeToString() {
switch (type) {
case ProposalType.policy:
return 'policy';
default:
return 'unknown';
}
}
}
65 changes: 64 additions & 1 deletion lib/core/extension/string_extension.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:convert';

extension NullableStringExtension on String? {
bool get isNullOrEmpty => this == null || this!.isEmpty;
}
Expand All @@ -9,4 +11,65 @@ extension StringExtension on String {
final List<String> parts = split(' ');
return double.parse(parts[0]);
}
}

String get toMarkdown {
late List<dynamic> data;
try {
data = jsonDecode(this);
} catch (e) {
throw FormatException('Invalid JSON string: $e');
}

final StringBuffer output = StringBuffer();
int orderedListCount = 0;
bool previousWasOrdered = false;

for (int i = 0; i < data.length; i++) {
final element = data[i];
if (element['insert'] == null) continue;

String text = element['insert'].trim();
final Map<String, dynamic>? attributes = element['attributes'];

if (attributes != null) {
if (attributes['italic'] == true) {
text = '_${text}_';
}
if (attributes['bold'] == true) {
text = '**$text**';
}
if (attributes.containsKey('link')) {
final String link = attributes['link'];
text = '**[$text]($link)**';
}
}

if (i + 1 < data.length && data[i + 1]['insert'] == '\n' && data[i + 1]['attributes'] != null) {
final Map<String, dynamic> nextAttributes = data[i + 1]['attributes'];

if (nextAttributes['list'] == 'bullet') {
text = '* $text';
previousWasOrdered = false;
} else if (nextAttributes['list'] == 'ordered') {
if (!previousWasOrdered) {
orderedListCount = 1;
} else {
orderedListCount++;
}
text = '$orderedListCount. $text';
previousWasOrdered = true;
} else if (nextAttributes['blockquote'] == true) {
text = '> $text';
}

i++;
} else {
previousWasOrdered = false;
}

output.write('$text\n');
}

return output.toString();
}
}
7 changes: 1 addition & 6 deletions lib/core/network/api/actions/vote_action_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ class VoteActionFactory {
return EOSAction()
..account = daoContract
..name = 'vote'
..data = {
'voter': voter,
'proposal_id': proposalId,
'vote': vote.name,
'notes': ''
};
..data = {'voter': voter, 'proposal_id': proposalId, 'vote': vote.name, 'notes': ''};
}
}
2 changes: 1 addition & 1 deletion lib/core/network/models/base_proposal_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:json_annotation/json_annotation.dart';
@JsonSerializable()
abstract class BaseProposalModel {
@JsonKey(name: 'docId')
final String id;
final String? id;

DaoData? dao;

Expand Down
16 changes: 7 additions & 9 deletions lib/core/network/models/proposal_creation_model.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import 'package:hypha_wallet/core/network/models/dao_data_model.dart';
import 'package:hypha_wallet/core/network/models/base_proposal_model.dart';

class ProposalCreationModel {
final String? id;
final String? title;
enum ProposalType { policy }

class ProposalCreationModel extends BaseProposalModel {
final String? details;
final DaoData? dao;
final String? type;
final ProposalType type;

ProposalCreationModel(
{this.type, this.dao, this.id, this.title, this.details});
ProposalCreationModel({super.id, super.title, this.details, super.dao, this.type = ProposalType.policy});

ProposalCreationModel copyWith(Map<String, dynamic> updates) {
return ProposalCreationModel(
id: updates.containsKey('id') ? updates['id'] : id,
title: updates.containsKey('title') ? updates['title'] : title,
details: updates.containsKey('details') ? updates['details'] : details,
dao: updates.containsKey('dao') ? updates['dao'] : dao,
details: updates.containsKey('details') ? updates['details'] : details,
type: updates.containsKey('type') ? updates['type'] : type,
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/core/network/models/proposal_details_model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/core/network/models/proposal_model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ed4ea92

Please sign in to comment.