-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): removal-and-challenge-justifications-display
- Loading branch information
1 parent
3ba2584
commit 4c83305
Showing
18 changed files
with
382 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Do not enter sensitive information here. | ||
export REACT_APP_DEPLOYMENT=devnet | ||
export REACT_APP_ARBSEPOLIA_SUBGRAPH=https://api.studio.thegraph.com/query/71663/curate-test/version/latest | ||
export REACT_APP_ARBSEPOLIA_SUBGRAPH=https://api.studio.thegraph.com/query/61738/curate-v2-devnet/version/latest | ||
export REACT_APP_CORE_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-core-devnet/version/latest | ||
export REACT_APP_STATUS_URL=https://curate-v2-devnet.betteruptime.com/badge | ||
export REACT_APP_GENESIS_BLOCK_ARBSEPOLIA=24725439 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from "react"; | ||
import styled from "styled-components"; | ||
|
||
const StyledHeader = styled.h1` | ||
margin: 0; | ||
`; | ||
|
||
interface IHeader { | ||
text: string; | ||
} | ||
|
||
const Header: React.FC<IHeader> = ({ text }) => { | ||
return <StyledHeader>{text}</StyledHeader>; | ||
}; | ||
|
||
export default Header; |
56 changes: 56 additions & 0 deletions
56
web/src/components/HistoryDisplay/Party/JustificationDetails.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React from "react"; | ||
import ReactMarkdown from "react-markdown"; | ||
import styled from "styled-components"; | ||
import { getIpfsUrl } from "utils/getIpfsUrl"; | ||
import AttachmentIcon from "svgs/icons/attachment.svg"; | ||
|
||
const Container = styled.div` | ||
width: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
`; | ||
|
||
const JustificationTitle = styled.h3` | ||
margin: 0px; | ||
font-weight: 600; | ||
`; | ||
|
||
const DescriptionContainer = styled.div` | ||
max-height: 400px; | ||
width: 100%; | ||
overflow-y: scroll; | ||
`; | ||
|
||
const StyledA = styled.a` | ||
display: flex; | ||
gap: 6px; | ||
> svg { | ||
width: 16px; | ||
fill: ${({ theme }) => theme.primaryBlue}; | ||
} | ||
`; | ||
|
||
export type Justification = { | ||
name: string; | ||
description: string; | ||
fileURI?: string; | ||
}; | ||
|
||
const JustificationDetails: React.FC<{ justification: Justification }> = ({ justification }) => { | ||
return ( | ||
<Container> | ||
<JustificationTitle>{justification.name}</JustificationTitle> | ||
<DescriptionContainer> | ||
<ReactMarkdown>{justification.description}</ReactMarkdown> | ||
</DescriptionContainer> | ||
{justification?.fileURI && ( | ||
<StyledA href={getIpfsUrl(justification.fileURI)}> | ||
<AttachmentIcon /> | ||
View attached file | ||
</StyledA> | ||
)} | ||
</Container> | ||
); | ||
}; | ||
|
||
export default JustificationDetails; |
127 changes: 127 additions & 0 deletions
127
web/src/components/HistoryDisplay/Party/JustificationModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import styled from "styled-components"; | ||
import { Button } from "@kleros/ui-components-library"; | ||
|
||
import Modal from "components/Modal"; | ||
import ActionButton from "components/ActionButton"; | ||
import { SkeletonJustificationCard } from "components/StyledSkeleton"; | ||
import { mapFromSubgraphStatus } from "components/RegistryCard/StatusBanner"; | ||
|
||
import { EvidencesQuery, RequestDetailsFragment } from "src/graphql/graphql"; | ||
import { isUndefined } from "src/utils"; | ||
import { getIpfsUrl } from "utils/getIpfsUrl"; | ||
import fetchJsonIpfs from "utils/fetchJsonIpfs"; | ||
import { useEvidences } from "queries/useEvidences"; | ||
|
||
import Header from "./Header"; | ||
import JustificationDetails, { Justification } from "./JustificationDetails"; | ||
|
||
const StyledModal = styled(Modal)` | ||
gap: 30px; | ||
`; | ||
|
||
const ButtonsContainer = styled.div` | ||
width: 100%; | ||
display: flex; | ||
justify-content: space-between; | ||
flex-wrap: wrap; | ||
margin-top: 38px; | ||
row-gap: 8px; | ||
`; | ||
|
||
const StyledLabel = styled.label` | ||
width: 100%; | ||
`; | ||
|
||
const JustificationText = styled.h3` | ||
width: 100%; | ||
margin: 0px; | ||
margin-bottom: 4px; | ||
text-align: center; | ||
`; | ||
|
||
interface IJustificationModal { | ||
request: RequestDetailsFragment; | ||
isRemoval: boolean; | ||
toggleModal: () => void; | ||
} | ||
|
||
const JustificationModal: React.FC<IJustificationModal> = ({ request, toggleModal, isRemoval }) => { | ||
const { data: evidenceData, isLoading: isLoadingEvidences } = useEvidences(request.externalDisputeID); | ||
const [justification, setJustification] = useState<Justification>(); | ||
const [isLoadingJustification, setIsLoadingJustification] = useState(false); | ||
|
||
useEffect(() => { | ||
if (isUndefined(evidenceData)) return; | ||
setIsLoadingJustification(true); | ||
|
||
const uri = getEvidenceUriForRequest(request, evidenceData.evidences, isRemoval); | ||
|
||
if (!uri) { | ||
setIsLoadingJustification(false); | ||
return; | ||
} | ||
|
||
fetchJsonIpfs(getIpfsUrl(uri)) | ||
.then((res) => { | ||
setJustification(res as Justification); | ||
}) | ||
.finally(() => setIsLoadingJustification(false)); | ||
}, [evidenceData, isRemoval, request]); | ||
|
||
return ( | ||
<StyledModal {...{ toggleModal }}> | ||
<Header text={isRemoval ? "Removal Requested" : "Request Challenged"} /> | ||
<JustificationText>Justification</JustificationText> | ||
{isLoadingEvidences || isLoadingJustification ? ( | ||
<SkeletonJustificationCard /> | ||
) : justification ? ( | ||
<JustificationDetails {...{ justification }} /> | ||
) : ( | ||
<StyledLabel>No Justification provided</StyledLabel> | ||
)} | ||
<ButtonsContainer> | ||
<Button variant="secondary" text="Return" onClick={toggleModal} /> | ||
{!request.resolved && ( | ||
<ActionButton | ||
isItem | ||
itemId={request.item.itemID} | ||
status={mapFromSubgraphStatus(request.item.status, request.disputed)} | ||
registryAddress={request.item.registryAddress} | ||
/> | ||
)} | ||
</ButtonsContainer> | ||
</StyledModal> | ||
); | ||
}; | ||
|
||
/** | ||
* @description returns the correct evidence relating to the request | ||
* @need this is needed since the removal request might not have the evidence, same for challenge request. | ||
* to get the correct evidence for the request, we match the timestamp of the request and evidence, | ||
* if both are same , it means the evidence was created in the same block as that request and belongs to the request | ||
* @returns the evidence uri for the request if it exists, otherwise null | ||
*/ | ||
const getEvidenceUriForRequest = ( | ||
request: RequestDetailsFragment, | ||
evidences: EvidencesQuery["evidences"], | ||
isRemoval: boolean | ||
) => { | ||
if (isRemoval) { | ||
if (evidences.length > 0 && evidences[0].timestamp === request.submissionTime) { | ||
return evidences[0].evidence; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
// in case of challenge either the first or the second one can be the challenge evidence, | ||
// in case of registration challenge, the 1st one is the challenge evidence, | ||
// or if the removal request did not have any justification, the 1st one could be the challenge justification | ||
if (evidences.length > 0 && evidences[0].timestamp === request.challengeTime) return evidences[0].evidence; | ||
if (evidences.length > 1 && evidences[1].timestamp === request.challengeTime) return evidences[1].evidence; | ||
|
||
return null; | ||
}; | ||
|
||
export default JustificationModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from "react"; | ||
import styled from "styled-components"; | ||
import AliasDisplay from "components/RegistryInfo/AliasDisplay"; | ||
import { RequestDetailsFragment } from "src/graphql/graphql"; | ||
import DocIcon from "svgs/icons/doc.svg"; | ||
import { useToggle } from "react-use"; | ||
import JustificationModal from "./JustificationModal"; | ||
|
||
const Container = styled.div` | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
flex-wrap: wrap; | ||
gap: 8px; | ||
`; | ||
|
||
const StyledLabel = styled.label` | ||
display: flex; | ||
align-items: center; | ||
gap: 4px; | ||
color: ${({ theme }) => theme.primaryBlue}; | ||
cursor: pointer; | ||
`; | ||
|
||
const StyledDoc = styled(DocIcon)` | ||
width: 16px; | ||
height: 16px; | ||
fill: ${({ theme }) => theme.primaryBlue}; | ||
`; | ||
|
||
interface IParty { | ||
request: RequestDetailsFragment; | ||
isRemoval?: boolean; | ||
} | ||
|
||
const Party: React.FC<IParty> = ({ request, isRemoval = false }) => { | ||
const [isOpen, toggleModal] = useToggle(false); | ||
return ( | ||
<Container> | ||
<label>by</label> | ||
<AliasDisplay address={request?.challenger?.id ?? ""} /> | ||
<label>-</label> | ||
<StyledLabel onClick={toggleModal}> | ||
<StyledDoc /> Justification | ||
</StyledLabel> | ||
{isOpen && <JustificationModal {...{ request, toggleModal, isRemoval }} />} | ||
</Container> | ||
); | ||
}; | ||
|
||
export default Party; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.