Skip to content

Commit 034a818

Browse files
authored
Merge branch 'dev' into fix(web)/prevent-app-crash-while-searching-cases
2 parents 14f59ae + d722cb2 commit 034a818

File tree

28 files changed

+829
-165
lines changed

28 files changed

+829
-165
lines changed

kleros-sdk/src/dataMappings/actions/jsonAction.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import { JsonMapping } from "../utils/actionTypes";
22
import { createResultObject } from "src/dataMappings/utils/createResultObject";
33

44
export const jsonAction = (mapping: JsonMapping) => {
5-
const { value: source, seek, populate } = mapping;
6-
return createResultObject(source, seek, populate);
5+
const { value, seek, populate } = mapping;
6+
7+
// Parse the source if it's a JSON string
8+
const parsedValue = typeof value === "string" ? JSON.parse(value) : value;
9+
10+
return createResultObject(parsedValue, seek, populate);
711
};

kleros-sdk/src/dataMappings/executeActions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const executeActions = async (mappings, initialContext = {}) => {
4242

4343
for (const mapping of mappings) {
4444
const actionResult = await executeAction(mapping, context);
45+
4546
if (actionResult) {
4647
Object.keys(actionResult).forEach((key) => {
4748
context[key] = actionResult[key];
Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,22 @@
1-
// Can this be replaced by Mustache ?
2-
export const createResultObject = (sourceData, seek, populate) => {
1+
export const createResultObject = (sourceData, seek: string[], populate: string[]) => {
32
const result = {};
43

5-
seek.forEach((key, idx) => {
6-
let foundValue = sourceData;
7-
8-
if (key.includes(".")) {
9-
const keyParts = key.split(".");
10-
for (const part of keyParts) {
11-
if (foundValue[part] !== undefined) {
12-
foundValue = foundValue[part];
13-
} else {
14-
foundValue = undefined;
15-
break;
16-
}
17-
}
18-
} else {
19-
if (typeof sourceData !== "object" || key === "0") {
20-
foundValue = sourceData;
21-
} else {
22-
foundValue = sourceData[key];
4+
const getNestedValue = (obj: any, path: string) => {
5+
return path.split(".").reduce((acc, part) => {
6+
if (acc && part.includes("[")) {
7+
const [key, index] = part.replace(/\]/g, "").split("[");
8+
return acc[key]?.[index];
239
}
24-
}
10+
return acc ? acc[part] : undefined;
11+
}, obj);
12+
};
2513

26-
console.log(`Seek key: ${key}, Found value:`, foundValue);
14+
seek.forEach((key, idx) => {
15+
const foundValue = getNestedValue(sourceData, key);
2716
if (foundValue !== undefined) {
2817
result[populate[idx]] = foundValue;
29-
console.log(`Populate key: ${populate[idx]}, Value to add:`, foundValue);
3018
}
3119
});
32-
console.log("Result object:", result);
20+
3321
return result;
3422
};
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
export const replacePlaceholdersWithValues = (mapping: any, context: any) => {
2-
let mappingAsString = JSON.stringify(mapping);
1+
import mustache from "mustache";
32

4-
const replacedMapping = mappingAsString.replace(/\{\{(\w+)\}\}/g, (_, variableName) => {
5-
if (context.hasOwnProperty(variableName)) {
6-
return context[variableName];
3+
export const replacePlaceholdersWithValues = (mapping: any, context: any) => {
4+
const replace = (obj) => {
5+
if (typeof obj === "string") {
6+
return mustache.render(obj, context);
7+
} else if (Array.isArray(obj)) {
8+
return obj.map(replace);
9+
} else if (typeof obj === "object" && obj !== null) {
10+
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, replace(value)]));
711
} else {
8-
throw new Error(`Variable '${variableName}' not found in context.`);
12+
return obj;
913
}
10-
});
14+
};
1115

12-
return JSON.parse(replacedMapping);
16+
return replace(mapping);
1317
};

web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"vite-tsconfig-paths": "^4.3.2"
7575
},
7676
"dependencies": {
77+
"@cyntler/react-doc-viewer": "^1.16.3",
7778
"@filebase/client": "^0.0.5",
7879
"@kleros/kleros-sdk": "workspace:^",
7980
"@kleros/ui-components-library": "^2.12.0",
Lines changed: 10 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

web/src/components/DisputePreview/Alias.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ import Skeleton from "react-loading-skeleton";
55
import { isAddress } from "viem";
66
import { useEnsAddress } from "wagmi";
77

8-
import { Alias } from "context/NewDisputeContext";
9-
import { isUndefined } from "utils/index";
10-
118
import { AddressOrName, IdenticonOrAvatar } from "../ConnectWallet/AccountDisplay";
129

1310
const AliasContainer = styled.div`
@@ -26,28 +23,29 @@ const TextContainer = styled.div`
2623
`;
2724

2825
interface IAlias {
29-
alias: Alias;
26+
name: string;
27+
address: `0x${string}`;
3028
}
3129

32-
const AliasDisplay: React.FC<IAlias> = ({ alias }) => {
30+
const AliasDisplay: React.FC<IAlias> = ({ name, address }) => {
3331
const { data: addressFromENS, isLoading } = useEnsAddress({
3432
query: {
3533
// if alias.address is not an Address, we treat it as ENS and try to fetch address from there
36-
enabled: !isAddress(alias.address),
34+
enabled: !isAddress(address),
3735
},
38-
name: alias.address,
36+
name: address,
3937
chainId: 1,
4038
});
4139

4240
// try fetching ens name, else go with address
43-
const address = addressFromENS ?? (alias.address as `0x${string}`);
41+
const resolvedAddress = addressFromENS ?? (address as `0x${string}`);
4442

4543
return (
4644
<AliasContainer>
47-
{isLoading ? <Skeleton width={30} height={24} /> : <IdenticonOrAvatar address={address} size="24" />}
45+
{isLoading ? <Skeleton width={30} height={24} /> : <IdenticonOrAvatar address={resolvedAddress} size="24" />}
4846
<TextContainer>
49-
{isLoading ? <Skeleton width={30} height={24} /> : <AddressOrName address={address} />}&nbsp;
50-
{!isUndefined(alias.name) && alias.name !== "" ? <label>({alias.name})</label> : null}
47+
{isLoading ? <Skeleton width={30} height={24} /> : <AddressOrName address={resolvedAddress} />}&nbsp;
48+
<label>({name})</label>
5149
</TextContainer>
5250
</AliasContainer>
5351
);

web/src/components/DisputePreview/DisputeContext.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ export const DisputeContext: React.FC<IDisputeContext> = ({ disputeDetails, isRp
103103
<>
104104
<Divider />
105105
<AliasesContainer>
106-
{disputeDetails.aliases.map((alias) => (
107-
<AliasDisplay alias={alias} key={alias.address} />
106+
{Object.keys(disputeDetails.aliases).map((key) => (
107+
<AliasDisplay name={key} key={key} address={disputeDetails.aliases[key]} />
108108
))}
109109
</AliasesContainer>
110110
</>

web/src/components/EvidenceCard.tsx

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ import styled, { css } from "styled-components";
33

44
import Identicon from "react-identicons";
55
import ReactMarkdown from "react-markdown";
6+
import { Link } from "react-router-dom";
67

78
import { Card } from "@kleros/ui-components-library";
89

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

1112
import { useIPFSQuery } from "hooks/useIPFSQuery";
13+
import { formatDate } from "utils/date";
1214
import { getIpfsUrl } from "utils/getIpfsUrl";
1315
import { shortenAddress } from "utils/shortenAddress";
14-
import { formatDate } from "utils/date";
1516

1617
import { landscapeStyle } from "styles/landscapeStyle";
1718
import { responsiveSize } from "styles/responsiveSize";
@@ -65,13 +66,13 @@ const StyledA = styled.a`
6566
margin-left: auto;
6667
gap: ${responsiveSize(5, 6)};
6768
${landscapeStyle(
68-
() => css`
69+
() => css`
6970
> svg {
7071
width: 16px;
7172
fill: ${({ theme }) => theme.primaryBlue};
7273
}
7374
`
74-
)}
75+
)}
7576
`;
7677

7778
const AccountContainer = styled.div`
@@ -95,22 +96,37 @@ const AccountContainer = styled.div`
9596
const DesktopText = styled.span`
9697
display: none;
9798
${landscapeStyle(
98-
() => css`
99+
() => css`
99100
display: inline;
100101
`
101-
)}
102+
)}
102103
`;
103104

104-
const Timestamp = styled.p`
105-
color: ${({ theme }) => theme.secondaryText};
105+
const Timestamp = styled.label`
106+
color: ${({ theme }) => theme.secondaryText};
106107
`;
107108

108109
const MobileText = styled.span`
109110
${landscapeStyle(
110-
() => css`
111+
() => css`
111112
display: none;
112113
`
113-
)}
114+
)}
115+
`;
116+
117+
const StyledLink = styled(Link)`
118+
height: fit-content;
119+
display: flex;
120+
margin-left: auto;
121+
gap: ${responsiveSize(5, 6)};
122+
${landscapeStyle(
123+
() => css`
124+
> svg {
125+
width: 16px;
126+
fill: ${({ theme }) => theme.primaryBlue};
127+
}
128+
`
129+
)}
114130
`;
115131

116132
const AttachedFileText: React.FC = () => (
@@ -129,6 +145,7 @@ interface IEvidenceCard {
129145

130146
const EvidenceCard: React.FC<IEvidenceCard> = ({ evidence, sender, index, timestamp }) => {
131147
const { data } = useIPFSQuery(evidence);
148+
132149
return (
133150
<StyledCard>
134151
<TextContainer>
@@ -147,12 +164,12 @@ const EvidenceCard: React.FC<IEvidenceCard> = ({ evidence, sender, index, timest
147164
<Identicon size="24" string={sender} />
148165
<p>{shortenAddress(sender)}</p>
149166
</AccountContainer>
150-
<Timestamp>{formatDate(Number(timestamp))}</Timestamp>
167+
<Timestamp>{formatDate(Number(timestamp), true)}</Timestamp>
151168
{data && typeof data.fileURI !== "undefined" && (
152-
<StyledA href={getIpfsUrl(data.fileURI)} target="_blank" rel="noreferrer">
169+
<StyledLink to={`attachment/?url=${getIpfsUrl(data.fileURI)}`}>
153170
<AttachmentIcon />
154171
<AttachedFileText />
155-
</StyledA>
172+
</StyledLink>
156173
)}
157174
</BottomShade>
158175
</StyledCard>

0 commit comments

Comments
 (0)