Skip to content

Commit a2be30c

Browse files
authored
Merge pull request #117 from MeshJS/bug/GA
fix and ad utxo blocking
2 parents 47e308d + 6d6495f commit a2be30c

File tree

5 files changed

+51
-31
lines changed

5 files changed

+51
-31
lines changed

src/components/pages/wallet/governance/index.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export default function PageGovernance() {
2727
<main className="flex flex-1 flex-col gap-4 p-4 md:gap-8 md:p-8">
2828
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
2929
<CardInfo appWallet={appWallet} />
30-
<AllProposals appWallet={appWallet} />
31-
<VoteCard appWallet={appWallet} />
30+
<AllProposals appWallet={appWallet} utxos={manualUtxos} />
31+
<VoteCard appWallet={appWallet} utxos={manualUtxos} />
3232
<ClarityCard appWallet={appWallet} />
3333
<div className="flex flex-col gap-4 col-span-2">
3434
{appWallet && (
@@ -41,12 +41,14 @@ export default function PageGovernance() {
4141
}}
4242
/>
4343
)}
44-
<VoteCC
45-
manualUtxos={manualUtxos}
46-
manualSelected={manualSelected}
47-
appWallet={appWallet}
48-
network={network}
49-
/>
44+
{false && (
45+
<VoteCC
46+
manualUtxos={manualUtxos}
47+
manualSelected={manualSelected}
48+
appWallet={appWallet}
49+
network={network}
50+
/>
51+
)}
5052
</div>
5153
</div>
5254
</main>

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,23 @@ import Button from "@/components/common/button";
99
import { useWalletsStore } from "@/lib/zustand/wallets";
1010
import useAppWallet from "@/hooks/useAppWallet";
1111
import VoteCard from "../vote-card";
12+
import { UTxO } from "@meshsdk/core";
13+
import UTxOSelector from "../../new-transaction/utxoSelector";
1214

