Skip to content

Commit 65a466a

Browse files
committed
fix: coderabbit and other type fixes
1 parent 872600e commit 65a466a

File tree

10 files changed

+105
-48
lines changed

10 files changed

+105
-48
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,22 @@ export const fetchIpfsJsonAction = async (mapping: FetchIpfsJsonMapping) => {
1212
httpUri = ipfsUri.replace("ipfs://", "https://ipfs.io/ipfs/");
1313
} else if (!ipfsUri.startsWith("http")) {
1414
httpUri = `https://ipfs.io/ipfs/${ipfsUri}`;
15+
} else {
16+
throw new Error("Invalid IPFS URI format");
1517
}
18+
1619
const response = await fetch(httpUri, { method: "GET" });
1720

18-
if (response.headers.get("content-length") > MAX_BYTE_SIZE) {
21+
if (!response) {
22+
throw new Error("Failed to fetch data from IPFS");
23+
}
24+
25+
const contentLength = response.headers.get("content-length");
26+
if (contentLength && parseInt(contentLength) > MAX_BYTE_SIZE) {
1927
throw new Error("Response size is too large");
2028
}
2129

2230
const contentType = response.headers.get("content-type");
23-
2431
if (!contentType || !contentType.includes("application/json")) {
2532
throw new Error("Fetched data is not JSON");
2633
}

kleros-sdk/src/dataMappings/executeActions.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,16 @@ import {
1414
} from "./utils/actionTypeValidators";
1515
import { ActionMapping } from "./utils/actionTypes";
1616
import { replacePlaceholdersWithValues } from "./utils/replacePlaceholdersWithValues";
17+
import { Address } from "viem";
1718

18-
export const executeAction = async (mapping: ActionMapping, context: Record<string, unknown> = {}) => {
19+
// Add these type definitions at the top of the file
20+
type ActionResult = Record<string, unknown> | null | undefined;
21+
22+
// Update the function signature
23+
export const executeAction = async (
24+
mapping: ActionMapping,
25+
context: Record<string, unknown> = {}
26+
): Promise<ActionResult> => {
1927
mapping = replacePlaceholdersWithValues(mapping, context);
2028

2129
switch (mapping.type) {
@@ -24,21 +32,24 @@ export const executeAction = async (mapping: ActionMapping, context: Record<stri
2432
case "json":
2533
return jsonAction(validateJsonMapping(mapping));
2634
case "abi/call":
27-
return await callAction(validateAbiCallMapping(mapping), context.alchemyApiKey);
35+
return await callAction(validateAbiCallMapping(mapping), context.alchemyApiKey as string);
2836
case "abi/event":
29-
return await eventAction(validateAbiEventMapping(mapping), context.alchemyApiKey);
37+
return await eventAction(validateAbiEventMapping(mapping), context.alchemyApiKey as string);
3038
case "fetch/ipfs/json":
3139
return await fetchIpfsJsonAction(validateFetchIpfsJsonMapping(mapping));
3240
case "reality":
3341
mapping = validateRealityMapping(mapping);
34-
return await retrieveRealityData(mapping.realityQuestionID, context.arbitrableAddress);
42+
return await retrieveRealityData(mapping.realityQuestionID, context.arbitrableAddress as Address);
3543
default:
3644
throw new Error(`Unsupported action type: ${mapping.type}`);
3745
}
3846
};
3947

40-
export const executeActions = async (mappings, initialContext = {}) => {
41-
const context = { ...initialContext };
48+
export const executeActions = async (
49+
mappings: ActionMapping[],
50+
initialContext: Record<string, unknown> = {}
51+
): Promise<Record<string, unknown>> => {
52+
const context: Record<string, unknown> = { ...initialContext };
4253

4354
for (const mapping of mappings) {
4455
const actionResult = await executeAction(mapping, context);

kleros-sdk/src/dataMappings/retrieveRealityData.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ export const retrieveRealityData = async (realityQuestionID: string, arbitrable?
5959
const templateData = await executeAction(templateMapping);
6060
console.log("templateData", templateData);
6161

62+
if (!templateData || !questionData) {
63+
throw new Error("Failed to retrieve template or question data");
64+
}
65+
6266
const rc_question = require("@reality.eth/reality-eth-lib/formatters/question.js");
6367
const populatedTemplate = rc_question.populatedJSONForTemplate(
6468
templateData.questionText,
@@ -67,7 +71,15 @@ export const retrieveRealityData = async (realityQuestionID: string, arbitrable?
6771

6872
console.log("populatedTemplate", populatedTemplate);
6973

70-
let answers = [];
74+
interface RealityAnswer {
75+
title: string;
76+
description: string;
77+
id: string;
78+
reserved: boolean;
79+
last?: boolean;
80+
}
81+
82+
let answers: RealityAnswer[] = [];
7183
if (populatedTemplate.type === "bool") {
7284
answers = [
7385
{

kleros-sdk/src/dataMappings/utils/createResultObject.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
export const createResultObject = (sourceData, seek: string[], populate: string[]) => {
2-
const result = {};
1+
export const createResultObject = (
2+
sourceData: Record<string, any>,
3+
seek: string[],
4+
populate: string[]
5+
): Record<string, any> => {
6+
const result: Record<string, any> = {};
37

48
const getNestedValue = (obj: any, path: string) => {
59
return path.split(".").reduce((acc, part) => {

web-devtools/next.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const nextConfig = {
88
// Dangerously allow production builds to successfully complete even if
99
// your project has type errors.
1010
// !! WARN !!
11-
ignoreBuildErrors: true,
11+
ignoreBuildErrors: process.env.NODE_ENV === 'development',
1212
},
1313
webpack(config) {
1414
// Grab the existing rule that handles SVG imports

web-devtools/src/app/(main)/dispute-template/FetchDisputeRequestInput.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const FetchDisputeRequestInput: React.FC<IFetchDisputeRequestInput> = ({ setPara
7474
const [txnHash, setTxnHash] = useState<string>("");
7575
const [debouncedTxnHash, setDebouncedTxnHash] = useState<string>("");
7676
const [loading, setLoading] = useState(false);
77+
const [error, setError] = useState<string | null>(null);
7778

7879
useDebounce(
7980
() => {
@@ -89,14 +90,16 @@ const FetchDisputeRequestInput: React.FC<IFetchDisputeRequestInput> = ({ setPara
8990
try {
9091
const params = await getDisputeRequestParamsFromTxn(debouncedTxnHash as `0x${string}`, chainId);
9192
if (!isUndefined(params)) setParams(params);
93+
setError(null);
9294
} catch (error) {
9395
console.error("Error fetching dispute request params:", error);
96+
setError("Failed to fetch dispute request parameters");
9497
} finally {
9598
setLoading(false);
9699
}
97100
};
98101
if (debouncedTxnHash && chainId) fetchData();
99-
}, [debouncedTxnHash]);
102+
}, [debouncedTxnHash, chainId]);
100103

101104
return (
102105
<Container>
@@ -106,7 +109,7 @@ const FetchDisputeRequestInput: React.FC<IFetchDisputeRequestInput> = ({ setPara
106109
value={txnHash}
107110
placeholder="Enter transaction hash"
108111
onChange={(e) => setTxnHash(e.target.value)}
109-
message={loading ? "fetching ..." : ""}
112+
message={loading ? "fetching ..." : error || ""}
110113
/>
111114
<StyledChainInput
112115
value={chainId}

web-devtools/src/app/(main)/ruler/ManualRuling.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ const ManualRuling: React.FC = () => {
117117
<LabeledInput label="Ruling" type="number" value={ruling} onChange={(e) => setRuling(Number(e.target.value))} />
118118
<LabeledInput label="Tie" inputType="checkbox" checked={tie} onChange={() => setTie((prev) => !prev)} />
119119
<LabeledInput
120-
label="Overidden"
120+
label="Overridden"
121121
inputType="checkbox"
122122
checked={overridden}
123123
onChange={() => setOverridden((prev) => !prev)}

web-devtools/src/app/(main)/ruler/RulingModes.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ const RulingModes: React.FC = () => {
262262
disabled={rulingMode !== RULING_MODE.AutomaticPreset}
263263
/>
264264
<LabeledInput
265-
label="Overidden"
265+
label="Overridden"
266266
inputType="checkbox"
267267
checked={overridden}
268268
onChange={() => setOverridden((prev) => !prev)}

web-devtools/src/app/(main)/ruler/SelectArbitrable.tsx

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
22
import styled, { css } from "styled-components";
33

4-
import { Address } from "viem";
4+
import { Address, PublicClient } from "viem";
5+
import { usePublicClient } from "wagmi";
56

67
import { Copiable, DropdownSelect, Field } from "@kleros/ui-components-library";
78

@@ -10,6 +11,7 @@ import { shortenAddress } from "utils/shortenAddress";
1011
import { klerosCoreAddress } from "hooks/contracts/generated";
1112
import { DEFAULT_CHAIN } from "consts/chains";
1213
import { landscapeStyle } from "styles/landscapeStyle";
14+
import { validateAddress } from "utils/validateAddressOrEns";
1315

1416
const Container = styled.div`
1517
width: 100%;
@@ -78,10 +80,19 @@ const StyledDropdown = styled(DropdownSelect)`
7880
}
7981
`;
8082

83+
const ErrorMessage = styled.div`
84+
color: red;
85+
font-size: 14px;
86+
margin-top: 4px;
87+
`;
88+
8189
const SelectArbitrable: React.FC = () => {
8290
const { arbitrable, setArbitrable, knownArbitrables } = useRulerContext();
91+
const publicClient = usePublicClient({ chainId: 1 }) as PublicClient;
8392
const ref = useRef<HTMLDivElement>(null);
8493
const [isClient, setIsClient] = useState(false);
94+
const [inputValue, setInputValue] = useState("");
95+
const [error, setError] = useState<string | null>(null);
8596

8697
// hydration workaround, local storage is inevitably going to be different, so knownArbitrables will be different
8798
// server and client side
@@ -102,6 +113,25 @@ const SelectArbitrable: React.FC = () => {
102113
child.click();
103114
}, [knownArbitrables, ref]);
104115

116+
const handleInputChange = useCallback(
117+
async (value: string) => {
118+
setInputValue(value);
119+
setError(null);
120+
121+
if (value) {
122+
const isValid = await validateAddress(value, publicClient);
123+
if (isValid) {
124+
setArbitrable(value as Address);
125+
} else {
126+
setError("Invalid address or ENS name");
127+
}
128+
} else {
129+
setArbitrable("" as Address);
130+
}
131+
},
132+
[publicClient, setArbitrable]
133+
);
134+
105135
return (
106136
<Container>
107137
<AddressContainer>
@@ -113,15 +143,18 @@ const SelectArbitrable: React.FC = () => {
113143
<Arbitrables suppressHydrationWarning={true}>
114144
<StyledLabel>Arbitrable:</StyledLabel>
115145
<SelectContainer ref={ref}>
116-
<StyledDropdown defaultValue={arbitrable} items={items} callback={(val) => setArbitrable(val as Address)} />
146+
<StyledDropdown
147+
defaultValue={arbitrable}
148+
items={items}
149+
callback={(val) => handleInputChange(val.toString())}
150+
/>
117151
<StyledField
118-
value={arbitrable}
152+
value={inputValue}
119153
placeholder="Enter Arbitrable"
120-
onChange={(e) => {
121-
setArbitrable(e.target.value as Address);
122-
}}
154+
onChange={(e) => handleInputChange(e.target.value)}
123155
onClick={openDropdown}
124156
/>
157+
{error && <ErrorMessage>{error}</ErrorMessage>}
125158
</SelectContainer>
126159
</Arbitrables>
127160
</Container>

web-devtools/wagmi.config.ts

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
11
import { readdir, readFile } from "fs/promises";
22
import { parse, join } from "path";
33

4-
import { Chain } from "@wagmi/chains";
54
import { type Config, type ContractConfig, defineConfig } from "@wagmi/cli";
65
import { react, actions } from "@wagmi/cli/plugins";
76
import dotenv from "dotenv";
8-
import { type Abi } from "viem";
9-
10-
import IArbitrableV2 from "@kleros/kleros-v2-contracts/artifacts/src/arbitration/interfaces/IArbitrableV2.sol/IArbitrableV2.json" assert { type: "json" };
11-
import IHomeGateway from "@kleros/kleros-v2-contracts/artifacts/src/gateway/interfaces/IHomeGateway.sol/IHomeGateway.json" assert { type: "json" };
7+
import { Chain } from "viem";
128

139
import { ArbitratorTypes, getArbitratorType } from "./src/consts/arbitratorTypes";
10+
import { arbitrum, arbitrumSepolia, gnosis, gnosisChiado, mainnet, sepolia } from "viem/chains";
1411

1512
dotenv.config();
1613

17-
type ArtifactPartial = {
18-
abi: Abi;
19-
};
20-
21-
const getAbi = (artifact: any) => {
22-
return (artifact as ArtifactPartial).abi;
23-
};
24-
2514
const readArtifacts = async (type: ArbitratorTypes, viemChainName: string, hardhatChainName?: string) => {
2615
const artifactSuffix =
2716
type === ArbitratorTypes.vanilla
@@ -30,8 +19,16 @@ const readArtifacts = async (type: ArbitratorTypes, viemChainName: string, hardh
3019
const vanillaArtifacts = ["KlerosCore", "DisputeKitClassic", "SortitionModule", "DisputeResolver", "KlerosCoreRuler"];
3120
const typeSpecificArtifacts = vanillaArtifacts.map((artifact) => `${artifact}${artifactSuffix}`);
3221

33-
const chains = await import("wagmi/chains");
34-
const chain = (chains as any)[viemChainName] as Chain;
22+
const chainMap: Record<string, Chain> = {
23+
arbitrum,
24+
arbitrumSepolia,
25+
sepolia,
26+
mainnet,
27+
gnosisChiado,
28+
gnosis,
29+
};
30+
31+
const chain = chainMap[viemChainName];
3532
if (!chain) {
3633
throw new Error(`Viem chain ${viemChainName} not found`);
3734
}
@@ -98,17 +95,7 @@ const getConfig = async (): Promise<Config> => {
9895

9996
return {
10097
out: "src/hooks/contracts/generated.ts",
101-
contracts: [
102-
...deploymentContracts,
103-
{
104-
name: "IHomeGateway",
105-
abi: getAbi(IHomeGateway),
106-
},
107-
{
108-
name: "IArbitrableV2",
109-
abi: getAbi(IArbitrableV2),
110-
},
111-
],
98+
contracts: [...deploymentContracts],
11299
plugins: [react(), actions()],
113100
};
114101
};

0 commit comments

Comments
 (0)