@@ -2,10 +2,12 @@ import 'package:flutter/cupertino.dart';
22import 'package:flutter/material.dart' ;
33import 'package:flutter_riverpod/flutter_riverpod.dart' ;
44import 'package:gridproxy_client/models/farms.dart' ;
5+ import 'package:threebotlogin/models/wallet.dart' ;
56import 'package:threebotlogin/providers/wallets_provider.dart' ;
7+ import 'package:threebotlogin/services/gridproxy_service.dart' ;
68import 'package:threebotlogin/services/tfchain_service.dart' ;
7- import 'package:threebotlogin/services/wallet_service.dart' ;
89import 'package:threebotlogin/widgets/custom_dialog.dart' ;
10+ import 'package:threebotlogin/services/tfchain_service.dart' as TFChainService;
911
1012class VoteDialog extends ConsumerStatefulWidget {
1113 final String proposalHash;
@@ -21,7 +23,7 @@ class VoteDialog extends ConsumerStatefulWidget {
2123class _VoteDialogState extends ConsumerState <VoteDialog > {
2224 int ? farmId;
2325 List <Farm > farms = [];
24- Map <int , Map < String , String > > twinIdWallets = {};
26+ Map <int , Wallet > twinIdWallets = {};
2527 bool loading = true ;
2628 bool yesLoading = false ;
2729 bool noLoading = false ;
@@ -33,7 +35,17 @@ class _VoteDialogState extends ConsumerState<VoteDialog> {
3335 });
3436 await ref.read (walletsNotifier.notifier).list ();
3537 final wallets = ref.read (walletsNotifier);
36- farms = await getDaoFarms (wallets);
38+ final twinIdFutures = wallets.map ((w) async {
39+ final twinId = await TFChainService .getTwinId (w.tfchainSecret);
40+ if (twinId != 0 ) {
41+ twinIdWallets[twinId] = w;
42+ }
43+ }).toList ();
44+
45+ await Future .wait (twinIdFutures);
46+
47+ farms =
48+ await getFarmsByTwinIds (twinIdWallets.keys.toList (), hasUpNode: true );
3749 } catch (e) {
3850 throw Exception ('Failed to get farms due to $e ' );
3951 } finally {
@@ -209,7 +221,7 @@ class _VoteDialogState extends ConsumerState<VoteDialog> {
209221 });
210222 final farm = farms.firstWhere ((farm) => farm.farmID == farmId);
211223 final twinId = farm.twinId;
212- final seed = twinIdWallets[twinId]! [ 'tfchainSeed' ] ;
224+ final seed = twinIdWallets[twinId]! .tfchainSecret ;
213225 final votes = await getProposalVotes (widget.proposalHash);
214226
215227 final hasVotedYes = votes.ayes.any ((vote) => vote.farmId == farmId);
@@ -226,7 +238,7 @@ class _VoteDialogState extends ConsumerState<VoteDialog> {
226238 return ;
227239 }
228240 try {
229- await vote (approve, widget.proposalHash, farmId! , seed! );
241+ await vote (approve, widget.proposalHash, farmId! , seed);
230242 await _showDialog ('Voted!' , 'You have voted successfully.' , Icons .check,
231243 DialogType .Info );
232244 Navigator .of (context).pop ();
0 commit comments