Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 11 additions & 24 deletions src/components/pages/wallet/governance/drep/registerDrep.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Plus } from "lucide-react";
import { useState, useCallback } from "react";
import useAppWallet from "@/hooks/useAppWallet";
import { useWallet } from "@meshsdk/react";
import { useUserStore } from "@/lib/zustand/user";
import { useSiteStore } from "@/lib/zustand/site";
import { getTxBuilder } from "@/utils/get-tx-builder";
Expand All @@ -14,7 +13,6 @@ import type { UTxO } from "@meshsdk/core";
import router from "next/router";
import useMultisigWallet from "@/hooks/useMultisigWallet";
import { MeshProxyContract } from "@/components/multisig/proxy/offchain";
import { getProvider } from "@/utils/get-provider";
import { Label } from "@/components/ui/label";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { api } from "@/utils/api";
Expand All @@ -33,8 +31,7 @@ interface RegisterDRepProps {

export default function RegisterDRep({ onClose }: RegisterDRepProps = {}) {
const { appWallet } = useAppWallet();
const { connected, wallet } = useWallet();
const { isAnyWalletConnected, isWalletReady } = useActiveWallet();
const { activeWallet } = useActiveWallet();
const userAddress = useUserStore((state) => state.userAddress);
const network = useSiteStore((state) => state.network);
const loading = useSiteStore((state) => state.loading);
Expand Down Expand Up @@ -95,16 +92,6 @@ export default function RegisterDRep({ onClose }: RegisterDRepProps = {}) {
});
throw new Error(errorMessage);
}
if (!multisigWallet) {
const errorMessage = "Multisig wallet not connected. Please ensure your multisig wallet is properly configured.";
toast({
title: "Multisig Wallet Not Connected",
description: errorMessage,
variant: "destructive",
duration: 5000,
});
throw new Error(errorMessage);
}
// Get metadata with both compacted (for upload) and normalized (for hashing) forms
const metadataResult = await getDRepMetadata(
formState,
Expand Down Expand Up @@ -133,8 +120,8 @@ export default function RegisterDRep({ onClose }: RegisterDRepProps = {}) {
}

async function registerDrep(): Promise<void> {
if (!isWalletReady || !userAddress || !multisigWallet || !appWallet) {
const errorMessage = "Multisig wallet not connected. Please ensure your wallet is connected and try again.";
if (!activeWallet || !userAddress || !appWallet) {
const errorMessage = "Wallet not connected. Please ensure your wallet is connected and try again.";
toast({
title: "Wallet Not Connected",
description: errorMessage,
Expand Down Expand Up @@ -263,8 +250,13 @@ export default function RegisterDRep({ onClose }: RegisterDRepProps = {}) {
}

async function registerProxyDrep(): Promise<void> {
if (!isWalletReady || !userAddress || !multisigWallet || !appWallet) {
const errorMessage = "Multisig wallet not connected. Please ensure your wallet is connected and try again.";
if (!hasValidProxy) {
// Fall back to standard registration if no valid proxy
return registerDrep();
}

if (!activeWallet || !userAddress || !multisigWallet || !appWallet) {
const errorMessage = "Proxy registration requires both connected wallet signer and multisig wallet configuration.";
toast({
title: "Wallet Not Connected",
description: errorMessage,
Expand All @@ -274,11 +266,6 @@ export default function RegisterDRep({ onClose }: RegisterDRepProps = {}) {
throw new Error(errorMessage);
}

if (!hasValidProxy) {
// Fall back to standard registration if no valid proxy
return registerDrep();
}

setLoading(true);
try {
const { anchorUrl, anchorHash } = await createAnchor();
Expand All @@ -298,7 +285,7 @@ export default function RegisterDRep({ onClose }: RegisterDRepProps = {}) {
const proxyContract = new MeshProxyContract(
{
mesh: txBuilder,
wallet: wallet,
wallet: activeWallet,
networkId: network,
},
{
Expand Down
30 changes: 11 additions & 19 deletions src/components/pages/wallet/governance/drep/retire.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useSiteStore } from "@/lib/zustand/site";
import { getProvider } from "@/utils/get-provider";
import { getTxBuilder } from "@/utils/get-tx-builder";
import { keepRelevant, Quantity, Unit, UTxO } from "@meshsdk/core";
import { useWallet } from "@meshsdk/react";
import { useUserStore } from "@/lib/zustand/user";
import { useWalletsStore } from "@/lib/zustand/wallets";
import useTransaction from "@/hooks/useTransaction";
Expand All @@ -15,10 +14,11 @@ import { api } from "@/utils/api";
import { useCallback } from "react";
import { useToast } from "@/hooks/use-toast";
import { DREP_DEPOSIT_STRING } from "@/utils/protocol-deposit-constants";
import useActiveWallet from "@/hooks/useActiveWallet";

export default function Retire({ appWallet, manualUtxos }: { appWallet: Wallet; manualUtxos: UTxO[] }) {
const network = useSiteStore((state) => state.network);
const { wallet, connected } = useWallet();
const { activeWallet } = useActiveWallet();
const userAddress = useUserStore((state) => state.userAddress);
const drepInfo = useWalletsStore((state) => state.drepInfo);
const { newTransaction } = useTransaction();
Expand Down Expand Up @@ -53,18 +53,19 @@ export default function Retire({ appWallet, manualUtxos }: { appWallet: Wallet;
}, [multisigWallet?.getScript().address, manualUtxos]);

async function retireProxyDrep(): Promise<void> {
if (!connected || !userAddress || !multisigWallet || !appWallet) {
if (!hasValidProxy) {
// Fall back to standard retire if no valid proxy
return retireDrep();
}

if (!activeWallet || !userAddress || !multisigWallet || !appWallet) {
toast({
title: "Connection Error",
description: "Multisig wallet not connected",
description: "Proxy retirement requires both connected wallet signer and multisig wallet configuration.",
variant: "destructive",
});
return;
}
if (!hasValidProxy) {
// Fall back to standard retire if no valid proxy
return retireDrep();
}

setLoading(true);

Expand Down Expand Up @@ -96,7 +97,7 @@ export default function Retire({ appWallet, manualUtxos }: { appWallet: Wallet;
const proxyContract = new MeshProxyContract(
{
mesh: txBuilder,
wallet: wallet,
wallet: activeWallet,
networkId: network,
},
{
Expand Down Expand Up @@ -127,7 +128,7 @@ export default function Retire({ appWallet, manualUtxos }: { appWallet: Wallet;
}

async function retireDrep() {
if (!connected) {
if (!activeWallet) {
toast({
title: "Connection Error",
description: "Not connected to wallet",
Expand All @@ -143,15 +144,6 @@ export default function Retire({ appWallet, manualUtxos }: { appWallet: Wallet;
});
return;
}
if (!multisigWallet) {
toast({
title: "Wallet Error",
description: "Multisig Wallet could not be built",
variant: "destructive",
});
return;
}

setLoading(true);

try {
Expand Down
Loading