diff --git a/prisma/schema.prisma b/prisma/schema.prisma index c5d8a416..ef466d65 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -107,4 +107,4 @@ model BalanceSnapshot { assetBalances Json isArchived Boolean snapshotDate DateTime @default(now()) -} \ No newline at end of file +} diff --git a/src/components/pages/wallet/governance/ballot/ballot.tsx b/src/components/pages/wallet/governance/ballot/ballot.tsx index 528f5af5..d0b2b997 100644 --- a/src/components/pages/wallet/governance/ballot/ballot.tsx +++ b/src/components/pages/wallet/governance/ballot/ballot.tsx @@ -118,7 +118,32 @@ export default function BallotCard({ setLoading(true); try { if (!multisigWallet) throw new Error("Multisig Wallet could not be built."); - const dRepId = appWallet.dRepId; + const dRepId = multisigWallet?.getKeysByRole(3) ? multisigWallet?.getDRepId() : appWallet?.dRepId; + if (!dRepId) { + setAlert("DRep not found"); + toast({ + title: "DRep not found", + description: `Please register as a DRep and retry.`, + duration: 10000, + variant: "destructive", + }); + return; + } + const scriptCbor = multisigWallet?.getKeysByRole(3) ? multisigWallet?.getScript().scriptCbor : appWallet.scriptCbor; + const drepCbor = multisigWallet?.getKeysByRole(3) ? multisigWallet?.getDRepScript() : appWallet.scriptCbor; + if (!scriptCbor) { + setAlert("Script not found"); + return; + } + if (!drepCbor) { + setAlert("DRep script not found"); + return; + } + const changeAddress = multisigWallet?.getKeysByRole(3) ? multisigWallet?.getScript().address : appWallet.address; + if (!changeAddress) { + setAlert("Change address not found"); + return; + } const txBuilder = getTxBuilder(network); // Ensure minimum ADA for fee and voting @@ -134,7 +159,7 @@ export default function BallotCard({ utxo.output.amount, utxo.output.address, ) - .txInScript(appWallet.scriptCbor); + .txInScript(scriptCbor); } // Submit a vote for each proposal in the ballot @@ -162,9 +187,8 @@ export default function BallotCard({ } txBuilder - .voteScript(appWallet.scriptCbor) - .selectUtxosFrom(utxos) - .changeAddress(appWallet.address); + .voteScript(drepCbor) + .changeAddress(changeAddress); await newTransaction({ txBuilder, diff --git a/src/components/pages/wallet/governance/drep/registerDrep.tsx b/src/components/pages/wallet/governance/drep/registerDrep.tsx index 1784161f..44557189 100644 --- a/src/components/pages/wallet/governance/drep/registerDrep.tsx +++ b/src/components/pages/wallet/governance/drep/registerDrep.tsx @@ -88,6 +88,14 @@ export default function RegisterDRep() { if (!dRepId) { throw new Error("DRep not found"); } + const scriptCbor = multisigWallet?.getKeysByRole(3) ? multisigWallet?.getScript().scriptCbor : appWallet.scriptCbor; + const drepCbor = multisigWallet?.getKeysByRole(3) ? multisigWallet?.getDRepScript() : appWallet.scriptCbor; + if (!scriptCbor) { + throw new Error("Script not found"); + } + if (!drepCbor) { + throw new Error("DRep script not found"); + } try { const { anchorUrl, anchorHash } = await createAnchor(); @@ -106,7 +114,7 @@ export default function RegisterDRep() { utxo.output.amount, utxo.output.address, ) - .txInScript(multisigWallet.getScript().scriptCbor!); + .txInScript(scriptCbor); } txBuilder @@ -114,7 +122,7 @@ export default function RegisterDRep() { anchorUrl: anchorUrl, anchorDataHash: anchorHash, }) - .certificateScript(multisigWallet.getDRepScript()!) + .certificateScript(drepCbor) .changeAddress(multisigWallet.getScript().address); diff --git a/src/components/pages/wallet/governance/drep/retire.tsx b/src/components/pages/wallet/governance/drep/retire.tsx index f76a7cee..88ed5679 100644 --- a/src/components/pages/wallet/governance/drep/retire.tsx +++ b/src/components/pages/wallet/governance/drep/retire.tsx @@ -37,6 +37,18 @@ export default function Retire({ appWallet }: { appWallet: Wallet }) { const txBuilder = getTxBuilder(network); const dRepId = multisigWallet?.getKeysByRole(3) ? multisigWallet?.getDRepId() : appWallet?.dRepId; + const scriptCbor = multisigWallet?.getKeysByRole(3) ? multisigWallet?.getScript().scriptCbor : appWallet.scriptCbor; + const drepCbor = multisigWallet?.getKeysByRole(3) ? multisigWallet?.getDRepScript() : appWallet.scriptCbor; + const changeAddress = multisigWallet?.getKeysByRole(3) ? multisigWallet?.getScript().address : appWallet.address; + if (!changeAddress) { + throw new Error("Change address not found"); + } + if (!scriptCbor) { + throw new Error("Script not found"); + } + if (!drepCbor) { + throw new Error("DRep script not found"); + } if (!dRepId) { throw new Error("DRep not found"); } @@ -50,10 +62,10 @@ export default function Retire({ appWallet }: { appWallet: Wallet }) { } txBuilder - .txInScript(multisigWallet.getScript().scriptCbor!) - .changeAddress(multisigWallet.getScript().address) + .txInScript(scriptCbor) + .changeAddress(changeAddress) .drepDeregistrationCertificate(dRepId, "500000000") - .certificateScript(multisigWallet.getDRepScript()!); + .certificateScript(drepCbor); await newTransaction({ txBuilder, diff --git a/src/components/pages/wallet/governance/drep/updateDrep.tsx b/src/components/pages/wallet/governance/drep/updateDrep.tsx index 5725c22a..c0145a43 100644 --- a/src/components/pages/wallet/governance/drep/updateDrep.tsx +++ b/src/components/pages/wallet/governance/drep/updateDrep.tsx @@ -88,6 +88,18 @@ export default function UpdateDRep() { if (!dRepId) { throw new Error("DRep not found"); } + const scriptCbor = multisigWallet?.getKeysByRole(3) ? multisigWallet?.getScript().scriptCbor : appWallet.scriptCbor; + const drepCbor = multisigWallet?.getKeysByRole(3) ? multisigWallet?.getDRepScript() : appWallet.scriptCbor; + if (!scriptCbor) { + throw new Error("Script not found"); + } + if (!drepCbor) { + throw new Error("DRep script not found"); + } + const changeAddress = multisigWallet?.getKeysByRole(3) ? multisigWallet?.getScript().address : appWallet.address; + if (!changeAddress) { + throw new Error("Change address not found"); + } try { const { anchorUrl, anchorHash } = await createAnchor(); @@ -106,7 +118,7 @@ export default function UpdateDRep() { utxo.output.amount, utxo.output.address, ) - .txInScript(multisigWallet.getScript().scriptCbor!); + .txInScript(scriptCbor); } txBuilder @@ -114,8 +126,8 @@ export default function UpdateDRep() { anchorUrl: anchorUrl, anchorDataHash: anchorHash, }) - .certificateScript(multisigWallet.getDRepScript()!) - .changeAddress(multisigWallet.getScript().address); + .certificateScript(drepCbor) + .changeAddress(changeAddress); await newTransaction({ txBuilder, diff --git a/src/components/pages/wallet/governance/proposal/voteButtton.tsx b/src/components/pages/wallet/governance/proposal/voteButtton.tsx index 2a981663..27bb980d 100644 --- a/src/components/pages/wallet/governance/proposal/voteButtton.tsx +++ b/src/components/pages/wallet/governance/proposal/voteButtton.tsx @@ -103,6 +103,21 @@ export default function VoteButton({ }); return; } + const scriptCbor = multisigWallet?.getKeysByRole(3) ? multisigWallet?.getScript().scriptCbor : appWallet.scriptCbor; + const drepCbor = multisigWallet?.getKeysByRole(3) ? multisigWallet?.getDRepScript() : appWallet.scriptCbor; + if (!scriptCbor) { + setAlert("Script not found"); + return; + } + if (!drepCbor) { + setAlert("DRep script not found"); + return; + } + const changeAddress = multisigWallet?.getKeysByRole(3) ? multisigWallet?.getScript().address : appWallet.address; + if (!changeAddress) { + setAlert("Change address not found"); + return; + } const txBuilder = getTxBuilder(network); const assetMap = new Map(); @@ -117,7 +132,7 @@ export default function VoteButton({ utxo.output.amount, utxo.output.address, ) - .txInScript(appWallet.scriptCbor); + .txInScript(scriptCbor); } txBuilder .vote( @@ -133,8 +148,8 @@ export default function VoteButton({ voteKind: voteKind, }, ) - .voteScript(appWallet.scriptCbor) - .changeAddress(appWallet.address); + .voteScript(drepCbor) + .changeAddress(changeAddress); await newTransaction({ txBuilder,