Skip to content

Commit 3d12702

Browse files
authored
Merge pull request #486 from kleros/feat/support-reality-hash-questions
Feat: support reality hash type questions
2 parents cdfa31d + 86b3913 commit 3d12702

3 files changed

Lines changed: 785 additions & 19 deletions

File tree

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"@kleros/pnk-merkle-drop-contracts": "^0.1.0",
6767
"@loadable/component": "^5.5.0",
6868
"@reality.eth/contracts": "3.0.0",
69-
"@reality.eth/reality-eth-lib": "3.0.0",
69+
"@reality.eth/reality-eth-lib": "3.4.6",
7070
"@sentry/react": "^7.37.2",
7171
"@sentry/tracing": "^7.37.2",
7272
"antd": "^3.10.8",
@@ -103,6 +103,9 @@
103103
"use-persisted-state": "^0.3.3",
104104
"web3": "1.5.2"
105105
},
106+
"resolutions": {
107+
"html-to-text": "^7.0.0"
108+
},
106109
"volta": {
107110
"node": "16.20.2",
108111
"yarn": "1.22.10"

src/components/case-details-card.jsx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,33 @@ const VoteOptions = ({ metaEvidence, votesData, complexRuling, setComplexRuling,
5959
const isSingleSelect = metaEvidence.rulingOptions.type === "single-select";
6060
const isMultipleSelect = metaEvidence.rulingOptions.type === "multiple-select";
6161
const isDateTime = metaEvidence.rulingOptions.type === "datetime";
62+
const isHash = metaEvidence.rulingOptions.type === "hash";
6263

6364
let inputComponent;
6465

65-
if (isMultipleSelect) {
66+
if (isHash) {
67+
inputComponent = (
68+
<StyledInput
69+
disabled={!votesData.canVote}
70+
onInput={(e) => {
71+
const newValue = e.target.value;
72+
if (/^(0)?([xX])?[0-9a-fA-F]{0,64}$/.test(newValue)) {
73+
if (!/0{64}/.test(newValue)) {
74+
setComplexRuling(newValue);
75+
}
76+
}
77+
}}
78+
onBlur={() => {
79+
const emptyOrUndefined = typeof complexRuling === "undefined" || complexRuling === "";
80+
const formatted = complexRuling?.replace("0x", "").padStart(64, "0");
81+
setComplexRuling(emptyOrUndefined ? "" : `0x${formatted}`);
82+
}}
83+
value={complexRuling}
84+
placeholder="0xffff...ffff"
85+
size="large"
86+
/>
87+
);
88+
} else if (isMultipleSelect) {
6689
inputComponent = (
6790
<div style={{ paddingTop: "1rem" }}>
6891
<Checkbox.Group
@@ -382,6 +405,9 @@ export default function CaseDetailsCard({ ID }) {
382405
case "uint":
383406
choice = complexRuling;
384407
break;
408+
case "hash":
409+
choice = complexRuling;
410+
break;
385411
default:
386412
choice = id;
387413
break;
@@ -390,6 +416,7 @@ export default function CaseDetailsCard({ ID }) {
390416
case "multiple-select":
391417
case "datetime":
392418
case "uint":
419+
case "hash":
393420
choice = realitioLibQuestionFormatter.answerToBytes32(choice, {
394421
decimals: metaEvidence.rulingOptions.precision,
395422
type: metaEvidence.rulingOptions.type,
@@ -983,6 +1010,10 @@ const StyledInputNumber = styled(InputNumber)`
9831010
width: 80%;
9841011
`;
9851012

1013+
const StyledInput = styled(Input)`
1014+
width: 80%;
1015+
`;
1016+
9861017
const StyledButtonsDiv = styled.div`
9871018
display: flex;
9881019
flex-wrap: wrap;

0 commit comments

Comments
 (0)