-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathceremony_box.dart
235 lines (223 loc) · 10.2 KB
/
ceremony_box.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
import 'dart:async';
import 'package:ew_test_keys/ew_test_keys.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:iconsax/iconsax.dart';
import 'package:encointer_wallet/common/components/gradient_elements.dart';
import 'package:encointer_wallet/models/index.dart';
import 'package:encointer_wallet/theme/theme.dart';
import 'package:encointer_wallet/modules/modules.dart';
import 'package:encointer_wallet/page-encointer/ceremony_box/ceremony_info.dart';
import 'package:encointer_wallet/page-encointer/ceremony_box/components/ceremony_register_button.dart';
import 'package:encointer_wallet/page-encointer/ceremony_box/components/ceremony_start_button.dart';
import 'package:encointer_wallet/page-encointer/ceremony_box/components/unregister_link_button.dart';
import 'package:encointer_wallet/page-encointer/ceremony_box/components/lower_ceremony_box_container.dart';
import 'package:encointer_wallet/models/communities/community_metadata.dart';
import 'package:encointer_wallet/page-encointer/ceremony_box/meetup_info/components/ceremony_notification.dart';
import 'package:encointer_wallet/page-encointer/ceremony_box/meetup_info/meetup_info.dart';
import 'package:encointer_wallet/page-encointer/meetup/ceremony_step1_count.dart';
import 'package:encointer_wallet/service/log/log_service.dart';
import 'package:encointer_wallet/service/substrate_api/api.dart';
import 'package:encointer_wallet/service/tx/lib/tx.dart';
import 'package:encointer_wallet/store/app.dart';
import 'package:encointer_wallet/l10n/l10.dart';
class CeremonyBox extends StatelessWidget {
const CeremonyBox(this.store, this.api, {super.key});
final AppStore store;
final Api api;
@override
Widget build(BuildContext context) {
return Observer(builder: (BuildContext context) {
final meetupTime = store.encointer.community?.meetupTimeOverride ??
store.encointer.community?.meetupTime ??
store.encointer.attestingPhaseStart;
// I decided to not introduce anymore degrees of freedom for the demo overrides, otherwise
// we want to do too much again. So I hardcode the assigning phase duration to 30 minutes
// if we have meetup time overrides. Before we do something more complex here, I want to
// think some more, of what we want to do with the feed in the future.
final assigningPhaseStart = store.encointer.community?.meetupTimeOverride != null
? store.encointer.community!.meetupTimeOverride! - const Duration(minutes: 30).inMilliseconds
: store.encointer.assigningPhaseStart;
return Column(
children: [
Container(
padding: EdgeInsets.fromLTRB(24, 24, 24, store.encointer.showMeetupInfo ? 12 : 24),
decoration: BoxDecoration(
color: context.colorScheme.background,
borderRadius: BorderRadius.vertical(
top: const Radius.circular(15),
bottom: Radius.circular(store.encointer.showMeetupInfo ? 0 : 15),
),
),
child: Column(
children: [
CeremonyInfo(
currentTime: DateTime.now().millisecondsSinceEpoch,
assigningPhaseStart: assigningPhaseStart,
meetupTime: meetupTime,
ceremonyPhaseDurations: store.encointer.phaseDurations,
meetupCompleted: store.encointer.communityAccount?.meetupCompleted ?? false,
communityRules: store.encointer.community?.metadata?.rules ?? CommunityRules.LoCo,
),
if (store.encointer.showRegisterButton)
Padding(
padding: const EdgeInsets.only(top: 12),
child: CeremonyRegisterButton(
key: const Key(EWTestKeys.registrationMeetupButton),
registerUntil: assigningPhaseStart,
onPressed: (context) async {
if (store.dataUpdate.expired) {
await awaitDataUpdateWithDialog(context, store);
}
await submitRegisterParticipant(
context,
store,
api,
store.account.getKeyringAccount(store.account.currentAccountPubKey!),
store.encointer.chosenCid!,
txPaymentAsset: store.encointer.getTxPaymentAsset(store.encointer.chosenCid),
);
}),
),
if (store.encointer.showRestartCeremonyButton)
TextButton(
key: const Key(EWTestKeys.restartMeetup),
onPressed: () => Navigator.of(context).push(
MaterialPageRoute<void>(builder: (context) => CeremonyStep1Count(store, api)),
),
child: Text(
context.l10n.restartGathering,
style: context.bodyMedium
.copyWith(color: AppColors.encointerBlack, decoration: TextDecoration.underline),
),
),
if (store.encointer.showStartCeremonyButton)
Padding(
padding: const EdgeInsets.only(top: 12),
child: CeremonyStartButton(
key: const Key(EWTestKeys.startMeetup),
onPressed: () => Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (context) => CeremonyStep1Count(store, api),
),
),
),
),
if (store.encointer.showSubmitClaimsButton)
Padding(
padding: const EdgeInsets.only(top: 6),
child: PrimaryButton(
// todo: this will be removed because we do it automatically
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Iconsax.login_1),
const SizedBox(width: 6),
Text(context.l10n.claimsSubmitN(store.encointer.communityAccount!.scannedAttendeesCount)),
],
),
onPressed: () => submitAttestAttendees(
context,
store,
api,
store.account.getKeyringAccount(store.account.currentAccountPubKey!),
store.encointer.chosenCid!,
txPaymentAsset: store.encointer.getTxPaymentAsset(store.encointer.chosenCid),
),
),
)
],
),
),
if (store.encointer.showMeetupInfo)
LowerCeremonyBoxContainer(
child: getMeetupInfoWidget(context, store),
)
],
);
});
}
}
Widget getMeetupInfoWidget(BuildContext context, AppStore store) {
final l10n = context.l10n;
final communityAccount = store.encointer.communityAccount;
switch (store.encointer.currentPhase) {
case CeremonyPhase.Registering:
if (communityAccount?.isRegistered ?? false) {
return Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
CeremonyNotification(
key: const Key(EWTestKeys.isRegisteredInfo),
notificationIconData: Iconsax.tick_square,
notification: l10n.youAreRegisteredAs(
store.encointer.communityAccount!.participantType!.toValue(),
),
),
const SizedBox(height: 4),
const UnregisteredLinkButton(),
],
);
} else {
// showMeetupInfo == false in this case. So we don't show this widget at all.
Log.d(
"'getMeetupInfoWidget' trapped in an unexpected if statement: Registering phase + Unregistered",
'CeremonyBox',
);
return const SizedBox.shrink();
}
case CeremonyPhase.Assigning:
if (store.encointer.communityAccount?.isAssigned ?? false) {
return _meetupInfo(context, store);
} else {
return CeremonyNotification(
key: const Key(EWTestKeys.accountUnassigned),
notificationIconData: Iconsax.close_square,
notification: l10n.youAreNotRegisteredPleaseRegisterNextTime,
);
}
case CeremonyPhase.Attesting:
if (!(store.encointer.communityAccount?.isAssigned ?? false)) {
return CeremonyNotification(
notificationIconData: Iconsax.close_square,
notification: l10n.youAreNotRegisteredPleaseRegisterNextTime,
);
} else {
if (store.encointer.communityAccount?.meetupCompleted ?? false) {
return CeremonyNotification(
notificationIconData: Iconsax.tick_square,
notification: l10n.successfullySentNAttestations(
store.encointer.communityAccount!.scannedAttendeesCount,
),
);
} else {
return _meetupInfo(context, store);
}
}
}
}
Widget _meetupInfo(BuildContext context, AppStore store) {
final meetup = store.encointer.communityAccount!.meetup!;
final location = store.encointer.community!.meetupLocations![meetup.locationIndex];
final rules = store.encointer.community!.metadata!.communityRules;
final args = MeetupLocationArgs(location, meetup, rules);
return MeetupInfo(
meetup,
location,
key: const Key(EWTestKeys.accountAssigned),
onPressed: () {
Navigator.pushNamed(context, MeetupLocationPage.route, arguments: args);
},
);
}
Future<void> awaitDataUpdateWithDialog(BuildContext context, AppStore store) async {
unawaited(showCupertinoDialog<void>(
context: context,
builder: (_) => CupertinoAlertDialog(
title: Text(context.l10n.updatingAppState),
content: const CupertinoActivityIndicator(),
),
));
await store.dataUpdate.executeUpdate().whenComplete(() => Navigator.of(context).pop());
}