-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathFinalDecision.tsx
137 lines (119 loc) · 4.6 KB
/
FinalDecision.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import React, { useMemo } from "react";
import styled from "styled-components";
import Skeleton from "react-loading-skeleton";
import { useParams } from "react-router-dom";
import { useAccount } from "wagmi";
import ArrowIcon from "svgs/icons/arrow.svg";
import { REFETCH_INTERVAL } from "consts/index";
import { Periods } from "consts/periods";
import { DEFAULT_CHAIN } from "consts/chains";
import { useReadKlerosCoreCurrentRuling } from "hooks/contracts/generated";
import { usePopulatedDisputeData } from "hooks/queries/usePopulatedDisputeData";
import { useVotingHistory } from "hooks/queries/useVotingHistory";
import { useVotingContext } from "hooks/useVotingContext";
import { getLocalRounds } from "utils/getLocalRounds";
import { isUndefined } from "utils/index";
import { useDisputeDetailsQuery } from "queries/useDisputeDetailsQuery";
import { responsiveSize } from "styles/responsiveSize";
import RulingAndRewardsIndicators from "./RulingAndRewardsIndicators";
import AnswerDisplay from "./Answer";
import { Divider } from "../Divider";
import { StyledArrowLink } from "../StyledArrowLink";
const Container = styled.div`
width: 100%;
`;
const JuryContainer = styled.div`
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: center;
gap: 4px 7px;
h3 {
line-height: 21px;
margin-bottom: 0px;
}
`;
const VerdictContainer = styled.div`
display: flex;
flex-direction: row;
align-items: center;
flex-wrap: wrap;
gap: ${responsiveSize(6, 8)};
`;
const JuryDecisionTag = styled.small`
font-weight: 400;
color: ${({ theme }) => theme.secondaryText};
`;
const StyledDivider = styled(Divider)`
margin: ${responsiveSize(16, 24)} 0px;
`;
const ReStyledArrowLink = styled(StyledArrowLink)`
font-size: 14px;
> svg {
height: 15px;
width: 15px;
}
`;
interface IFinalDecision {
arbitrable?: `0x${string}`;
}
const FinalDecision: React.FC<IFinalDecision> = ({ arbitrable }) => {
const { id } = useParams();
const { isDisconnected } = useAccount();
const { data: populatedDisputeData } = usePopulatedDisputeData(id, arbitrable);
const { data: disputeDetails } = useDisputeDetailsQuery(id);
const { wasDrawn, hasVoted, isLoading, isCommitPeriod, isVotingPeriod, commited, isHiddenVotes } = useVotingContext();
const { data: votingHistory } = useVotingHistory(id);
const localRounds = getLocalRounds(votingHistory?.dispute?.disputeKitDispute);
const ruled = disputeDetails?.dispute?.ruled ?? false;
const periodIndex = Periods[disputeDetails?.dispute?.period ?? "evidence"];
const { data: currentRulingArray } = useReadKlerosCoreCurrentRuling({
query: { refetchInterval: REFETCH_INTERVAL },
args: [BigInt(id ?? 0)],
chainId: DEFAULT_CHAIN,
});
const currentRuling = Number(currentRulingArray?.[0]);
const answer = populatedDisputeData?.answers?.[currentRuling! - 1];
const rounds = votingHistory?.dispute?.rounds;
const jurorRewardsDispersed = useMemo(() => Boolean(rounds?.every((round) => round.jurorRewardsDispersed)), [rounds]);
const buttonText = useMemo(() => {
if (!wasDrawn || isDisconnected) return "Check how the jury voted";
if (isCommitPeriod && !commited) return "Commit your vote";
if (isVotingPeriod && isHiddenVotes && commited && !hasVoted) return "Reveal your vote";
if (isVotingPeriod && !isHiddenVotes && !hasVoted) return "Cast your vote";
return "Check how the jury voted";
}, [wasDrawn, hasVoted, isCommitPeriod, isVotingPeriod, commited, isHiddenVotes]);
return (
<Container>
<VerdictContainer>
{!isUndefined(Boolean(disputeDetails?.dispute?.ruled)) || jurorRewardsDispersed ? (
<RulingAndRewardsIndicators
ruled={Boolean(disputeDetails?.dispute?.ruled)}
jurorRewardsDispersed={jurorRewardsDispersed}
/>
) : null}
{ruled && (
<JuryContainer>
<JuryDecisionTag>The jury decided in favor of:</JuryDecisionTag>
<AnswerDisplay {...{ answer, currentRuling }} />
</JuryContainer>
)}
{!ruled && periodIndex > 1 && localRounds?.at(localRounds.length - 1)?.totalVoted > 0 && (
<JuryContainer>
<JuryDecisionTag>This option is winning:</JuryDecisionTag>
<AnswerDisplay {...{ answer, currentRuling }} />
</JuryContainer>
)}
</VerdictContainer>
<StyledDivider />
{isLoading && !isDisconnected ? (
<Skeleton width={250} height={20} />
) : (
<ReStyledArrowLink to={`/cases/${id?.toString()}/voting`}>
{buttonText} <ArrowIcon />
</ReStyledArrowLink>
)}
</Container>
);
};
export default FinalDecision;