11import { Button } from "@/components/ui/button" ;
22import { Wallet } from "@/types/wallet" ;
3- // import { useState } from "react";
4- // import { api } from "@/utils/api";
5- // import { useToast } from "@/hooks/use-toast";
63import { useSiteStore } from "@/lib/zustand/site" ;
74import { getProvider } from "@/utils/get-provider" ;
85import { getTxBuilder } from "@/utils/get-tx-builder" ;
@@ -11,40 +8,22 @@ import { useWallet } from "@meshsdk/react";
118import { useUserStore } from "@/lib/zustand/user" ;
129import { useWalletsStore } from "@/lib/zustand/wallets" ;
1310import useTransaction from "@/hooks/useTransaction" ;
11+ import useMultisigWallet from "@/hooks/useMultisigWallet" ;
1412
1513export default function Retire ( { appWallet } : { appWallet : Wallet } ) {
16- // const [loading, setLoading] = useState<boolean>(false);
17- // const { toast } = useToast();
18- // const ctx = api.useUtils();
1914 const network = useSiteStore ( ( state ) => state . network ) ;
2015 const { connected } = useWallet ( ) ;
2116 const userAddress = useUserStore ( ( state ) => state . userAddress ) ;
2217 const drepInfo = useWalletsStore ( ( state ) => state . drepInfo ) ;
2318 const { newTransaction } = useTransaction ( ) ;
2419 const loading = useSiteStore ( ( state ) => state . loading ) ;
2520 const setLoading = useSiteStore ( ( state ) => state . setLoading ) ;
26-
27- // const { mutate: createTransaction } =
28- // api.transaction.createTransaction.useMutation({
29- // onSuccess: async () => {
30- // setLoading(false);
31- // toast({
32- // title: "Transaction Created",
33- // description: "DRep registration transaction has been created",
34- // duration: 5000,
35- // });
36- // void ctx.transaction.getPendingTransactions.invalidate();
37- // void ctx.transaction.getAllTransactions.invalidate();
38- // },
39- // onError: (e) => {
40- // console.error(e);
41- // setLoading(false);
42- // },
43- // });
21+ const { multisigWallet } = useMultisigWallet ( ) ;
4422
4523 async function retireDrep ( ) {
4624 if ( ! connected ) throw new Error ( "Not connected to wallet" ) ;
4725 if ( ! userAddress ) throw new Error ( "No user address" ) ;
26+ if ( ! multisigWallet ) throw new Error ( "Multisig Wallet could not be built." ) ;
4827
4928 setLoading ( true ) ;
5029
@@ -73,29 +52,16 @@ export default function Retire({ appWallet }: { appWallet: Wallet }) {
7352 . drepDeregistrationCertificate ( appWallet . dRepId , "500000000" )
7453 . certificateScript ( appWallet . scriptCbor ) ;
7554
76- // const unsignedTx = await txBuilder.complete();
77-
78- // const signedTx = await wallet.signTx(unsignedTx, true);
79-
80- // const signedAddresses = [];
81- // signedAddresses.push(userAddress);
82-
83- // let txHash = undefined;
84- // let state = 0;
85- // if (appWallet.numRequiredSigners == signedAddresses.length) {
86- // state = 1;
87- // txHash = await wallet.submitTx(signedTx);
88- // }
89-
90- // createTransaction({
91- // walletId: appWallet.id,
92- // txJson: JSON.stringify(txBuilder.meshTxBuilderBody),
93- // txCbor: signedTx,
94- // signedAddresses: [userAddress],
95- // state: state,
96- // description: "DRep retirement",
97- // txHash: txHash,
98- // });
55+ const paymentKeys = multisigWallet . getKeysByRole ( 0 ) ?? [ ] ;
56+ for ( const key of paymentKeys ) {
57+ txBuilder . requiredSignerHash ( key . keyHash ) ;
58+ }
59+ if ( multisigWallet . stakingEnabled ( ) ) {
60+ const stakingKeys = multisigWallet . getKeysByRole ( 2 ) ?? [ ] ;
61+ for ( const key of stakingKeys ) {
62+ txBuilder . requiredSignerHash ( key . keyHash ) ;
63+ }
64+ }
9965
10066 await newTransaction ( {
10167 txBuilder,
0 commit comments