Skip to content

Commit 816a2e6

Browse files
committed
add staking inclusion for gov.
1 parent 4f20b7f commit 816a2e6

File tree

4 files changed

+43
-48
lines changed

4 files changed

+43
-48
lines changed

src/components/pages/wallet/governance/drep/registerDrep.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { getDRepMetadata } from "./drepMetadata";
1313
import { getFile, hashDrepAnchor } from "@meshsdk/core";
1414
import type { UTxO } from "@meshsdk/core";
1515
import router from "next/router";
16+
import useMultisigWallet from "@/hooks/useMultisigWallet";
1617

1718
interface PutResponse {
1819
url: string;
@@ -26,6 +27,7 @@ export default function RegisterDRep() {
2627
const loading = useSiteStore((state) => state.loading);
2728
const setLoading = useSiteStore((state) => state.setLoading);
2829
const { newTransaction } = useTransaction();
30+
const { multisigWallet } = useMultisigWallet();
2931

3032
const [manualUtxos, setManualUtxos] = useState<UTxO[]>([]);
3133
const [formState, setFormState] = useState({
@@ -77,6 +79,7 @@ export default function RegisterDRep() {
7779
async function registerDrep(): Promise<void> {
7880
if (!connected || !userAddress || !appWallet)
7981
throw new Error("Wallet not connected");
82+
if (!multisigWallet) throw new Error("Multisig Wallet could not be built.");
8083

8184
setLoading(true);
8285
const txBuilder = getTxBuilder(network);
@@ -111,6 +114,18 @@ export default function RegisterDRep() {
111114
.changeAddress(appWallet.address)
112115
.selectUtxosFrom(manualUtxos);
113116

117+
const paymentKeys = multisigWallet.getKeysByRole(0) ?? [];
118+
for (const key of paymentKeys) {
119+
txBuilder.requiredSignerHash(key.keyHash);
120+
}
121+
122+
if (multisigWallet.stakingEnabled()) {
123+
const stakingKeys = multisigWallet.getKeysByRole(2) ?? [];
124+
for (const key of stakingKeys) {
125+
txBuilder.requiredSignerHash(key.keyHash);
126+
}
127+
}
128+
114129
await newTransaction({
115130
txBuilder,
116131
description: "DRep registration",

src/components/pages/wallet/governance/drep/retire.tsx

Lines changed: 13 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { Button } from "@/components/ui/button";
22
import { Wallet } from "@/types/wallet";
3-
// import { useState } from "react";
4-
// import { api } from "@/utils/api";
5-
// import { useToast } from "@/hooks/use-toast";
63
import { useSiteStore } from "@/lib/zustand/site";
74
import { getProvider } from "@/utils/get-provider";
85
import { getTxBuilder } from "@/utils/get-tx-builder";
@@ -11,40 +8,22 @@ import { useWallet } from "@meshsdk/react";
118
import { useUserStore } from "@/lib/zustand/user";
129
import { useWalletsStore } from "@/lib/zustand/wallets";
1310
import useTransaction from "@/hooks/useTransaction";
11+
import useMultisigWallet from "@/hooks/useMultisigWallet";
1412

1513
export 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,

src/components/pages/wallet/governance/drep/updateDrep.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { getDRepMetadata } from "./drepMetadata";
1313
import { getFile, hashDrepAnchor } from "@meshsdk/core";
1414
import type { UTxO } from "@meshsdk/core";
1515
import router from "next/router";
16+
import useMultisigWallet from "@/hooks/useMultisigWallet";
1617

1718
export default function UpdateDRep() {
1819
const { appWallet } = useAppWallet();
@@ -22,6 +23,7 @@ export default function UpdateDRep() {
2223
const loading = useSiteStore((state) => state.loading);
2324
const setLoading = useSiteStore((state) => state.setLoading);
2425
const { newTransaction } = useTransaction();
26+
const { multisigWallet } = useMultisigWallet();
2527

2628
const [manualUtxos, setManualUtxos] = useState<UTxO[]>([]);
2729
const [formState, setFormState] = useState({
@@ -70,6 +72,7 @@ export default function UpdateDRep() {
7072
async function updateDrep(): Promise<void> {
7173
if (!connected || !userAddress || !appWallet)
7274
throw new Error("Wallet not connected");
75+
if (!multisigWallet) throw new Error("Multisig Wallet could not be built.");
7376

7477
setLoading(true);
7578
const txBuilder = getTxBuilder(network);
@@ -104,6 +107,17 @@ export default function UpdateDRep() {
104107
.changeAddress(appWallet.address)
105108
.selectUtxosFrom(manualUtxos);
106109

110+
const paymentKeys = multisigWallet.getKeysByRole(0) ?? [];
111+
for (const key of paymentKeys) {
112+
txBuilder.requiredSignerHash(key.keyHash);
113+
}
114+
if (multisigWallet.stakingEnabled()) {
115+
const stakingKeys = multisigWallet.getKeysByRole(2) ?? [];
116+
for (const key of stakingKeys) {
117+
txBuilder.requiredSignerHash(key.keyHash);
118+
}
119+
}
120+
107121
await newTransaction({
108122
txBuilder,
109123
description: "DRep update",

src/hooks/useMultisigWallet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default function useMultisigWallet() {
1818
enabled: walletId !== undefined && userAddress !== undefined,
1919
},
2020
);
21-
if (wallet && network !== undefined) {
21+
if (wallet) {
2222
return { multisigWallet: buildMultisigWallet(wallet, network), isLoading };
2323
}
2424

0 commit comments

Comments
 (0)