Skip to content

Commit 73a2728

Browse files
authored
Merge pull request #149 from MeshJS/bug/drep-id
fix(wallet): improve DRep ID retrieval and error handling
2 parents 17b088d + a27b24a commit 73a2728

File tree

7 files changed

+34
-12
lines changed

7 files changed

+34
-12
lines changed

src/components/common/overall-layout/layout.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,10 @@ export default function RootLayout({
135135
let drepKeyHash = "";
136136
try {
137137
const dRepKey = await wallet.getDRep();
138-
console.log("DRep key:", dRepKey);
139138
if (dRepKey && dRepKey.publicKeyHash) {
140139
drepKeyHash = dRepKey.publicKeyHash;
141140
}
142141
} catch (error) {
143-
// DRep key is optional, so we continue without it
144-
console.log("No DRep key available for this wallet");
145142
}
146143

147144
// 4) Create or update user (upsert pattern handles both cases)

src/components/pages/wallet/governance/card-info.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ export default function CardInfo({ appWallet }: { appWallet: Wallet }) {
1919
const { toast } = useToast();
2020

2121
// Get DRep ID from multisig wallet if available, otherwise fallback to appWallet
22-
const dRepId = multisigWallet?.getDRepId() || appWallet.dRepId;
22+
const dRepId = multisigWallet?.getKeysByRole(3) ? multisigWallet?.getDRepId() : appWallet?.dRepId;
23+
if (!dRepId) {
24+
throw new Error("DRep not found");
25+
}
2326

2427
// Check if DRep is actually registered (has info from Blockfrost)
2528
const isDRepRegistered = drepInfo?.active === true;

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ export default function RegisterDRep() {
8484

8585
setLoading(true);
8686
const txBuilder = getTxBuilder(network);
87-
const drepIds = getDRepIds(multisigWallet.getDRepId()!);
87+
const dRepId = multisigWallet?.getKeysByRole(3) ? multisigWallet?.getDRepId() : appWallet?.dRepId;
88+
if (!dRepId) {
89+
throw new Error("DRep not found");
90+
}
8891
try {
8992
const { anchorUrl, anchorHash } = await createAnchor();
9093

@@ -107,7 +110,7 @@ export default function RegisterDRep() {
107110
}
108111

109112
txBuilder
110-
.drepRegistrationCertificate(drepIds.cip105, {
113+
.drepRegistrationCertificate(dRepId, {
111114
anchorUrl: anchorUrl,
112115
anchorDataHash: anchorHash,
113116
})

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ export default function Retire({ appWallet }: { appWallet: Wallet }) {
3636
if (selectedUtxos.length === 0) throw new Error("No relevant UTxOs found");
3737

3838
const txBuilder = getTxBuilder(network);
39-
39+
const dRepId = multisigWallet?.getKeysByRole(3) ? multisigWallet?.getDRepId() : appWallet?.dRepId;
40+
if (!dRepId) {
41+
throw new Error("DRep not found");
42+
}
4043
for (const utxo of selectedUtxos) {
4144
txBuilder.txIn(
4245
utxo.input.txHash,
@@ -49,7 +52,7 @@ export default function Retire({ appWallet }: { appWallet: Wallet }) {
4952
txBuilder
5053
.txInScript(multisigWallet.getScript().scriptCbor!)
5154
.changeAddress(multisigWallet.getScript().address)
52-
.drepDeregistrationCertificate(multisigWallet.getDRepId()!, "500000000")
55+
.drepDeregistrationCertificate(dRepId, "500000000")
5356
.certificateScript(multisigWallet.getDRepScript()!);
5457

5558
await newTransaction({

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ export default function UpdateDRep() {
8484

8585
setLoading(true);
8686
const txBuilder = getTxBuilder(network);
87-
const drepIds = getDRepIds(multisigWallet.getDRepId()!);
87+
const dRepId = multisigWallet?.getKeysByRole(3) ? multisigWallet?.getDRepId() : appWallet?.dRepId;
88+
if (!dRepId) {
89+
throw new Error("DRep not found");
90+
}
8891
try {
8992
const { anchorUrl, anchorHash } = await createAnchor();
9093

@@ -107,7 +110,7 @@ export default function UpdateDRep() {
107110
}
108111

109112
txBuilder
110-
.drepUpdateCertificate(drepIds.cip105, {
113+
.drepUpdateCertificate(dRepId, {
111114
anchorUrl: anchorUrl,
112115
anchorDataHash: anchorHash,
113116
})

src/components/pages/wallet/governance/proposal/voteButtton.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,17 @@ export default function VoteButton({
9292
}
9393
if (!multisigWallet)
9494
throw new Error("Multisig Wallet could not be built.");
95-
const dRepId = appWallet.dRepId;
95+
const dRepId = multisigWallet?.getKeysByRole(3) ? multisigWallet?.getDRepId() : appWallet?.dRepId;
96+
if (!dRepId) {
97+
setAlert("DRep not found");
98+
toast({
99+
title: "DRep not found",
100+
description: `Please register as a DRep and retry.`,
101+
duration: 10000,
102+
variant: "destructive",
103+
});
104+
return;
105+
}
96106
const txBuilder = getTxBuilder(network);
97107

98108
const assetMap = new Map<Unit, Quantity>();

src/components/pages/wallet/info/card-info.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ function ShowInfo({ appWallet }: { appWallet: Wallet }) {
175175
const { multisigWallet } = useMultisigWallet();
176176

177177
// Get DRep ID from multisig wallet if available, otherwise fallback to appWallet
178-
const dRepId = multisigWallet?.getDRepId() || appWallet.dRepId;
178+
const dRepId = multisigWallet?.getKeysByRole(3) ? multisigWallet?.getDRepId() : appWallet?.dRepId;
179+
if (!dRepId) {
180+
throw new Error("DRep not found");
181+
}
179182

180183
return (
181184
<>

0 commit comments

Comments
 (0)