Skip to content

Commit dbec24b

Browse files
committed
Enhance VoteButton functionality to manage proposals on ballots
- Introduced logic to determine if a proposal is already on any ballot, improving user interaction. - Updated button text dynamically based on proposal status, enhancing clarity for users managing proposals.
1 parent ad05899 commit dbec24b

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ export default function VoteButton({
6161
// Use the custom hook for ballots (still used for proxy / context where needed)
6262
const { ballots } = useBallot(appWallet?.id);
6363

64+
// Determine if this proposal already exists on any ballot
65+
const isOnAnyBallot = useMemo(
66+
() =>
67+
!!proposalId &&
68+
Array.isArray(ballots) &&
69+
ballots.some(
70+
(b: BallotType) => Array.isArray(b.items) && b.items.includes(proposalId),
71+
),
72+
[ballots, proposalId],
73+
);
74+
6475
const drepInfo = useWalletsStore((state) => state.drepInfo);
6576
const [loading, setLoading] = useState(false);
6677
const [voteKind, setVoteKind] = useState<"Yes" | "No" | "Abstain">("Abstain");
@@ -360,7 +371,7 @@ export default function VoteButton({
360371
onClick={onOpenBallotSidebar}
361372
className="w-full rounded-md bg-green-600 hover:bg-green-700 px-6 py-2 font-semibold text-white shadow"
362373
>
363-
Add proposal to ballot
374+
{isOnAnyBallot ? "Manage proposal on ballots" : "Add proposal to ballot"}
364375
</Button>
365376
)}
366377
</div>

0 commit comments

Comments
 (0)