Skip to content

Commit

Permalink
feat: make addresses clickable in evidence, hide button if no file at…
Browse files Browse the repository at this point in the history
…tached, transaction hash
  • Loading branch information
kemuru committed Nov 20, 2024
1 parent 884674e commit 15497de
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 16 deletions.
1 change: 1 addition & 0 deletions subgraph/core/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ type ClassicEvidence implements Evidence @entity(immutable: true) {
sender: User!
senderAddress: String!
timestamp: BigInt!
transactionHash: Bytes!
name: String
description: String
fileURI: String
Expand Down
1 change: 1 addition & 0 deletions subgraph/core/src/EvidenceModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function handleEvidenceEvent(event: EvidenceEvent): void {
evidence.evidenceIndex = evidenceIndex.plus(ONE).toString();
const userId = event.params._party.toHexString();
evidence.timestamp = event.block.timestamp;
evidence.transactionHash = event.transaction.hash;
evidence.evidence = event.params._evidence;
evidence.evidenceGroup = evidenceGroupID.toString();
evidence.sender = userId;
Expand Down
47 changes: 41 additions & 6 deletions web/src/components/EvidenceCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useMemo } from "react";
import styled, { css } from "styled-components";

import Identicon from "react-identicons";
Expand All @@ -9,6 +9,7 @@ import { Card } from "@kleros/ui-components-library";

import AttachmentIcon from "svgs/icons/attachment.svg";

import { DEFAULT_CHAIN, getChain } from "consts/chains";
import { formatDate } from "utils/date";
import { getIpfsUrl } from "utils/getIpfsUrl";
import { shortenAddress } from "utils/shortenAddress";
Expand Down Expand Up @@ -116,6 +117,19 @@ const StyledLink = styled(Link)`
)}
`;

const StyledA = styled.a`
:hover {
text-decoration: underline;
p {
color: ${({ theme }) => theme.primaryBlue};
}
label {
cursor: pointer;
color: ${({ theme }) => theme.primaryBlue};
}
}
`;

const AttachedFileText: React.FC = () => (
<>
<DesktopText>View attached file</DesktopText>
Expand All @@ -128,7 +142,24 @@ interface IEvidenceCard extends Pick<Evidence, "evidence" | "timestamp" | "name"
index: number;
}

const EvidenceCard: React.FC<IEvidenceCard> = ({ evidence, sender, index, timestamp, name, description, fileURI }) => {
const EvidenceCard: React.FC<IEvidenceCard> = ({
evidence,
sender,
index,
timestamp,
transactionHash,
name,
description,
fileURI,
}) => {
const addressExplorerLink = useMemo(() => {
return `${getChain(DEFAULT_CHAIN)?.blockExplorers?.default.url}/address/${sender}`;
}, [sender]);

const transactionExplorerLink = useMemo(() => {
return `${getChain(DEFAULT_CHAIN)?.blockExplorers?.default.url}/tx/${transactionHash}`;
}, [transactionHash]);

return (
<StyledCard>
<TextContainer>
Expand All @@ -145,15 +176,19 @@ const EvidenceCard: React.FC<IEvidenceCard> = ({ evidence, sender, index, timest
<BottomShade>
<AccountContainer>
<Identicon size="24" string={sender} />
<p>{shortenAddress(sender)}</p>
<StyledA href={addressExplorerLink} rel="noreferrer" target="_blank">
<p>{shortenAddress(sender)}</p>
</StyledA>
</AccountContainer>
<Timestamp>{formatDate(Number(timestamp), true)}</Timestamp>
{fileURI && (
<StyledA href={transactionExplorerLink} rel="noreferrer" target="_blank">
<Timestamp>{formatDate(Number(timestamp), true)}</Timestamp>
</StyledA>
{fileURI && fileURI !== "-" ? (
<StyledLink to={`attachment/?url=${getIpfsUrl(fileURI)}`}>
<AttachmentIcon />
<AttachedFileText />
</StyledLink>
)}
) : null}
</BottomShade>
</StyledCard>
);
Expand Down
1 change: 1 addition & 0 deletions web/src/hooks/queries/useEvidences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const evidenceFragment = graphql(`
id
}
timestamp
transactionHash
name
description
fileURI
Expand Down
22 changes: 12 additions & 10 deletions web/src/pages/Cases/CaseDetails/Evidence/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,16 @@ const Evidence: React.FC = () => {
<EvidenceSearch {...{ search, setSearch, evidenceGroup: disputeData?.dispute?.externalDisputeId }} />
<ScrollButton small Icon={DownArrow} text="Scroll to latest" onClick={scrollToLatest} />
{evidences?.realEvidences ? (
evidences?.realEvidences.map(({ evidence, sender, timestamp, name, description, fileURI, evidenceIndex }) => (
<EvidenceCard
key={timestamp}
index={parseInt(evidenceIndex)}
sender={sender?.id}
{...{ evidence, timestamp, name, description, fileURI }}
/>
))
evidences?.realEvidences.map(
({ evidence, sender, timestamp, transactionHash, name, description, fileURI, evidenceIndex }) => (
<EvidenceCard
key={timestamp}
index={parseInt(evidenceIndex)}
sender={sender?.id}
{...{ evidence, timestamp, transactionHash, name, description, fileURI }}
/>
)
)
) : (
<SkeletonEvidenceCard />
)}
Expand All @@ -111,12 +113,12 @@ const Evidence: React.FC = () => {
<Divider />
{showSpam ? (
evidences?.spamEvidences.map(
({ evidence, sender, timestamp, name, description, fileURI, evidenceIndex }) => (
({ evidence, sender, timestamp, transactionHash, name, description, fileURI, evidenceIndex }) => (
<EvidenceCard
key={timestamp}
index={parseInt(evidenceIndex)}
sender={sender?.id}
{...{ evidence, timestamp, name, description, fileURI }}
{...{ evidence, timestamp, transactionHash, name, description, fileURI }}
/>
)
)
Expand Down

0 comments on commit 15497de

Please sign in to comment.