Skip to content

Commit ac97b73

Browse files
authored
Merge branch 'master' into cl/increase-avatars-to-30
2 parents 477a883 + 49e9e81 commit ac97b73

File tree

162 files changed

+20835
-3349
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+20835
-3349
lines changed

app/lib/models/ceremonies/ceremonies.dart

+3-46
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import 'dart:convert';
22

33
import 'package:json_annotation/json_annotation.dart';
44

5-
import 'package:encointer_wallet/models/communities/community_identifier.dart';
65
import 'package:ew_polkadart/encointer_types.dart' as et;
76
import 'package:encointer_wallet/utils/enum.dart';
87

8+
export 'reputation/v1.dart';
9+
export 'reputation/v2.dart';
10+
911
part 'ceremonies.g.dart';
1012

1113
@JsonSerializable(explicitToJson: true)
@@ -72,23 +74,6 @@ class AggregatedAccountDataGlobal {
7274
// ignore: constant_identifier_names
7375
enum ParticipantType { Bootstrapper, Reputable, Endorsee, Newbie }
7476

75-
@JsonSerializable()
76-
class CommunityReputation {
77-
CommunityReputation(this.communityIdentifier, this.reputation);
78-
79-
factory CommunityReputation.fromJson(Map<String, dynamic> json) => _$CommunityReputationFromJson(json);
80-
81-
Map<String, dynamic> toJson() => _$CommunityReputationToJson(this);
82-
83-
CommunityIdentifier communityIdentifier;
84-
Reputation reputation;
85-
86-
@override
87-
String toString() {
88-
return jsonEncode(this);
89-
}
90-
}
91-
9277
@JsonSerializable()
9378
class Meetup {
9479
Meetup(this.index, this.locationIndex, this.time, this.registry);
@@ -116,10 +101,6 @@ class Meetup {
116101
// ignore: constant_identifier_names
117102
enum CeremonyPhase { Registering, Assigning, Attesting }
118103

119-
// For compatibility with substrate's naming convention.
120-
// ignore: constant_identifier_names
121-
enum Reputation { Unverified, UnverifiedReputable, VerifiedUnlinked, VerifiedLinked }
122-
123104
// -- Helper functions for above types
124105

125106
CeremonyPhase ceremonyPhaseTypeFromPolkadart(et.CeremonyPhaseType phase) {
@@ -137,20 +118,6 @@ CeremonyPhase? ceremonyPhaseFromString(String value) {
137118
return getEnumFromString(CeremonyPhase.values, value);
138119
}
139120

140-
Reputation? reputationFromString(String value) {
141-
return getEnumFromString(Reputation.values, value);
142-
}
143-
144-
extension ReputationExtension on Reputation {
145-
String toValue() {
146-
return toEnumValue(this);
147-
}
148-
149-
bool isVerified() {
150-
return this == Reputation.VerifiedUnlinked || this == Reputation.VerifiedLinked;
151-
}
152-
}
153-
154121
extension ParticipantTypeExtension on ParticipantType {
155122
String toValue() {
156123
return toEnumValue(this);
@@ -164,13 +131,3 @@ extension CeremonyPhaseExtension on CeremonyPhase {
164131
return toEnumValue(this);
165132
}
166133
}
167-
168-
/// Takes a `List<dynamic>` which contains a `List<List<[int, Map<String, dynamic>]>` and
169-
/// transforms it into a `Map<int, CommunityReputation>`.
170-
Map<int, CommunityReputation> reputationsFromList(List<dynamic> reputationsList) {
171-
final reputations = reputationsList.cast<List<dynamic>>();
172-
173-
return {
174-
for (final cr in reputations) cr[0] as int: CommunityReputation.fromJson(cr[1] as Map<String, dynamic>),
175-
};
176-
}

app/lib/models/ceremonies/ceremonies.g.dart

-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import 'dart:convert';
2+
3+
import 'package:encointer_wallet/models/ceremonies/reputation/v2.dart';
4+
import 'package:encointer_wallet/utils/enum.dart';
5+
import 'package:json_annotation/json_annotation.dart';
6+
import 'package:encointer_wallet/models/communities/community_identifier.dart';
7+
8+
part 'v1.g.dart';
9+
10+
@JsonSerializable()
11+
class CommunityReputationV1 {
12+
CommunityReputationV1(this.communityIdentifier, this.reputation);
13+
14+
factory CommunityReputationV1.fromJson(Map<String, dynamic> json) => _$CommunityReputationV1FromJson(json);
15+
16+
Map<String, dynamic> toJson() => _$CommunityReputationV1ToJson(this);
17+
18+
CommunityIdentifier communityIdentifier;
19+
ReputationV1 reputation;
20+
21+
CommunityReputation toV2(int currentCeremonyIndex) {
22+
return CommunityReputation(communityIdentifier, reputation.toV2(currentCeremonyIndex));
23+
}
24+
25+
@override
26+
String toString() {
27+
return jsonEncode(this);
28+
}
29+
}
30+
31+
// For compatibility with substrate's naming convention.
32+
// ignore: constant_identifier_names
33+
enum ReputationV1 { Unverified, UnverifiedReputable, VerifiedUnlinked, VerifiedLinked }
34+
35+
extension ReputationV1Extension on ReputationV1 {
36+
String toValue() {
37+
return toEnumValue(this);
38+
}
39+
40+
bool isVerified() {
41+
return this == ReputationV1.VerifiedUnlinked || this == ReputationV1.VerifiedLinked;
42+
}
43+
44+
Reputation toV2(int currentCeremonyIndex) {
45+
return switch (this) {
46+
ReputationV1.Unverified => Reputation.values.unverified(),
47+
ReputationV1.UnverifiedReputable => Reputation.values.unverifiedReputable(),
48+
ReputationV1.VerifiedUnlinked => Reputation.values.verifiedUnlinked(),
49+
ReputationV1.VerifiedLinked => Reputation.values.verifiedLinked(currentCeremonyIndex),
50+
};
51+
}
52+
}
53+
54+
/// Takes a `List<dynamic>` which contains a `List<List<[int, Map<String, dynamic>]>` and
55+
/// transforms it into a `Map<int, CommunityReputation>`.
56+
Map<int, CommunityReputationV1> reputationsV1FromList(List<dynamic> reputationsList) {
57+
final reputations = reputationsList.cast<List<dynamic>>();
58+
59+
return {
60+
for (final cr in reputations) cr[0] as int: CommunityReputationV1.fromJson(cr[1] as Map<String, dynamic>),
61+
};
62+
}

app/lib/models/ceremonies/reputation/v1.g.dart

+24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
import 'dart:convert';
2+
3+
import 'package:encointer_wallet/utils/enum.dart';
4+
import 'package:json_annotation/json_annotation.dart';
5+
import 'package:encointer_wallet/models/communities/community_identifier.dart';
6+
7+
part 'v2.g.dart';
8+
9+
@JsonSerializable()
10+
class CommunityReputation {
11+
CommunityReputation(this.communityIdentifier, this.reputation);
12+
13+
factory CommunityReputation.fromJson(Map<String, dynamic> json) => _$CommunityReputationFromJson(json);
14+
15+
Map<String, dynamic> toJson() => _$CommunityReputationToJson(this);
16+
17+
CommunityIdentifier communityIdentifier;
18+
Reputation reputation;
19+
20+
@override
21+
String toString() {
22+
return jsonEncode(this);
23+
}
24+
}
25+
26+
abstract class Reputation {
27+
const Reputation();
28+
29+
factory Reputation.fromJson(dynamic json) {
30+
if (json.runtimeType == String) {
31+
final variant = json as String;
32+
switch (variant) {
33+
case 'Unverified':
34+
return const Unverified();
35+
case 'UnverifiedReputable':
36+
return const UnverifiedReputable();
37+
case 'VerifiedUnlinked':
38+
return const VerifiedUnlinked();
39+
default:
40+
throw Exception('Reputation: Invalid variant: "$variant"');
41+
}
42+
} else {
43+
final variant = (json as Map<String, dynamic>).keys.first;
44+
switch (variant) {
45+
case 'VerifiedLinked':
46+
return VerifiedLinked(json.values.first as int);
47+
default:
48+
throw Exception('Reputation: Invalid variant: "$variant"');
49+
}
50+
}
51+
}
52+
53+
static const $Reputation values = $Reputation();
54+
55+
Map<String, dynamic> toJson();
56+
}
57+
58+
class $Reputation {
59+
const $Reputation();
60+
61+
Unverified unverified() {
62+
return const Unverified();
63+
}
64+
65+
UnverifiedReputable unverifiedReputable() {
66+
return const UnverifiedReputable();
67+
}
68+
69+
VerifiedUnlinked verifiedUnlinked() {
70+
return const VerifiedUnlinked();
71+
}
72+
73+
VerifiedLinked verifiedLinked(int value0) {
74+
return VerifiedLinked(value0);
75+
}
76+
}
77+
78+
class Unverified extends Reputation {
79+
const Unverified();
80+
81+
@override
82+
Map<String, dynamic> toJson() => {'Unverified': null};
83+
84+
@override
85+
bool operator ==(Object other) => other is Unverified;
86+
87+
@override
88+
int get hashCode => runtimeType.hashCode;
89+
}
90+
91+
class UnverifiedReputable extends Reputation {
92+
const UnverifiedReputable();
93+
94+
@override
95+
Map<String, dynamic> toJson() => {'UnverifiedReputable': null};
96+
97+
@override
98+
bool operator ==(Object other) => other is UnverifiedReputable;
99+
100+
@override
101+
int get hashCode => runtimeType.hashCode;
102+
}
103+
104+
class VerifiedUnlinked extends Reputation {
105+
const VerifiedUnlinked();
106+
107+
@override
108+
Map<String, dynamic> toJson() => {'VerifiedUnlinked': null};
109+
110+
@override
111+
bool operator ==(Object other) => other is VerifiedUnlinked;
112+
113+
@override
114+
int get hashCode => runtimeType.hashCode;
115+
}
116+
117+
class VerifiedLinked extends Reputation {
118+
const VerifiedLinked(this.value0);
119+
120+
/// CeremonyIndexType
121+
final int value0;
122+
123+
@override
124+
Map<String, int> toJson() => {'VerifiedLinked': value0};
125+
126+
@override
127+
bool operator ==(Object other) =>
128+
identical(
129+
this,
130+
other,
131+
) ||
132+
other is VerifiedLinked && other.value0 == value0;
133+
134+
@override
135+
int get hashCode => value0.hashCode;
136+
}
137+
138+
extension ReputationExtension on Reputation {
139+
String toValue() {
140+
return toEnumValue(this);
141+
}
142+
143+
bool isVerified() {
144+
return runtimeType == VerifiedUnlinked || runtimeType == VerifiedLinked;
145+
}
146+
}
147+
148+
/// Takes a `List<dynamic>` which contains a `List<List<[int, Map<String, dynamic>]>` and
149+
/// transforms it into a `Map<int, CommunityReputation>`.
150+
Map<int, CommunityReputation> reputationsFromList(List<dynamic> reputationsList) {
151+
final reputations = reputationsList.cast<List<dynamic>>();
152+
153+
return {
154+
for (final cr in reputations) cr[0] as int: CommunityReputation.fromJson(cr[1] as Map<String, dynamic>),
155+
};
156+
}

app/lib/models/ceremonies/reputation/v2.g.dart

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)