@@ -184,6 +184,7 @@ interface CardanoContextType {
184184 setStakeKey : ( key : string ) => void ;
185185 stakeKeys : string [ ] ;
186186 walletApi ?: CardanoApiWallet ;
187+ registeredStakeKeysListState : string [ ] ;
187188 buildSignSubmitConwayCertTx : ( {
188189 certBuilder,
189190 govActionBuilder,
@@ -192,8 +193,9 @@ interface CardanoContextType {
192193 votingBuilder,
193194 voter,
194195 } : BuildSignSubmitConwayCertTxArgs ) => Promise < string > ;
196+ buildStakeKeyRegCert : ( ) => Promise < Certificate > ;
195197 buildDRepRegCert : ( url ?: string , hash ?: string ) => Promise < Certificate > ;
196- buildVoteDelegationCert : ( vote : string ) => Promise < CertificatesBuilder > ;
198+ buildVoteDelegationCert : ( vote : string ) => Promise < Certificate > ;
197199 buildDRepUpdateCert : ( url ?: string , hash ?: string ) => Promise < Certificate > ;
198200 buildDRepRetirementCert : ( voterDeposit : string ) => Promise < Certificate > ;
199201 buildVote : (
@@ -626,28 +628,34 @@ const CardanoProvider = (props: Props) => {
626628 [ isPendingTransaction , stakeKey , updateTransaction , walletApi , walletState ] ,
627629 ) ;
628630
631+ const buildStakeKeyRegCert = useCallback ( async ( ) : Promise < Certificate > => {
632+ try {
633+ if ( ! stakeKey ) {
634+ throw new Error ( t ( "errors.noStakeKeySelected" ) ) ;
635+ }
636+ const stakeKeyHash = Ed25519KeyHash . from_hex ( stakeKey . substring ( 2 ) ) ;
637+ const stakeCred = Credential . from_keyhash ( stakeKeyHash ) ;
638+ const stakeKeyRegCert = StakeRegistration . new_with_explicit_deposit (
639+ stakeCred ,
640+ BigNum . from_str ( `${ epochParams . key_deposit } ` ) ,
641+ ) ;
642+ return Certificate . new_stake_registration ( stakeKeyRegCert ) ;
643+ } catch ( e ) {
644+ console . error ( e ) ;
645+ throw e ;
646+ }
647+ } , [ epochParams ] ) ;
648+
629649 const buildVoteDelegationCert = useCallback (
630- async ( target : string ) : Promise < CertificatesBuilder > => {
650+ async ( target : string ) : Promise < Certificate > => {
631651 try {
632652 // Build Vote Delegation Certificate
633- const certBuilder = CertificatesBuilder . new ( ) ;
634- let stakeCred ;
635653 if ( ! stakeKey ) {
636654 throw new Error ( t ( "errors.noStakeKeySelected" ) ) ;
637655 }
638656 // Remove network tag from stake key hash
639657 const stakeKeyHash = Ed25519KeyHash . from_hex ( stakeKey . substring ( 2 ) ) ;
640- // if chosen stake key is registered use it, else register it
641- if ( registeredStakeKeysListState . length > 0 ) {
642- stakeCred = Credential . from_keyhash ( stakeKeyHash ) ;
643- } else {
644- stakeCred = Credential . from_keyhash ( stakeKeyHash ) ;
645- const stakeKeyRegCert = StakeRegistration . new_with_explicit_deposit (
646- stakeCred ,
647- BigNum . from_str ( `${ epochParams . key_deposit } ` ) ,
648- ) ;
649- certBuilder . add ( Certificate . new_stake_registration ( stakeKeyRegCert ) ) ;
650- }
658+ const stakeCred = Credential . from_keyhash ( stakeKeyHash ) ;
651659
652660 // Create correct DRep
653661 let targetDRep ;
@@ -665,9 +673,7 @@ const CardanoProvider = (props: Props) => {
665673 // Create cert object
666674 const voteDelegationCert = VoteDelegation . new ( stakeCred , targetDRep ) ;
667675 // add cert to tbuilder
668- certBuilder . add ( Certificate . new_vote_delegation ( voteDelegationCert ) ) ;
669-
670- return certBuilder ;
676+ return Certificate . new_vote_delegation ( voteDelegationCert ) ;
671677 } catch ( e ) {
672678 console . error ( e ) ;
673679 throw e ;
@@ -1039,24 +1045,26 @@ const CardanoProvider = (props: Props) => {
10391045 buildDRepRegCert,
10401046 buildDRepRetirementCert,
10411047 buildDRepUpdateCert,
1048+ buildHardForkGovernanceAction,
10421049 buildNewInfoGovernanceAction,
1050+ buildProtocolParameterChangeGovernanceAction,
10431051 buildSignSubmitConwayCertTx,
1052+ buildStakeKeyRegCert,
10441053 buildTreasuryGovernanceAction,
1045- buildProtocolParameterChangeGovernanceAction,
1046- buildHardForkGovernanceAction,
10471054 buildVote,
10481055 buildVoteDelegationCert,
1049- disconnectWallet,
1050- getChangeAddress,
10511056 dRepID,
1057+ disconnectWallet,
10521058 enable,
10531059 error,
1054- isEnabled ,
1060+ getChangeAddress ,
10551061 isEnableLoading,
1062+ isEnabled,
10561063 isMainnet,
10571064 isPendingTransaction,
10581065 pendingTransaction,
10591066 pubDRepKey,
1067+ registeredStakeKeysListState,
10601068 setStakeKey,
10611069 stakeKey,
10621070 stakeKeys,
@@ -1067,24 +1075,26 @@ const CardanoProvider = (props: Props) => {
10671075 buildDRepRegCert ,
10681076 buildDRepRetirementCert ,
10691077 buildDRepUpdateCert ,
1078+ buildHardForkGovernanceAction ,
10701079 buildNewInfoGovernanceAction ,
1080+ buildProtocolParameterChangeGovernanceAction ,
10711081 buildSignSubmitConwayCertTx ,
1082+ buildStakeKeyRegCert ,
10721083 buildTreasuryGovernanceAction ,
1073- buildProtocolParameterChangeGovernanceAction ,
1074- buildHardForkGovernanceAction ,
10751084 buildVote ,
10761085 buildVoteDelegationCert ,
1077- disconnectWallet ,
1078- getChangeAddress ,
10791086 dRepID ,
1087+ disconnectWallet ,
10801088 enable ,
10811089 error ,
1082- isEnabled ,
1090+ getChangeAddress ,
10831091 isEnableLoading ,
1092+ isEnabled ,
10841093 isMainnet ,
10851094 isPendingTransaction ,
10861095 pendingTransaction ,
10871096 pubDRepKey ,
1097+ registeredStakeKeysListState ,
10881098 setStakeKey ,
10891099 stakeKey ,
10901100 stakeKeys ,
0 commit comments