@@ -16,12 +16,20 @@ import 'human.dart';
1616import 'org.dart' ;
1717
1818delegate (String toWhom, Org org) async {
19+ final human = Human (); // Get the singleton instance
20+ if (human.web3user == null ) {
21+ print ("Error in delegate: web3user is null. Wallet not connected or on wrong chain?" );
22+ return "not ok: Wallet not ready" ;
23+ }
24+ // Ensure we are using the latest provider state by creating contract with current web3user
1925 var sourceContract =
20- Contract (org.govTokenAddress! , tokenAbiString, Human () .web3user);
21- print ("facuram contractu " );
26+ Contract (org.govTokenAddress! , tokenAbiString, human .web3user);
27+ print ("delegate: Contract object created with current web3user for chain: ${ human . chain . name } " );
2228 try {
23- sourceContract = sourceContract.connect (Human ().web3user! .getSigner ());
24- print ("signed ok" );
29+ // Connect with the signer from the current web3user
30+ final signer = human.web3user! .getSigner ();
31+ sourceContract = sourceContract.connect (signer);
32+ print ("delegate: Contract connected with signer for chain: ${human .chain .name }" );
2533 final transaction =
2634 await promiseToFuture (callMethod (sourceContract, "delegate" , [toWhom]));
2735 print ("facuram tranzactia" );
@@ -443,24 +451,26 @@ Future<List<String>> createDAOwithWrappedToken(Org org, DaoConfig daoConfig) asy
443451 return ["ERROR: Wrapped token symbol not provided" ];
444452 }
445453
446- final String contractAddressToUse = Human ().chain.wrapperContract_w ?? "0xf4B3022b0fb4e8A73082ba9081722d6a276195c2" ;
447- print ("Using wrapper contract address for wrapped token DAO: $contractAddressToUse " );
454+ final human = Human (); // Get the singleton instance
455+ final String contractAddressToUse = human.chain.wrapperContract_w ?? "0xf4B3022b0fb4e8A73082ba9081722d6a276195c2" ;
456+ print ("Using wrapper contract address for wrapped token DAO: $contractAddressToUse for chain: ${human .chain .name }" );
448457
449- if (Human () .web3user == null ) {
450- print ("Error: Web3 provider (Human(). web3user) is null." );
458+ if (human .web3user == null ) {
459+ print ("Error in createDAOwithWrappedToken: web3user is null." );
451460 return ["ERROR: Web3 provider not initialized" ];
452461 }
453462
454463 var sourceContract = Contract (
455- contractAddressToUse,
464+ contractAddressToUse,
456465 wrapperAbiStringGlobal,
457- Human () .web3user
466+ human.web3user // Use human .web3user
458467 );
459- print ("Contract object created with address: $contractAddressToUse " );
468+ print ("createDAOwithWrappedToken: Contract object created with address: $contractAddressToUse for chain: ${ human . chain . name } " );
460469
461470 try {
462- sourceContract = sourceContract.connect (Human ().web3user! .getSigner ());
463- print ("Contract connected with signer." );
471+ final signer = human.web3user! .getSigner (); // Get signer from current web3user
472+ sourceContract = sourceContract.connect (signer);
473+ print ("createDAOwithWrappedToken: Contract connected with signer for chain: ${human .chain .name }" );
464474
465475 String executionDelayString = (org.executionDelay ?? 0 ).toString ();
466476 String votingDelayString = (org.votingDelay ?? 0 ).toString ();
@@ -495,7 +505,7 @@ Future<List<String>> createDAOwithWrappedToken(Org org, DaoConfig daoConfig) asy
495505 print ("Transaction hash: $hash " );
496506
497507 final result = await promiseToFuture (
498- callMethod (Human () .web3user! , 'waitForTransaction' , [hash, 1 ]));
508+ callMethod (human .web3user! , 'waitForTransaction' , [hash, 1 ])); // Use human.web3user
499509
500510 final decodedResult = json.decode (stringify (result));
501511 print ("Transaction receipt status: ${decodedResult ["status" ]}" );
@@ -591,14 +601,22 @@ createDAO(Org org) async {
591601 org.proposalThreshold.toString (),
592602 org.quorum.toString (),
593603 ]);
594- print ("wrapper contract address ${Human ().chain .wrapperContract }" );
595- print ("web3 is of type ${Human ().web3user }" );
604+ final human = Human (); // Get the singleton instance
605+ print ("wrapper contract address ${human .chain .wrapperContract } for chain: ${human .chain .name }" );
606+ print ("web3 is of type ${human .web3user }" );
607+
608+ if (human.web3user == null ) {
609+ print ("Error in createDAO: web3user is null." );
610+ return ["ERROR: Web3 provider not initialized" ]; // Or appropriate error list
611+ }
612+
596613 var sourceContract = Contract (
597- Human () .chain.wrapperContract, wrapperAbiStringGlobal, Human () .web3user);
598- print ("facuram contractu " );
614+ human .chain.wrapperContract, wrapperAbiStringGlobal, human .web3user); // Use human.web3user
615+ print ("createDAO: Contract object created for chain: ${ human . chain . name } " );
599616 try {
600- sourceContract = sourceContract.connect (Human ().web3user! .getSigner ());
601- print ("signed oki" );
617+ final signer = human.web3user! .getSigner (); // Get signer from current web3user
618+ sourceContract = sourceContract.connect (signer);
619+ print ("createDAO: Contract connected with signer for chain: ${human .chain .name }" );
602620
603621 if (org.debatesOnly ?? false ) {
604622 org.registry = {"debatesOnly" : "True" };
@@ -628,7 +646,7 @@ createDAO(Org org) async {
628646 final hash = json.decode (stringify (transaction))["hash" ];
629647
630648 final result = await promiseToFuture (
631- callMethod (Human () .web3user! , 'waitForTransaction' , [hash]));
649+ callMethod (human .web3user! , 'waitForTransaction' , [hash])); // Use human.web3user
632650 if (json.decode (stringify (result))["status" ] == 0 ) {
633651 print ("nu merge eroare de greseala" );
634652 return "not ok" ;
@@ -675,13 +693,21 @@ propose(Proposal p) async {
675693 print (p.description);
676694 String concatenated =
677695 "${p .name }0|||0${p .type }0|||0${p .description }0|||0${p .externalResource }" ;
678- print ("web3user: ${Human ().web3user }" );
679- var sourceContract = Contract (p.org.address! , daoAbiString, Human ().web3user);
680- print ("facuram contractu" );
696+ final human = Human (); // Get the singleton instance
697+ print ("propose: web3user is type ${human .web3user } for chain: ${human .chain .name }" );
698+
699+ if (human.web3user == null ) {
700+ print ("Error in propose: web3user is null." );
701+ return "not ok: Wallet not ready" ;
702+ }
703+
704+ var sourceContract = Contract (p.org.address! , daoAbiString, human.web3user); // Use human.web3user
705+ print ("propose: Contract object created for chain: ${human .chain .name }" );
681706 String calldata0;
682707 try {
683- sourceContract = sourceContract.connect (Human ().web3user! .getSigner ());
684- print ("signed ok" );
708+ final signer = human.web3user! .getSigner (); // Get signer from current web3user
709+ sourceContract = sourceContract.connect (signer);
710+ print ("propose: Contract connected with signer for chain: ${human .chain .name }" );
685711 print ("concatenated: $concatenated " );
686712 print ("targets ${p .targets }" );
687713 print ("values ${p .values }" );
@@ -691,7 +717,7 @@ propose(Proposal p) async {
691717 print ("facuram tranzactia" );
692718 final hash = json.decode (stringify (transaction))["hash" ];
693719 final result = await promiseToFuture (
694- callMethod (Human () .web3user! , 'waitForTransaction' , [hash]));
720+ callMethod (human .web3user! , 'waitForTransaction' , [hash])); // Use human.web3user
695721 if (json.decode (stringify (result))["status" ] == 0 ) {
696722 print ("nu merge eroare de greseala" );
697723 return "not ok" ;
@@ -728,11 +754,19 @@ queueProposal(Proposal p) async {
728754 Uint8List keccakHash = keccak256 (encodedInput);
729755 String hashHex = "0x${bytesToHex (keccakHash )}" ;
730756 print ("Keccak-256 hash: $hashHex " );
731- var sourceContract = Contract (p.org.address! , daoAbiString, Human ().web3user);
732- print ("facuram contractu" );
757+ final human = Human (); // Get the singleton instance
758+
759+ if (human.web3user == null ) {
760+ print ("Error in queueProposal: web3user is null." );
761+ return "not ok: Wallet not ready" ;
762+ }
763+
764+ var sourceContract = Contract (p.org.address! , daoAbiString, human.web3user); // Use human.web3user
765+ print ("queueProposal: Contract object created for chain: ${human .chain .name }" );
733766 try {
734- sourceContract = sourceContract.connect (Human ().web3user! .getSigner ());
735- print ("signed ok" );
767+ final signer = human.web3user! .getSigner (); // Get signer from current web3user
768+ sourceContract = sourceContract.connect (signer);
769+ print ("queueProposal: Contract connected with signer for chain: ${human .chain .name }" );
736770 List <String > calldatas = [];
737771 for (String c in p.callDatas) {
738772 calldatas.add ("0x$c " );
@@ -747,7 +781,7 @@ queueProposal(Proposal p) async {
747781
748782 final hash = json.decode (stringify (transaction))["hash" ];
749783 final result = await promiseToFuture (
750- callMethod (Human () .web3user! , 'waitForTransaction' , [hash]));
784+ callMethod (human .web3user! , 'waitForTransaction' , [hash])); // Use human.web3user
751785 if (json.decode (stringify (result))["status" ] == 0 ) {
752786 print ("nu merge eroare de greseala" );
753787 return "not ok" ;
@@ -775,11 +809,19 @@ execute(Proposal p) async {
775809 Uint8List keccakHash = keccak256 (encodedInput);
776810 String hashHex = "0x${bytesToHex (keccakHash )}" ;
777811 print ("Keccak-256 hash: $hashHex " );
778- var sourceContract = Contract (p.org.address! , daoAbiString, Human ().web3user);
779- print ("facuram contractu" );
812+ final human = Human (); // Get the singleton instance
813+
814+ if (human.web3user == null ) {
815+ print ("Error in execute: web3user is null." );
816+ return "not ok: Wallet not ready" ;
817+ }
818+
819+ var sourceContract = Contract (p.org.address! , daoAbiString, human.web3user); // Use human.web3user
820+ print ("execute: Contract object created for chain: ${human .chain .name }" );
780821 try {
781- sourceContract = sourceContract.connect (Human ().web3user! .getSigner ());
782- print ("signed okkkkk" );
822+ final signer = human.web3user! .getSigner (); // Get signer from current web3user
823+ sourceContract = sourceContract.connect (signer);
824+ print ("execute: Contract connected with signer for chain: ${human .chain .name }" );
783825 List <String > calldatas = [];
784826 for (String c in p.callDatas) {
785827 calldatas.add ("0x$c " );
@@ -793,7 +835,7 @@ execute(Proposal p) async {
793835 print ("facuram tranzactia" );
794836 final hash = json.decode (stringify (transaction))["hash" ];
795837 final result = await promiseToFuture (
796- callMethod (Human () .web3user! , 'waitForTransaction' , [hash]));
838+ callMethod (human .web3user! , 'waitForTransaction' , [hash])); // Use human.web3user
797839 if (json.decode (stringify (result))["status" ] == 0 ) {
798840 print ("nu merge eroare de greseala" );
799841 return "not ok" ;
@@ -813,17 +855,23 @@ execute(Proposal p) async {
813855}
814856
815857vote (Vote v, Org org) async {
816- var sourceContract = Contract (org.address! , daoAbiString, Human ().web3user);
817- print ("facuram contractu" );
858+ final human = Human (); // Get the singleton instance
859+ if (human.web3user == null ) {
860+ print ("Error in vote: web3user is null." );
861+ return "not ok: Wallet not ready" ;
862+ }
863+ var sourceContract = Contract (org.address! , daoAbiString, human.web3user); // Use human.web3user
864+ print ("vote: Contract object created for chain: ${human .chain .name }" );
818865 try {
819- print ("before signing" );
820- sourceContract = sourceContract.connect (Human ().web3user! .getSigner ());
866+ print ("vote: before signing for chain: ${human .chain .name }" );
867+ final signer = human.web3user! .getSigner (); // Get signer from current web3user
868+ sourceContract = sourceContract.connect (signer);
821869 final transaction = await promiseToFuture (callMethod (
822870 sourceContract, "castVote" , [v.proposalID, v.option.toString ()]));
823- print ("facuram tranzactia " );
871+ print ("vote: transaction submitted for chain: ${ human . chain . name } " );
824872 final hash = json.decode (stringify (transaction))["hash" ];
825873 final result = await promiseToFuture (
826- callMethod (Human () .web3user! , 'waitForTransaction' , [hash]));
874+ callMethod (human .web3user! , 'waitForTransaction' , [hash])); // Use human.web3user
827875 if (json.decode (stringify (result))["status" ] == 0 ) {
828876 print ("nu merge eroare de greseala" );
829877 return "not ok" ;
0 commit comments