Skip to content

Commit b746fe9

Browse files
authored
Merge pull request #30 from kleros/fix/feedback-application
Feat/feedback application
2 parents 0c50437 + 961ff82 commit b746fe9

File tree

46 files changed

+820
-588
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+820
-588
lines changed

subgraph/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ type ItemProp @entity {
149149

150150
type FieldProp @entity {
151151
id: ID!
152+
position: BigInt!
152153
type: String!
153154
label: String!
154155
description: String!

subgraph/src/Curate.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable prefer-const */
2-
import { json, log } from "@graphprotocol/graph-ts";
2+
import { BigInt, json, log } from "@graphprotocol/graph-ts";
33
import { Item, Request, Registry, FieldProp } from "../generated/schema";
44

55
import {
@@ -219,6 +219,7 @@ export function handleListMetadataSet(event: ListMetadataSet): void {
219219
let fieldPropId = registry.id + "@" + checkedLabel;
220220
let fieldProp = new FieldProp(fieldPropId);
221221

222+
fieldProp.position = BigInt.fromI32(i);
222223
fieldProp.type = JSONValueToMaybeString(_type);
223224
fieldProp.label = JSONValueToMaybeString(label);
224225
fieldProp.description = JSONValueToMaybeString(description);

web/src/components/ActionButton/Modal/ChallengeItemModal.tsx

Lines changed: 44 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import React, { useMemo, useRef, useState } from "react";
1+
import React, { useMemo, useState } from "react";
22
import styled from "styled-components";
3-
import { useClickAway } from "react-use";
4-
import { Overlay } from "components/Overlay";
53
import Header from "./Header";
64
import Buttons from "./Buttons";
75
import DepositRequired from "./DepositRequired";
8-
import { StyledModal } from "./StyledModal";
96
import Info from "./Info";
107
import {
118
prepareWriteCurateV2,
@@ -19,8 +16,9 @@ import { wrapWithToast } from "utils/wrapWithToast";
1916
import { IBaseModal } from ".";
2017
import EvidenceUpload, { Evidence } from "./EvidenceUpload";
2118
import { uploadFileToIPFS } from "utils/uploadFileToIPFS";
19+
import Modal from "components/Modal";
2220

23-
const ReStyledModal = styled(StyledModal)`
21+
const ReStyledModal = styled(Modal)`
2422
gap: 32px;
2523
`;
2624

@@ -46,8 +44,6 @@ const ChallengeItemModal: React.FC<IChallengeItemModal> = ({
4644
challengeType,
4745
refetch,
4846
}) => {
49-
const containerRef = useRef(null);
50-
useClickAway(containerRef, () => toggleModal());
5147
const { address } = useAccount();
5248
const publicClient = usePublicClient();
5349
const { data: walletClient } = useWalletClient();
@@ -111,52 +107,50 @@ const ChallengeItemModal: React.FC<IChallengeItemModal> = ({
111107
}, [depositRequired, userBalance, isEvidenceUploading, isEvidenceValid]);
112108

113109
return (
114-
<>
115-
<Overlay />
116-
<ReStyledModal ref={containerRef}>
117-
<Header text={`Challenge ${isItem ? "Item" : "List"}`} />
118-
<DepositRequired value={depositRequired} />
119-
<EvidenceUpload {...{ setEvidence, setIsEvidenceUploading }} />
120-
<Info alertMessage={alertMessage} />
121-
<Buttons
122-
buttonText="Challenge"
123-
toggleModal={toggleModal}
124-
isDisabled={isDisabled || isChallengingItem}
125-
isLoading={isLoading}
126-
callback={async () => {
127-
setIsChallengingItem(true);
128-
129-
const evidenceFile = new File([JSON.stringify(evidence)], "evidence.json", {
130-
type: "application/json",
131-
});
132-
133-
uploadFileToIPFS(evidenceFile)
134-
.then(async (res) => {
135-
if (res.status === 200 && walletClient) {
136-
const response = await res.json();
137-
const fileURI = response["cids"][0];
138-
139-
const { request } = await prepareWriteCurateV2({
140-
//@ts-ignore
141-
address: registryAddress,
142-
functionName: "challengeRequest",
143-
args: [itemId as `0x${string}`, fileURI],
144-
value: depositRequired,
145-
});
146-
147-
wrapWithToast(async () => await walletClient.writeContract(request), publicClient).then((res) => {
110+
<ReStyledModal {...{ toggleModal }}>
111+
<Header text={`Challenge ${isItem ? "Item" : "List"}`} />
112+
<DepositRequired value={depositRequired} />
113+
<EvidenceUpload {...{ setEvidence, setIsEvidenceUploading }} />
114+
<Info alertMessage={alertMessage} />
115+
<Buttons
116+
buttonText="Challenge"
117+
toggleModal={toggleModal}
118+
isDisabled={isDisabled || isChallengingItem}
119+
isLoading={isLoading}
120+
callback={async () => {
121+
setIsChallengingItem(true);
122+
123+
const evidenceFile = new File([JSON.stringify(evidence)], "evidence.json", {
124+
type: "application/json",
125+
});
126+
127+
uploadFileToIPFS(evidenceFile)
128+
.then(async (res) => {
129+
if (res.status === 200 && walletClient) {
130+
const response = await res.json();
131+
const fileURI = response["cids"][0];
132+
133+
const { request } = await prepareWriteCurateV2({
134+
//@ts-ignore
135+
address: registryAddress,
136+
functionName: "challengeRequest",
137+
args: [itemId as `0x${string}`, fileURI],
138+
value: depositRequired,
139+
});
140+
141+
wrapWithToast(async () => await walletClient.writeContract(request), publicClient)
142+
.then((res) => {
148143
console.log({ res });
149144
refetch();
150145
toggleModal();
151-
});
152-
}
153-
})
154-
.catch((err) => console.log(err))
155-
.finally(() => setIsChallengingItem(false));
156-
}}
157-
/>
158-
</ReStyledModal>
159-
</>
146+
})
147+
.finally(() => setIsChallengingItem(false));
148+
}
149+
})
150+
.catch((err) => console.log(err));
151+
}}
152+
/>
153+
</ReStyledModal>
160154
);
161155
};
162156

web/src/components/ActionButton/Modal/EvidenceUpload.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import LabeledInput from "components/LabeledInput";
66
import { responsiveSize } from "styles/responsiveSize";
77
import { OPTIONS as toastOptions } from "utils/wrapWithToast";
88
import { uploadFileToIPFS } from "utils/uploadFileToIPFS";
9+
import { SUPPORTED_FILE_TYPES } from "src/consts";
910

1011
const Container = styled.div`
1112
width: 100%;
@@ -69,7 +70,7 @@ const EvidenceUpload: React.FC<IEvidenceUpload> = ({ setEvidence, setIsEvidenceU
6970
}, [title, description, fileURI]);
7071

7172
const handleFileUpload = (file: File) => {
72-
if (file?.type !== "application/pdf") {
73+
if (!SUPPORTED_FILE_TYPES.includes(file?.type)) {
7374
toast.error("File type not supported", toastOptions);
7475
return;
7576
}

web/src/components/ActionButton/Modal/RemoveModal.tsx

Lines changed: 44 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import React, { useMemo, useRef, useState } from "react";
1+
import React, { useMemo, useState } from "react";
22
import styled from "styled-components";
3-
import { useClickAway } from "react-use";
4-
import { Overlay } from "components/Overlay";
53
import Header from "./Header";
64
import Buttons from "./Buttons";
75
import DepositRequired from "./DepositRequired";
8-
import { StyledModal } from "./StyledModal";
96
import Info from "./Info";
107
import { IBaseModal } from ".";
118
import { useAccount, useBalance, usePublicClient, useWalletClient } from "wagmi";
@@ -18,8 +15,9 @@ import { useArbitrationCost } from "hooks/useArbitrationCostFromKlerosCore";
1815
import { wrapWithToast } from "utils/wrapWithToast";
1916
import EvidenceUpload, { Evidence } from "./EvidenceUpload";
2017
import { uploadFileToIPFS } from "utils/uploadFileToIPFS";
18+
import Modal from "components/Modal";
2119

22-
const ReStyledModal = styled(StyledModal)`
20+
const ReStyledModal = styled(Modal)`
2321
gap: 32px;
2422
`;
2523

@@ -32,8 +30,6 @@ const alertMessage = (isItem: boolean) =>
3230
` Make sure you read and understand the Policy before proceeding.`;
3331

3432
const RemoveModal: React.FC<IRemoveModal> = ({ toggleModal, isItem, registryAddress, itemId, refetch }) => {
35-
const containerRef = useRef(null);
36-
useClickAway(containerRef, () => toggleModal());
3733
const { address } = useAccount();
3834
const publicClient = usePublicClient();
3935
const { data: walletClient } = useWalletClient();
@@ -87,52 +83,50 @@ const RemoveModal: React.FC<IRemoveModal> = ({ toggleModal, isItem, registryAddr
8783
}, [depositRequired, userBalance, isEvidenceUploading, isEvidenceValid]);
8884

8985
return (
90-
<>
91-
<Overlay />
92-
<ReStyledModal ref={containerRef}>
93-
<Header text={`Remove ${isItem ? "Item" : "List"}`} />
94-
<DepositRequired value={depositRequired ?? 0} />
95-
<EvidenceUpload setEvidence={setEvidence} setIsEvidenceUploading={setIsEvidenceUploading} />
96-
<Info alertMessage={alertMessage(isItem)} />
97-
<Buttons
98-
buttonText="Remove"
99-
toggleModal={toggleModal}
100-
isDisabled={isDisabled || isRemovingItem}
101-
isLoading={isLoading}
102-
callback={() => {
103-
setIsRemovingItem(true);
104-
105-
const evidenceFile = new File([JSON.stringify(evidence)], "evidence.json", {
106-
type: "application/json",
107-
});
108-
109-
uploadFileToIPFS(evidenceFile)
110-
.then(async (res) => {
111-
if (res.status === 200 && walletClient) {
112-
const response = await res.json();
113-
const fileURI = response["cids"][0];
114-
115-
const { request } = await prepareWriteCurateV2({
116-
//@ts-ignore
117-
address: registryAddress,
118-
functionName: "removeItem",
119-
args: [itemId as `0x${string}`, fileURI],
120-
value: depositRequired,
121-
});
122-
123-
wrapWithToast(async () => await walletClient.writeContract(request), publicClient).then((res) => {
86+
<ReStyledModal {...{ toggleModal }}>
87+
<Header text={`Remove ${isItem ? "Item" : "List"}`} />
88+
<DepositRequired value={depositRequired ?? 0} />
89+
<EvidenceUpload setEvidence={setEvidence} setIsEvidenceUploading={setIsEvidenceUploading} />
90+
<Info alertMessage={alertMessage(isItem)} />
91+
<Buttons
92+
buttonText="Remove"
93+
toggleModal={toggleModal}
94+
isDisabled={isDisabled || isRemovingItem}
95+
isLoading={isLoading}
96+
callback={() => {
97+
setIsRemovingItem(true);
98+
99+
const evidenceFile = new File([JSON.stringify(evidence)], "evidence.json", {
100+
type: "application/json",
101+
});
102+
103+
uploadFileToIPFS(evidenceFile)
104+
.then(async (res) => {
105+
if (res.status === 200 && walletClient) {
106+
const response = await res.json();
107+
const fileURI = response["cids"][0];
108+
109+
const { request } = await prepareWriteCurateV2({
110+
//@ts-ignore
111+
address: registryAddress,
112+
functionName: "removeItem",
113+
args: [itemId as `0x${string}`, fileURI],
114+
value: depositRequired,
115+
});
116+
117+
wrapWithToast(async () => await walletClient.writeContract(request), publicClient)
118+
.then((res) => {
124119
console.log({ res });
125120
refetch();
126121
toggleModal();
127-
});
128-
}
129-
})
130-
.catch((err) => console.log(err))
131-
.finally(() => setIsRemovingItem(false));
132-
}}
133-
/>
134-
</ReStyledModal>
135-
</>
122+
})
123+
.finally(() => setIsRemovingItem(false));
124+
}
125+
})
126+
.catch((err) => console.log(err));
127+
}}
128+
/>
129+
</ReStyledModal>
136130
);
137131
};
138132

web/src/components/ActionButton/Modal/ResubmitModal.tsx

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import React, { useMemo, useRef, useState } from "react";
1+
import React, { useMemo, useState } from "react";
22
import styled from "styled-components";
3-
import { useClickAway } from "react-use";
4-
import { Overlay } from "components/Overlay";
53
import Header from "./Header";
64
import Buttons from "./Buttons";
75
import DepositRequired from "./DepositRequired";
8-
import { StyledModal } from "./StyledModal";
96
import Info from "./Info";
107
import { IBaseModal } from ".";
118
import { useAccount, useBalance, usePublicClient } from "wagmi";
@@ -18,8 +15,9 @@ import {
1815
import { useArbitrationCost } from "hooks/useArbitrationCostFromKlerosCore";
1916
import { wrapWithToast } from "utils/wrapWithToast";
2017
import { useItemDetailsQuery } from "hooks/queries/useItemDetailsQuery";
18+
import Modal from "components/Modal";
2119

22-
const ReStyledModal = styled(StyledModal)`
20+
const ReStyledModal = styled(Modal)`
2321
gap: 32px;
2422
`;
2523

@@ -32,8 +30,6 @@ const alertMessage = (isItem: boolean) =>
3230
` Make sure you read and understand the Policy before proceeding.`;
3331

3432
const ResubmitModal: React.FC<ISubmitModal> = ({ toggleModal, isItem, registryAddress, itemId, refetch }) => {
35-
const containerRef = useRef(null);
36-
useClickAway(containerRef, () => toggleModal());
3733
const { address } = useAccount();
3834
const publicClient = usePublicClient();
3935
const [isResubmittingItem, setIsResubmittingItem] = useState(false);
@@ -79,38 +75,35 @@ const ResubmitModal: React.FC<ISubmitModal> = ({ toggleModal, isItem, registryAd
7975
const { writeAsync: resubmitItem } = useCurateV2AddItem(config);
8076

8177
return (
82-
<>
83-
<Overlay />
84-
<ReStyledModal ref={containerRef}>
85-
<Header text={`Resubmit ${isItem ? "Item" : "List"}`} />
86-
<DepositRequired value={depositRequired ?? 0} />
87-
<Info alertMessage={alertMessage(isItem)} />
88-
<Buttons
89-
buttonText="Resubmit"
90-
toggleModal={toggleModal}
91-
isDisabled={isDisabled || isError || isResubmittingItem}
92-
isLoading={isLoading}
93-
callback={() => {
94-
if (!resubmitItem) return;
95-
setIsResubmittingItem(true);
96-
wrapWithToast(
97-
async () =>
98-
await resubmitItem().then((response) => {
99-
return response.hash;
100-
}),
101-
publicClient
102-
)
103-
.then((res) => {
104-
console.log({ res });
105-
refetch();
106-
toggleModal();
107-
})
108-
.catch(() => {})
109-
.finally(() => setIsResubmittingItem(false));
110-
}}
111-
/>
112-
</ReStyledModal>
113-
</>
78+
<ReStyledModal {...{ toggleModal }}>
79+
<Header text={`Resubmit ${isItem ? "Item" : "List"}`} />
80+
<DepositRequired value={depositRequired ?? 0} />
81+
<Info alertMessage={alertMessage(isItem)} />
82+
<Buttons
83+
buttonText="Resubmit"
84+
toggleModal={toggleModal}
85+
isDisabled={isDisabled || isError || isResubmittingItem}
86+
isLoading={isLoading}
87+
callback={() => {
88+
if (!resubmitItem) return;
89+
setIsResubmittingItem(true);
90+
wrapWithToast(
91+
async () =>
92+
await resubmitItem().then((response) => {
93+
return response.hash;
94+
}),
95+
publicClient
96+
)
97+
.then((res) => {
98+
console.log({ res });
99+
refetch();
100+
toggleModal();
101+
})
102+
.catch(() => {})
103+
.finally(() => setIsResubmittingItem(false));
104+
}}
105+
/>
106+
</ReStyledModal>
114107
);
115108
};
116109

0 commit comments

Comments
 (0)