Skip to content

Commit ed197ab

Browse files
committed
fix: add error text display for invalid vote context
1 parent dd102c0 commit ed197ab

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

govtool/frontend/src/components/molecules/VoteActionForm.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
useGetVoteContextTextFromFile,
1313
} from "@hooks";
1414
import { formatDisplayDate } from "@utils";
15-
import { fadedPurple } from "@/consts";
15+
import { errorRed, fadedPurple } from "@/consts";
1616
import { ProposalData, ProposalVote, Vote } from "@/models";
1717
import { VoteContextModalState, SubmittedVotesModalState } from "../organisms";
1818

@@ -36,7 +36,8 @@ export const VoteActionForm = ({
3636
useState<boolean>(false);
3737

3838
const { voter } = useGetVoterInfo();
39-
const { voteContextText } = useGetVoteContextTextFromFile(voteContextUrl, voteContextHash) || {};
39+
const { voteContextText, valid: voteContextValid = true } =
40+
useGetVoteContextTextFromFile(voteContextUrl, voteContextHash) || {};
4041

4142
const finalVoteContextText =
4243
((previousVote != null || undefined) && !voteContextUrl && !voteContextHash)
@@ -247,6 +248,12 @@ export const VoteActionForm = ({
247248
{t("govActions.showVotes")}
248249
</Button>
249250
)}
251+
{
252+
!voteContextValid &&
253+
<Typography sx={{ fontSize: "14px", fontWeight: 700, color: errorRed.c500 }}>
254+
{t("govActions.invalidVoteContext")}
255+
</Typography>
256+
}
250257
{finalVoteContextText && (
251258
<>
252259
<Typography sx={{ fontSize: "14px", fontWeight: 500 }}>{t("govActions.yourVoteRationale")}</Typography>

govtool/frontend/src/hooks/queries/useGetVoteContextTextFromFile.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,25 @@ export const useGetVoteContextTextFromFile = (url: string | undefined,
2323

2424
const voteContextText = (data?.metadata as { comment?: string })?.comment || "";
2525

26-
if (data?.valid) {
26+
if (url === undefined || contextHash === undefined) {
2727
return {
28-
voteContextText,
29-
isLoading
30-
};
31-
}
32-
return {
3328
voteContextText: undefined,
34-
isLoading
29+
isLoading: false,
30+
valid: true
3531
};
32+
}
33+
if (data) {
34+
if (data?.valid) {
35+
return {
36+
voteContextText,
37+
isLoading,
38+
valid: true
39+
};
40+
}
41+
return {
42+
voteContextText: undefined,
43+
isLoading,
44+
valid: false
45+
};
46+
}
3647
};

govtool/frontend/src/i18n/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@
456456
"changeYourVote": "Change your vote",
457457
"chooseHowToVote": "Choose how you want to vote:",
458458
"yourVoteRationale": "Your Vote Rationale",
459+
"invalidVoteContext": "Invalid Vote Context",
459460
"dataMissing": "Data Missing",
460461
"dataMissingTooltipExplanation": "Please click “View Details” for more information.",
461462
"details": "Governance Details:",

0 commit comments

Comments
 (0)