Skip to content

Commit 9856bb9

Browse files
committed
fix: fix vote button being incorrectly disabled (#1122)
This was caused by returning undefined from react query to signal that the user has no existing vote, but returning undefined is disallowed by react query.
1 parent c6b3c0f commit 9856bb9

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

apps/namadillo/src/App/Governance/ProposalHeader.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ const ProgressBar: React.FC<{
291291

292292
const VoteButton: React.FC<{
293293
proposal: AtomWithQueryResult<Proposal>;
294-
vote: AtomWithQueryResult<VoteType | undefined>;
294+
vote: AtomWithQueryResult<VoteType | null>;
295295
proposalId: bigint;
296296
}> = ({ proposal, vote, proposalId }) => {
297297
const navigate = useNavigate();
@@ -317,7 +317,7 @@ const VoteButton: React.FC<{
317317
const disabled =
318318
!isExtensionConnected || !canVote.data || status !== "ongoing";
319319

320-
const voted = typeof vote.data !== "undefined";
320+
const voted = vote.data !== null;
321321
const text = voted ? "Edit Vote" : "Vote";
322322

323323
return {
@@ -344,9 +344,9 @@ const VoteButton: React.FC<{
344344
};
345345

346346
const VotedLabel: React.FC<{
347-
vote: AtomWithQueryResult<VoteType | undefined>;
347+
vote: AtomWithQueryResult<VoteType | null>;
348348
}> = ({ vote }) => {
349-
if (vote.isSuccess && typeof vote.data !== "undefined") {
349+
if (vote.isSuccess && vote.data !== null) {
350350
return (
351351
<VotedLabelComponent vote={vote.data} className="text-xs min-w-22" />
352352
);

apps/namadillo/src/atoms/proposals/atoms.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const proposalFamily = atomFamily((id: bigint) =>
3838
);
3939

4040
export const proposalVoteFamily = atomFamily((id: bigint) =>
41-
atomWithQuery<VoteType | undefined>((get) => {
41+
atomWithQuery<VoteType | null>((get) => {
4242
const votedProposals = get(votedProposalsAtom);
4343
const enablePolling = get(shouldUpdateProposalAtom);
4444

@@ -47,7 +47,9 @@ export const proposalVoteFamily = atomFamily((id: bigint) =>
4747
refetchInterval: enablePolling ? 1000 : false,
4848
queryKey: ["proposal-vote", id.toString()],
4949
...queryDependentFn(async () => {
50-
return votedProposals.data!.find((v) => v.proposalId === id)?.vote;
50+
return (
51+
votedProposals.data!.find((v) => v.proposalId === id)?.vote ?? null
52+
);
5153
}, [votedProposals]),
5254
};
5355
})

0 commit comments

Comments
 (0)