13-
export default function WalletGovernanceProposal({ id }: { id: string }) {
15+
export default function WalletGovernanceProposal({
16+
id,
17+
}: {
18+
id: string;
19+
}) {
1420
const network = useSiteStore((state) => state.network);
1521
const [proposalMetadata, setProposalMetadata] = useState<
1622
ProposalMetadata | undefined
1723
>(undefined);
1824
const drepInfo = useWalletsStore((state) => state.drepInfo);
1925
const { appWallet } = useAppWallet();
2026
const loading = useSiteStore((state) => state.loading);
27+
const [manualUtxos, setManualUtxos] = useState<UTxO[]>([]);
28+
const [manualSelected, setManualSelected] = useState(false);
2129

2230
useEffect(() => {
2331
const blockchainProvider = getProvider(network);
@@ -34,7 +42,6 @@ export default function WalletGovernanceProposal({ id }: { id: string }) {
3442
get();
3543
}, []);
3644

37-
3845
if (!proposalMetadata) return <></>;
3946

4047
return (
@@ -91,7 +98,23 @@ export default function WalletGovernanceProposal({ id }: { id: string }) {
9198
allowOverflow={true}
9299
/>
93100
</CardUI>
94-
{appWallet && <VoteCard appWallet={appWallet} proposalId={`${proposalMetadata.tx_hash}#${proposalMetadata.cert_index}`}/>}
101+
{appWallet && (
102+
<UTxOSelector
103+
appWallet={appWallet}
104+
network={network}
105+
onSelectionChange={(utxos, manual) => {
106+
setManualUtxos(utxos);
107+
setManualSelected(manual);
108+
}}
109+
/>
110+
)}
111+
{appWallet && (
112+
<VoteCard
113+
appWallet={appWallet}
114+
utxos={manualUtxos}
115+
proposalId={`${proposalMetadata.tx_hash}#${proposalMetadata.cert_index}`}
116+
/>
117+
)}
95118
</main>
96119
);
97120
}

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

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useSiteStore } from "@/lib/zustand/site";
44
import { getTxBuilder } from "@/utils/get-tx-builder";
55
import { getProvider } from "@/utils/get-provider";
66
import useTransaction from "@/hooks/useTransaction";
7-
import { keepRelevant, Quantity, Unit } from "@meshsdk/core";
7+
import { keepRelevant, Quantity, Unit, UTxO } from "@meshsdk/core";
88
import { Wallet } from "@/types/wallet";
99
import { useWalletsStore } from "@/lib/zustand/wallets";
1010
import { useToast } from "@/hooks/use-toast";
@@ -24,13 +24,15 @@ interface VoteButtonProps {
2424
proposalId: string;
2525
description?: string;
2626
metadata?: string;
27+
utxos: UTxO[];
2728
}
2829

2930
export default function VoteButton({
3031
appWallet,
3132
proposalId,
3233
description = "",
3334
metadata = "",
35+
utxos,
3436
}: VoteButtonProps) {
3537
const drepInfo = useWalletsStore((state) => state.drepInfo);
3638
const [loading, setLoading] = useState(false);
@@ -65,10 +67,6 @@ export default function VoteButton({
6567
throw new Error("Multisig Wallet could not be built.");
6668
const dRepId = appWallet.dRepId;
6769
const txBuilder = getTxBuilder(network);
68-
const blockchainProvider = getProvider(network);
69-
const utxos = await blockchainProvider.fetchAddressUTxOs(
70-
appWallet.address,
71-
);
7270

7371
const assetMap = new Map<Unit, Quantity>();
7472
assetMap.set("lovelace", "5000000");
@@ -102,17 +100,6 @@ export default function VoteButton({
102100
.selectUtxosFrom(utxos)
103101
.changeAddress(appWallet.address);
104102

105-
const paymentKeys = multisigWallet.getKeysByRole(0) ?? [];
106-
for (const key of paymentKeys) {
107-
txBuilder.requiredSignerHash(key.keyHash);
108-
}
109-
110-
if (multisigWallet.stakingEnabled()) {
111-
const stakingKeys = multisigWallet.getKeysByRole(2) ?? [];
112-
for (const key of stakingKeys) {
113-
txBuilder.requiredSignerHash(key.keyHash);
114-
}
115-
}
116103
await newTransaction({
117104
txBuilder,
118105
description: `Vote: ${voteKind} - ${description}`,
@@ -187,10 +174,10 @@ export default function VoteButton({
187174

188175
<Button
189176
onClick={vote}
190-
disabled={loading || proposalId.length !== 66}
177+
disabled={loading || proposalId.length !== 66 || utxos.length === 0}
191178
className="w-full rounded-md bg-blue-600 px-6 py-2 font-semibold text-white shadow hover:bg-blue-700"
192179
>
193-
{loading ? "Voting..." : "Vote"}
180+
{loading ? "Voting..." : utxos.length > 0 ? "Vote" : "No UTxOs Available"}
194181
</Button>
195182
</div>
196183
);

src/components/pages/wallet/governance/proposals.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ import {
2424
} from "@/components/ui/dialog";
2525
import Link from "next/link";
2626
import VoteButton from "./proposal/voteButtton";
27+
import { UTxO } from "@meshsdk/core";
2728

28-
export default function AllProposals({ appWallet }: { appWallet: Wallet }) {
29+
export default function AllProposals({ appWallet, utxos }: { appWallet: Wallet; utxos: UTxO[] }) {
2930
const network = useSiteStore((state) => state.network);
3031
const [proposals, setProposals] = useState<ProposalMetadata[]>([]);
3132
const [limit, setLimit] = useState(5);
@@ -102,6 +103,7 @@ export default function AllProposals({ appWallet }: { appWallet: Wallet }) {
102103
key={proposal.tx_hash}
103104
proposal={proposal}
104105
appWallet={appWallet}
106+
utxos={utxos}
105107
/>
106108
))}
107109
</TableBody>
@@ -125,9 +127,11 @@ export default function AllProposals({ appWallet }: { appWallet: Wallet }) {
125127
function ProposalRow({
126128
proposal,
127129
appWallet,
130+
utxos,
128131
}: {
129132
proposal: ProposalMetadata;
130133
appWallet: Wallet;
134+
utxos: UTxO[];
131135
}) {
132136
return (
133137
<TableRow>
@@ -149,6 +153,7 @@ function ProposalRow({
149153
</TableCell>
150154
<TableCell>
151155
<VoteButton
156+
utxos={utxos}
152157
appWallet={appWallet}
153158
proposalId={proposal.tx_hash + "#" + proposal.cert_index}
154159
/>

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import { Label } from "@/components/ui/label";
66
import { Textarea } from "@/components/ui/textarea";
77
import { useState } from "react";
88
import VoteButton from "./proposal/voteButtton";
9+
import { UTxO } from "@meshsdk/core";
910

1011
interface VoteCardProps {
1112
appWallet: Wallet;
13+
utxos: UTxO[];
1214
proposalId?: string; // Optional proposalId
1315
}
1416

15-
export default function VoteCard({ appWallet, proposalId }: VoteCardProps) {
17+
export default function VoteCard({ appWallet, utxos, proposalId }: VoteCardProps) {
1618
const drepInfo = useWalletsStore((state) => state.drepInfo);
1719
const [localProposalId, setLocalProposalId] = useState<string>(proposalId ?? "");
1820
const [description, setDescription] = useState<string>("");
@@ -69,6 +71,7 @@ export default function VoteCard({ appWallet, proposalId }: VoteCardProps) {
6971
proposalId={proposalId ?? localProposalId}
7072
description={description}
7173
metadata={metadata}
74+
utxos={utxos}
7275
/>
7376
</div>
7477
</fieldset>

0 commit comments

Comments
 (0)