Skip to content

Commit 8822904

Browse files
authored
Merge pull request #1884 from kleros/fix/verdict-answer-decoding
fix(web): verdict-answer-decoding
2 parents 3e1118d + 1671d34 commit 8822904

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

web/src/components/Verdict/FinalDecision.tsx

+14-5
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,14 @@ const FinalDecision: React.FC<IFinalDecision> = ({ arbitrable }) => {
9393
const localRounds = getLocalRounds(votingHistory?.dispute?.disputeKitDispute);
9494
const ruled = disputeDetails?.dispute?.ruled ?? false;
9595
const periodIndex = Periods[disputeDetails?.dispute?.period ?? "evidence"];
96-
const { data: currentRulingArray } = useReadKlerosCoreCurrentRuling({
96+
const { data: currentRulingArray, isLoading: isLoadingCurrentRuling } = useReadKlerosCoreCurrentRuling({
9797
query: { refetchInterval: REFETCH_INTERVAL },
9898
args: [BigInt(id ?? 0)],
9999
chainId: DEFAULT_CHAIN,
100100
});
101-
const currentRuling = Number(currentRulingArray?.[0]);
102-
const answer = populatedDisputeData?.answers?.[currentRuling! - 1];
101+
const currentRuling = Number(currentRulingArray?.[0] ?? 0);
102+
103+
const answer = populatedDisputeData?.answers?.find((answer) => BigInt(answer.id) === BigInt(currentRuling));
103104
const rounds = votingHistory?.dispute?.rounds;
104105
const jurorRewardsDispersed = useMemo(() => Boolean(rounds?.every((round) => round.jurorRewardsDispersed)), [rounds]);
105106
const buttonText = useMemo(() => {
@@ -122,13 +123,21 @@ const FinalDecision: React.FC<IFinalDecision> = ({ arbitrable }) => {
122123
{ruled && (
123124
<JuryContainer>
124125
<JuryDecisionTag>The jury decided in favor of:</JuryDecisionTag>
125-
<AnswerDisplay {...{ answer, currentRuling }} />
126+
{isLoadingCurrentRuling ? (
127+
<Skeleton height={14} width={60} />
128+
) : (
129+
<AnswerDisplay {...{ answer, currentRuling }} />
130+
)}
126131
</JuryContainer>
127132
)}
128133
{!ruled && periodIndex > 1 && localRounds?.at(localRounds.length - 1)?.totalVoted > 0 && (
129134
<JuryContainer>
130135
<JuryDecisionTag>This option is winning:</JuryDecisionTag>
131-
<AnswerDisplay {...{ answer, currentRuling }} />
136+
{isLoadingCurrentRuling ? (
137+
<Skeleton height={14} width={60} />
138+
) : (
139+
<AnswerDisplay {...{ answer, currentRuling }} />
140+
)}
132141
</JuryContainer>
133142
)}
134143
</VerdictContainer>

web/src/hooks/useClassicAppealContext.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ const getCurrentLocalRound = (dispute?: ClassicAppealQuery["dispute"]) => {
133133
};
134134

135135
const getOptions = (dispute?: DisputeDetails, classicDispute?: ClassicAppealQuery["dispute"]) => {
136-
if (!dispute) return [];
136+
if (!dispute || Object.keys(dispute).length === 0) return [];
137137
const currentLocalRound = getCurrentLocalRound(classicDispute);
138138
const classicAnswers = currentLocalRound?.answers;
139139

140-
const options = dispute.answers.map((answer) => {
140+
const options = dispute.answers?.map((answer) => {
141141
const classicAnswer = classicAnswers?.find((classicAnswer) => BigInt(classicAnswer.answerId) == BigInt(answer.id));
142142
// converting hexadecimal id to stringified bigint to match id fomr subgraph
143143
return {

0 commit comments

Comments
 (0)