From f8b78ec9a340aa1b305fb555f37ecd0d4c0680b3 Mon Sep 17 00:00:00 2001 From: AlaaElattar Date: Mon, 21 Oct 2024 12:57:12 +0300 Subject: [PATCH 1/6] Add msg when user can't vote --- app/lib/widgets/dao/vote_dialog.dart | 208 ++++++++++++++------------- 1 file changed, 111 insertions(+), 97 deletions(-) diff --git a/app/lib/widgets/dao/vote_dialog.dart b/app/lib/widgets/dao/vote_dialog.dart index e3f4b86b7..f33b0e200 100644 --- a/app/lib/widgets/dao/vote_dialog.dart +++ b/app/lib/widgets/dao/vote_dialog.dart @@ -81,109 +81,123 @@ class _VoteDialogState extends State { ), ); } else { - content = Padding( - padding: const EdgeInsets.all(30), - child: Flex( - direction: Axis.vertical, - mainAxisSize: MainAxisSize.min, - children: [ - DropdownMenu( - menuHeight: MediaQuery.sizeOf(context).height * 0.3, - enableFilter: true, - width: MediaQuery.sizeOf(context).width * 0.55, - textStyle: Theme.of(context).textTheme.bodyLarge!.copyWith( - color: Theme.of(context).colorScheme.onSurface, - ), - trailingIcon: const Icon( - CupertinoIcons.chevron_down, - size: 18, - ), - selectedTrailingIcon: const Icon( - CupertinoIcons.chevron_up, - size: 18, - ), - inputDecorationTheme: InputDecorationTheme( - filled: true, - fillColor: Theme.of(context).colorScheme.secondaryContainer, - enabledBorder: UnderlineInputBorder( - borderRadius: const BorderRadius.all(Radius.circular(4)), - borderSide: BorderSide( - color: Theme.of(context).colorScheme.secondaryContainer, - width: 8.0, - ), + if (farms.isEmpty) { + content = Padding( + padding: const EdgeInsets.all(30), + child: Text( + 'No farms available with online node to vote.', + style: Theme.of(context).textTheme.bodyLarge!.copyWith( + color: Theme.of(context).colorScheme.onBackground, ), - ), - menuStyle: MenuStyle( - shape: WidgetStateProperty.all( - const RoundedRectangleBorder( - borderRadius: BorderRadius.all(Radius.circular(4)), + textAlign: TextAlign.center, + ), + ); + } else { + content = Padding( + padding: const EdgeInsets.all(30), + child: Flex( + direction: Axis.vertical, + mainAxisSize: MainAxisSize.min, + children: [ + DropdownMenu( + menuHeight: MediaQuery.sizeOf(context).height * 0.3, + enableFilter: true, + width: MediaQuery.sizeOf(context).width * 0.55, + textStyle: Theme.of(context).textTheme.bodyLarge!.copyWith( + color: Theme.of(context).colorScheme.onSurface, + ), + trailingIcon: const Icon( + CupertinoIcons.chevron_down, + size: 18, + ), + selectedTrailingIcon: const Icon( + CupertinoIcons.chevron_up, + size: 18, + ), + inputDecorationTheme: InputDecorationTheme( + filled: true, + fillColor: Theme.of(context).colorScheme.secondaryContainer, + enabledBorder: UnderlineInputBorder( + borderRadius: const BorderRadius.all(Radius.circular(4)), + borderSide: BorderSide( + color: Theme.of(context).colorScheme.secondaryContainer, + width: 8.0, + ), ), ), - ), - label: Text( - 'Select Farm', - style: Theme.of(context).textTheme.bodyLarge!.copyWith( - color: Theme.of(context).colorScheme.onSecondaryContainer, + menuStyle: MenuStyle( + shape: WidgetStateProperty.all( + const RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(4)), ), - ), - dropdownMenuEntries: _buildDropdownMenuEntries(farms), - onSelected: (int? value) { - if (value != null) { - farmId = value; - } - }, - ), - const SizedBox(height: 20), - Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - ElevatedButton( - onPressed: () { - _vote(true); - }, - child: yesLoading - ? const SizedBox( - width: 20, - height: 20, - child: CircularProgressIndicator( - strokeWidth: 2, - )) - : Text( - 'Yes', - style: - Theme.of(context).textTheme.bodyLarge!.copyWith( - color: Theme.of(context) - .colorScheme - .onPrimaryContainer, - ), - ), + ), ), - ElevatedButton( - onPressed: () { - _vote(false); - }, - child: noLoading - ? const SizedBox( - width: 20, - height: 20, - child: CircularProgressIndicator( - strokeWidth: 2, - )) - : Text( - 'No', - style: - Theme.of(context).textTheme.bodyLarge!.copyWith( - color: Theme.of(context) - .colorScheme - .onPrimaryContainer, - ), - ), + label: Text( + 'Select Farm', + style: Theme.of(context).textTheme.bodyLarge!.copyWith( + color: + Theme.of(context).colorScheme.onSecondaryContainer, + ), ), - ], - ), - ], - ), - ); + dropdownMenuEntries: _buildDropdownMenuEntries(farms), + onSelected: (int? value) { + if (value != null) { + farmId = value; + } + }, + ), + const SizedBox(height: 20), + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + ElevatedButton( + onPressed: () { + _vote(true); + }, + child: yesLoading + ? const SizedBox( + width: 20, + height: 20, + child: CircularProgressIndicator( + strokeWidth: 2, + )) + : Text( + 'Yes', + style: + Theme.of(context).textTheme.bodyLarge!.copyWith( + color: Theme.of(context) + .colorScheme + .onPrimaryContainer, + ), + ), + ), + ElevatedButton( + onPressed: () { + _vote(false); + }, + child: noLoading + ? const SizedBox( + width: 20, + height: 20, + child: CircularProgressIndicator( + strokeWidth: 2, + )) + : Text( + 'No', + style: + Theme.of(context).textTheme.bodyLarge!.copyWith( + color: Theme.of(context) + .colorScheme + .onPrimaryContainer, + ), + ), + ), + ], + ), + ], + ), + ); + } } return Dialog( shape: RoundedRectangleBorder( From b59de4995620f413357d8c13b3e94e1ed6d0b768 Mon Sep 17 00:00:00 2001 From: AlaaElattar Date: Mon, 21 Oct 2024 13:13:42 +0300 Subject: [PATCH 2/6] update onBackground to onSurface --- app/lib/widgets/dao/vote_dialog.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/lib/widgets/dao/vote_dialog.dart b/app/lib/widgets/dao/vote_dialog.dart index f33b0e200..6eb6e78ea 100644 --- a/app/lib/widgets/dao/vote_dialog.dart +++ b/app/lib/widgets/dao/vote_dialog.dart @@ -87,7 +87,7 @@ class _VoteDialogState extends State { child: Text( 'No farms available with online node to vote.', style: Theme.of(context).textTheme.bodyLarge!.copyWith( - color: Theme.of(context).colorScheme.onBackground, + color: Theme.of(context).colorScheme.onSurface, ), textAlign: TextAlign.center, ), From 5ef7bab2af01c74ac9a1c9ce0c582a806067bdce Mon Sep 17 00:00:00 2001 From: AlaaElattar Date: Tue, 22 Oct 2024 11:47:28 +0300 Subject: [PATCH 3/6] add custom dialog for voting dialog in dao --- app/lib/widgets/dao/vote_dialog.dart | 33 ++++++++++++++++------------ 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/app/lib/widgets/dao/vote_dialog.dart b/app/lib/widgets/dao/vote_dialog.dart index 6eb6e78ea..de6fa6a0f 100644 --- a/app/lib/widgets/dao/vote_dialog.dart +++ b/app/lib/widgets/dao/vote_dialog.dart @@ -82,15 +82,12 @@ class _VoteDialogState extends State { ); } else { if (farms.isEmpty) { - content = Padding( - padding: const EdgeInsets.all(30), - child: Text( - 'No farms available with online node to vote.', - style: Theme.of(context).textTheme.bodyLarge!.copyWith( - color: Theme.of(context).colorScheme.onSurface, - ), - textAlign: TextAlign.center, - ), + content = Text( + 'No farms available with online node to vote.', + style: Theme.of(context).textTheme.bodyLarge!.copyWith( + color: Theme.of(context).colorScheme.onSurface, + ), + textAlign: TextAlign.center, ); } else { content = Padding( @@ -199,11 +196,19 @@ class _VoteDialogState extends State { ); } } - return Dialog( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10), - ), - child: content); + return CustomDialog( + title: 'Vote', + widgetDescription: content, + image: Icons.how_to_vote_outlined, + actions: [ + TextButton( + child: const Text('Close'), + onPressed: () { + Navigator.pop(context); + }, + ) + ], + ); } void _vote(bool approve) async { From 91deda609c8ed9445b5757b671287bf7afd55f5e Mon Sep 17 00:00:00 2001 From: AlaaElattar Date: Tue, 22 Oct 2024 12:52:12 +0300 Subject: [PATCH 4/6] Update result dialog with using CustomDialog --- app/lib/widgets/dao/show_result_dialog.dart | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/lib/widgets/dao/show_result_dialog.dart b/app/lib/widgets/dao/show_result_dialog.dart index ca325b1d7..d2c97af0e 100644 --- a/app/lib/widgets/dao/show_result_dialog.dart +++ b/app/lib/widgets/dao/show_result_dialog.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:threebotlogin/services/tfchain_service.dart'; +import 'package:threebotlogin/widgets/custom_dialog.dart'; class ShowResultDialog extends StatefulWidget { final String proposalHash; @@ -179,11 +180,18 @@ class _ShowResultDialogState extends State ); } - return Dialog( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10), - ), - backgroundColor: Theme.of(context).colorScheme.surface, - child: content); + return CustomDialog( + title: 'Vote', + widgetDescription: content, + image: Icons.how_to_vote_outlined, + actions: [ + TextButton( + child: const Text('Close'), + onPressed: () { + Navigator.pop(context); + }, + ) + ], + ); } } From b8eb07abc42158054a2fd5686e789312898b3dcf Mon Sep 17 00:00:00 2001 From: AlaaElattar Date: Wed, 23 Oct 2024 12:19:16 +0300 Subject: [PATCH 5/6] update all dailogues & check if user voted before --- app/lib/widgets/dao/show_result_dialog.dart | 10 +- app/lib/widgets/dao/vote_dialog.dart | 106 +++++++++++--------- 2 files changed, 58 insertions(+), 58 deletions(-) diff --git a/app/lib/widgets/dao/show_result_dialog.dart b/app/lib/widgets/dao/show_result_dialog.dart index d2c97af0e..b16d67b60 100644 --- a/app/lib/widgets/dao/show_result_dialog.dart +++ b/app/lib/widgets/dao/show_result_dialog.dart @@ -181,17 +181,9 @@ class _ShowResultDialogState extends State } return CustomDialog( - title: 'Vote', + title: 'Voting Result', widgetDescription: content, image: Icons.how_to_vote_outlined, - actions: [ - TextButton( - child: const Text('Close'), - onPressed: () { - Navigator.pop(context); - }, - ) - ], ); } } diff --git a/app/lib/widgets/dao/vote_dialog.dart b/app/lib/widgets/dao/vote_dialog.dart index de6fa6a0f..43ab2c774 100644 --- a/app/lib/widgets/dao/vote_dialog.dart +++ b/app/lib/widgets/dao/vote_dialog.dart @@ -143,71 +143,65 @@ class _VoteDialogState extends State { } }, ), - const SizedBox(height: 20), - Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - ElevatedButton( - onPressed: () { - _vote(true); - }, - child: yesLoading + ], + ), + ); + } + } + return CustomDialog( + title: 'Vote', + widgetDescription: content, + image: Icons.how_to_vote_outlined, + actions: farms.isEmpty && !loading + ? [ + TextButton( + child: const Text('Close'), + onPressed: () { + Navigator.pop(context); + }, + ), + ] + : loading + ? null + : [ + TextButton( + child: noLoading ? const SizedBox( width: 20, height: 20, child: CircularProgressIndicator( strokeWidth: 2, - )) - : Text( - 'Yes', - style: - Theme.of(context).textTheme.bodyLarge!.copyWith( - color: Theme.of(context) - .colorScheme - .onPrimaryContainer, - ), - ), - ), - ElevatedButton( + ), + ) + : const Text('No'), onPressed: () { _vote(false); }, - child: noLoading + ), + TextButton( + child: yesLoading ? const SizedBox( width: 20, height: 20, child: CircularProgressIndicator( strokeWidth: 2, - )) + ), + ) : Text( - 'No', - style: - Theme.of(context).textTheme.bodyLarge!.copyWith( - color: Theme.of(context) - .colorScheme - .onPrimaryContainer, - ), + 'Yes', + style: Theme.of(context) + .textTheme + .bodyMedium! + .copyWith( + color: Theme.of(context) + .colorScheme + .onSurface), ), - ), + onPressed: () async { + _vote(true); + }, + ) ], - ), - ], - ), - ); - } - } - return CustomDialog( - title: 'Vote', - widgetDescription: content, - image: Icons.how_to_vote_outlined, - actions: [ - TextButton( - child: const Text('Close'), - onPressed: () { - Navigator.pop(context); - }, - ) - ], ); } @@ -219,6 +213,20 @@ class _VoteDialogState extends State { final farm = farms.firstWhere((farm) => farm.farmID == farmId); final twinId = farm.twinId; final seed = twinIdWallets[twinId]!['tfchainSeed']; + final votes = await getProposalVotes(widget.proposalHash); + + final hasVotedYes = votes.ayes.any((vote) => vote.farmId == farmId); + final hasVotedNo = votes.nays.any((vote) => vote.farmId == farmId); + + if ((approve && hasVotedYes) || (!approve && hasVotedNo)) { + _showDialog('Voted!', 'You have voted successfully.', Icons.check, + DialogType.Info); + setState(() { + yesLoading = false; + noLoading = false; + }); + return; + } try { await vote(approve, widget.proposalHash, farmId!, seed!); From 391b70322d029b283ec2b1eb7e21f1339bf54696 Mon Sep 17 00:00:00 2001 From: AlaaElattar Date: Wed, 23 Oct 2024 12:27:52 +0300 Subject: [PATCH 6/6] update Yes button to be the same color as No button. --- app/lib/widgets/dao/vote_dialog.dart | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/app/lib/widgets/dao/vote_dialog.dart b/app/lib/widgets/dao/vote_dialog.dart index 43ab2c774..0b13a7bc9 100644 --- a/app/lib/widgets/dao/vote_dialog.dart +++ b/app/lib/widgets/dao/vote_dialog.dart @@ -187,15 +187,8 @@ class _VoteDialogState extends State { strokeWidth: 2, ), ) - : Text( + : const Text( 'Yes', - style: Theme.of(context) - .textTheme - .bodyMedium! - .copyWith( - color: Theme.of(context) - .colorScheme - .onSurface), ), onPressed: () async { _vote(true);