-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathDisputeContext.tsx
113 lines (98 loc) · 3.04 KB
/
DisputeContext.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
import React from "react";
import styled from "styled-components";
import { DisputeDetails } from "@kleros/kleros-sdk/src/dataMappings/utils/disputeDetailsTypes";
import { INVALID_DISPUTE_DATA_ERROR, RPC_ERROR } from "consts/index";
import { Answer as IAnswer } from "context/NewDisputeContext";
import { isUndefined } from "utils/index";
import { responsiveSize } from "styles/responsiveSize";
import ReactMarkdown from "components/ReactMarkdown";
import { StyledSkeleton } from "components/StyledSkeleton";
import AliasDisplay from "./Alias";
import { Divider } from "../Divider";
const StyledH1 = styled.h1`
margin: 0;
word-wrap: break-word;
`;
const QuestionAndDescription = styled.div`
display: flex;
flex-direction: column;
word-wrap: break-word;
div:first-child p:first-of-type {
font-size: 16px;
font-weight: 600;
margin: 0;
}
`;
const VotingOptions = styled(QuestionAndDescription)`
display: flex;
flex-direction: column;
gap: 8px;
`;
const AnswersContainer = styled.div`
display: flex;
flex-direction: column;
`;
const AnswersHeader = styled.h3`
margin: 0;
`;
const Answer = styled.div`
margin: 0px;
display: flex;
flex-wrap: wrap;
gap: ${responsiveSize(2, 8)};
> label {
max-width: 100%;
}
`;
const AliasesContainer = styled.div`
display: flex;
flex-wrap: wrap;
gap: ${responsiveSize(8, 20)};
`;
interface IDisputeContext {
disputeDetails?: DisputeDetails;
isRpcError?: boolean;
}
export const DisputeContext: React.FC<IDisputeContext> = ({ disputeDetails, isRpcError = false }) => {
const errMsg = isRpcError ? RPC_ERROR : INVALID_DISPUTE_DATA_ERROR;
return (
<>
<StyledH1>{isUndefined(disputeDetails) ? <StyledSkeleton /> : (disputeDetails?.title ?? errMsg)}</StyledH1>
{!isUndefined(disputeDetails) && (
<QuestionAndDescription>
<ReactMarkdown>{disputeDetails?.question}</ReactMarkdown>
<ReactMarkdown>{disputeDetails?.description}</ReactMarkdown>
</QuestionAndDescription>
)}
{isUndefined(disputeDetails?.frontendUrl) ? null : (
<a href={disputeDetails?.frontendUrl} target="_blank" rel="noreferrer">
Go to arbitrable
</a>
)}
<VotingOptions>
{isUndefined(disputeDetails) ? null : <AnswersHeader>Voting Options</AnswersHeader>}
<AnswersContainer>
{disputeDetails?.answers?.map((answer: IAnswer, i: number) => (
<Answer key={answer.title}>
<small>Option {i + 1}:</small>
<label>
{answer.title}
{answer.description ? ` - ${answer.description}` : null}
</label>
</Answer>
))}
</AnswersContainer>
</VotingOptions>
{isUndefined(disputeDetails?.aliases) ? null : (
<>
<Divider />
<AliasesContainer>
{Object.keys(disputeDetails.aliases).map((key) => (
<AliasDisplay name={key} key={key} address={disputeDetails.aliases[key]} />
))}
</AliasesContainer>
</>
)}
</>
);
};