Skip to content

Commit

Permalink
Merge pull request #360 from hypha-dao/chore/refactor-proposal-details
Browse files Browse the repository at this point in the history
refactor: proposal details
  • Loading branch information
Zied-Dahmani authored Nov 8, 2024
2 parents 5771b66 + 2e1e3e6 commit 917adba
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 565 deletions.
95 changes: 0 additions & 95 deletions lib/core/extension/proposal_details_model_extension.dart

This file was deleted.

6 changes: 2 additions & 4 deletions lib/core/network/api/services/proposal_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ class ProposalService {
return _graphQLService.graphQLQuery(network: user.network, query: query);
}

Future<Result<Map<String, dynamic>, HyphaError>> getProposalDetails(
String proposalId, UserProfileData user) async {
final String query =
'{"query":"query proposalDetails(\$docId: String!) { getDocument(docId: \$docId) {__typename docId creator createdDate ... on Votable { votetally { ... on VoteTally { pass_votePower_a fail_votePower_a abstain_votePower_a } } pass: voteAggregate(filter: { vote_vote_s: { regexp: \\"/.*pass*./\\" } }) {count} fail: voteAggregate(filter: { vote_vote_s: { regexp: \\"/.*fail*./\\" } }) {count} vote { ... on Vote { vote_voter_n vote_vote_s } } } ... on Edit {details_title_s details_description_s details_periodCount_i details_deferredPercX100_i ballot_expiration_t dao {docId settings {settings_daoTitle_s settings_periodDurationSec_i}} details_ballotAlignment_i details_ballotQuorum_i} ... on Queststart {details_title_s details_description_s details_periodCount_i details_deferredPercX100_i start {details_startTime_t} ballot_expiration_t dao {docId settings {settings_daoTitle_s settings_periodDurationSec_i}} details_ballotAlignment_i details_ballotSupply_a details_ballotQuorum_i details_pegAmount_a details_voiceAmount_a details_rewardAmount_a} ... on Questcomple {details_title_s details_description_s ballot_expiration_t dao {docId settings {settings_daoTitle_s settings_periodDurationSec_i}} details_pegAmount_a details_voiceAmount_a details_rewardAmount_a} ... on Policy {details_title_s details_description_s details_periodCount_i details_deferredPercX100_i ballot_expiration_t dao {docId settings {settings_daoTitle_s settings_periodDurationSec_i}} details_ballotAlignment_i details_ballotSupply_a details_ballotQuorum_i details_pegAmount_a details_voiceAmount_a details_rewardAmount_a} ... on Payout {details_title_s details_description_s details_periodCount_i details_deferredPercX100_i start {details_startTime_t} ballot_expiration_t dao {docId settings {settings_daoTitle_s settings_periodDurationSec_i}} details_ballotAlignment_i details_ballotSupply_a details_ballotQuorum_i details_pegAmount_a details_voiceAmount_a details_rewardAmount_a} ... on Badge {details_title_s details_description_s details_periodCount_i ballot_expiration_t dao {docId settings {settings_daoTitle_s settings_periodDurationSec_i}} details_ballotAlignment_i details_ballotSupply_a details_ballotQuorum_i} ... on Poll {details_title_s details_description_s ballot_expiration_t dao {docId settings {settings_daoTitle_s settings_periodDurationSec_i}} details_ballotAlignment_i details_ballotSupply_a details_ballotQuorum_i} ... on Budget {details_title_s details_description_s details_deferredPercX100_i ballot_expiration_t dao {docId settings {settings_daoTitle_s settings_periodDurationSec_i}} details_ballotAlignment_i details_ballotSupply_a details_ballotQuorum_i details_pegAmount_a details_voiceAmount_a details_rewardAmount_a} ... on Assignment {details_title_s details_description_s details_periodCount_i details_deferredPercX100_i start {details_startTime_t} details_rewardSalaryPerPeriod_a details_voiceSalaryPerPeriod_a details_pegSalaryPerPeriod_a ballot_expiration_t dao {docId settings {settings_daoTitle_s settings_periodDurationSec_i}} details_timeShareX100_i details_ballotAlignment_i details_ballotSupply_a details_ballotQuorum_i} } }", "variables":{"docId":"$proposalId"}}';
Future<Result<Map<String, dynamic>, HyphaError>> getProposalDetails(String proposalId, UserProfileData user) async {
final String query = '{"query":"query proposalDetails(\$docId: String!) { getDocument(docId: \$docId) {docId creator ... on Votable { votetally { ... on VoteTally { pass_votePower_a fail_votePower_a abstain_votePower_a } } pass: voteAggregate(filter: { vote_vote_s: { regexp: \\"/.*pass*./\\" } }) {count} fail: voteAggregate(filter: { vote_vote_s: { regexp: \\"/.*fail*./\\" } }) {count} vote { ... on Vote { vote_voter_n vote_vote_s } } } ... on Edit {details_title_s details_description_s ballot_expiration_t dao {docId } details_ballotAlignment_i details_ballotQuorum_i} ... on Queststart {details_title_s details_description_s ballot_expiration_t dao {docId} details_ballotAlignment_i details_ballotSupply_a details_ballotQuorum_i} ... on Questcomple {details_title_s details_description_s ballot_expiration_t dao {docId}} ... on Policy {details_title_s details_description_s ballot_expiration_t dao {docId} details_ballotAlignment_i details_ballotSupply_a details_ballotQuorum_i} ... on Payout {details_title_s details_description_s ballot_expiration_t dao {docId} details_ballotAlignment_i details_ballotSupply_a details_ballotQuorum_i} ... on Badge {details_title_s details_description_s dao {docId} details_ballotAlignment_i details_ballotSupply_a details_ballotQuorum_i} ... on Poll {details_title_s details_description_s ballot_expiration_t dao {docId} details_ballotAlignment_i details_ballotSupply_a details_ballotQuorum_i} ... on Budget {details_title_s details_description_s ballot_expiration_t dao {docId} details_ballotAlignment_i details_ballotSupply_a details_ballotQuorum_i} ... on Assignment {details_title_s details_description_s ballot_expiration_t dao {docId} details_timeShareX100_i details_ballotAlignment_i details_ballotSupply_a details_ballotQuorum_i} } }", "variables":{"docId":"$proposalId"}}';

return _graphQLService.graphQLQuery(network: user.network, query: query);
}
Expand Down
8 changes: 0 additions & 8 deletions lib/core/network/models/dao_proposals_model.dart

This file was deleted.

91 changes: 1 addition & 90 deletions lib/core/network/models/proposal_details_model.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:hypha_wallet/core/extension/string_extension.dart';
import 'package:hypha_wallet/core/extension/vote_tally_extension.dart';
import 'package:hypha_wallet/core/network/models/base_proposal_model.dart';
import 'package:hypha_wallet/core/network/models/dao_data_model.dart';
Expand All @@ -8,72 +7,13 @@ import 'package:json_annotation/json_annotation.dart';

part 'proposal_details_model.g.dart';

enum TokenType {
utility,
voice,
cash,
}

@JsonSerializable()
class ProposalDetailsModel extends BaseProposalModel {
double? get utilityAmountDouble => utilityAmount?.quantityAsDouble;

double? get voiceAmountDouble => voiceAmount?.quantityAsDouble;

double? get cashAmountDouble => cashAmount?.quantityAsDouble;

double? get utilityAmountPerPeriodDouble =>
utilityAmountPerPeriod?.quantityAsDouble;

double? get voiceAmountPerPeriodDouble =>
voiceAmountPerPeriod?.quantityAsDouble;

double? get cashAmountPerPeriodDouble =>
cashAmountPerPeriod?.quantityAsDouble;

@JsonKey(name: '__typename')
final String type;

@JsonKey(name: 'settings_periodDurationSec_i')
final int? periodDurationSec;

@JsonKey(name: 'createdDate')
final DateTime creationDate;

@JsonKey(name: 'details_deferredPercX100_i')
final int? tokenMixPercentage;

@JsonKey(name: 'details_periodCount_i')
final int? cycleCount;

@JsonKey(name: 'start')
final DateTime? cycleStartDate;

@JsonKey(name: 'details_rewardAmount_a')
final String? utilityAmount;

@JsonKey(name: 'details_voiceAmount_a')
final String? voiceAmount;

@JsonKey(name: 'details_pegAmount_a')
final String? cashAmount;

@JsonKey(name: 'details_rewardSalaryPerPeriod_a')
final String? utilityAmountPerPeriod;

@JsonKey(name: 'details_voiceSalaryPerPeriod_a')
final String? voiceAmountPerPeriod;

@JsonKey(name: 'details_pegSalaryPerPeriod_a')
final String? cashAmountPerPeriod;

@JsonKey(name: 'details_description_s')
final String? description;

ProposalDetailsModel(
{required super.id,
required this.type,
required this.creationDate,
super.dao,
super.commitment,
super.title,
Expand All @@ -84,39 +24,10 @@ class ProposalDetailsModel extends BaseProposalModel {
super.expiration,
super.creator,
super.votes,
this.tokenMixPercentage,
this.cycleCount,
this.cycleStartDate,
this.utilityAmount,
this.voiceAmount,
this.cashAmount,
this.utilityAmountPerPeriod,
this.voiceAmountPerPeriod,
this.cashAmountPerPeriod,
this.description,
this.periodDurationSec});
});

factory ProposalDetailsModel.fromJson(Map<String, dynamic> json) {
// Handle the 'start' field if it's a list
if (json['start'] is List) {
if ((json['start'] as List).isNotEmpty) {
json['start'] = json['start'][0]['details_startTime_t'];
} else {
json['start'] = null;
}
}
if (json['dao'] is List) {
final daoList = json['dao'];
if (daoList.isNotEmpty &&
daoList[0] is Map &&
daoList[0]['settings'] is List) {
final settingsList = daoList[0]['settings'] as List;
if (settingsList.isNotEmpty && settingsList[0] is Map) {
json['settings_periodDurationSec_i'] =
settingsList[0]['settings_periodDurationSec_i'];
}
}
}
json['dao'] = null;
json['creator'] = null;

Expand Down
28 changes: 0 additions & 28 deletions 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.

Loading

0 comments on commit 917adba

Please sign in to comment.