Skip to content

Commit 4d0c513

Browse files
committed
feat(web): fetch-dispute-kit-data-in-duplication
1 parent 8818c80 commit 4d0c513

File tree

5 files changed

+68
-6
lines changed

5 files changed

+68
-6
lines changed

web/src/hooks/queries/useRoundDetailsQuery.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ const roundDetailsQuery = graphql(`
1717
disputeKit {
1818
id
1919
}
20+
dispute {
21+
disputeKitDispute {
22+
... on ClassicDispute {
23+
extraData
24+
}
25+
}
26+
}
2027
}
2128
}
2229
`);

web/src/pages/Resolver/Landing/index.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { useDebounce } from "react-use";
77
import { Button } from "@kleros/ui-components-library";
88

99
import { AliasArray, Answer, useNewDisputeContext } from "context/NewDisputeContext";
10+
import { extraDataToTokenInfo } from "utils/extradataToTokenInfo";
1011

1112
import { useDisputeDetailsQuery } from "queries/useDisputeDetailsQuery";
1213
import { usePopulatedDisputeData } from "queries/usePopulatedDisputeData";
@@ -68,6 +69,13 @@ const Landing: React.FC = () => {
6869
isLoading: isLoadingRound,
6970
} = useRoundDetailsQuery(debouncedDisputeID, 0);
7071

72+
const gatedTokenInfo = useMemo(() => {
73+
const extradata = roundData?.round?.dispute.disputeKitDispute?.[0].extraData;
74+
75+
if (isUndefined(extradata)) return;
76+
return extraDataToTokenInfo(extradata);
77+
}, [roundData]);
78+
7179
const isLoading = useMemo(
7280
() => isLoadingDispute || isPopulatingDispute || isLoadingRound,
7381
[isLoadingDispute, isPopulatingDispute, isLoadingRound]
@@ -114,6 +122,7 @@ const Landing: React.FC = () => {
114122
disputeKitId: parseInt(roundData.round?.disputeKit.id ?? "1", 10),
115123
answers,
116124
aliasesArray: aliasesArray ?? disputeData.aliasesArray,
125+
disputeKitData: gatedTokenInfo ? { ...gatedTokenInfo, type: "gated" } : undefined,
117126
});
118127
// eslint-disable-next-line react-hooks/exhaustive-deps
119128
}, [populatedDispute, roundData, isInvalidDispute]);

web/src/pages/Resolver/Parameters/Court.tsx

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

44
import { AlertMessage, Checkbox, DropdownCascader, DropdownSelect, Field } from "@kleros/ui-components-library";
@@ -88,7 +88,6 @@ const StyledCheckbox = styled(Checkbox)`
8888

8989
const Court: React.FC = () => {
9090
const { disputeData, setDisputeData } = useNewDisputeContext();
91-
const [isGatedDisputeKit, setIsGatedDisputeKit] = useState(false);
9291
const { data: courtTree } = useCourtTree();
9392
const { data: supportedDisputeKits } = useSupportedDisputeKits(disputeData.courtId);
9493
const items = useMemo(() => !isUndefined(courtTree?.court) && [rootCourtToItems(courtTree.court)], [courtTree]);
@@ -123,7 +122,7 @@ const Court: React.FC = () => {
123122
};
124123

125124
const handleDisputeKitChange = (newValue: string | number) => {
126-
const options = disputeKitOptions.find((dk) => dk.value === String(newValue));
125+
const options = disputeKitOptions.find((dk) => String(dk.value) === String(newValue));
127126
const isNewValueGated = options?.gated ?? false;
128127
const gatedDisputeKitData: IGatedDisputeData | undefined = isNewValueGated
129128
? {
@@ -133,10 +132,14 @@ const Court: React.FC = () => {
133132
tokenId: "0",
134133
}
135134
: undefined;
136-
setIsGatedDisputeKit(isNewValueGated);
137135
setDisputeData({ ...disputeData, disputeKitId: Number(newValue), disputeKitData: gatedDisputeKitData });
138136
};
139137

138+
const isGatedDisputeKit = useMemo(() => {
139+
const options = disputeKitOptions.find((dk) => String(dk.value) === String(selectedDisputeKitId));
140+
return options?.gated ?? false;
141+
}, [disputeKitOptions, selectedDisputeKitId]);
142+
140143
const handleTokenAddressChange = (event: React.ChangeEvent<HTMLInputElement>) => {
141144
const currentData = disputeData.disputeKitData as IGatedDisputeData;
142145
setDisputeData({
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Address, hexToBytes } from "viem";
2+
3+
type GatedTokenInfo = {
4+
tokenGate: Address;
5+
isERC1155: boolean;
6+
tokenId: string;
7+
};
8+
9+
/**
10+
* @dev Decodes token information from encoded extra data.
11+
* @param extraData The extraData
12+
* @returns GatedTokenInfo object with tokenGate address, isERC1155 flag, and tokenId.
13+
*/
14+
export function extraDataToTokenInfo(extraDataHex: `0x${string}`): GatedTokenInfo {
15+
const extraDataBytes = hexToBytes(extraDataHex);
16+
17+
if (extraDataBytes.length < 160) {
18+
return {
19+
tokenGate: "0x0000000000000000000000000000000000000000",
20+
isERC1155: false,
21+
tokenId: "0",
22+
};
23+
}
24+
25+
// Slot 4 (bytes 96–127): packedTokenGateAndFlag
26+
const packedBytes = extraDataBytes.slice(96, 128);
27+
const packed = BigInt("0x" + Buffer.from(packedBytes).toString("hex"));
28+
29+
// Slot 5 (bytes 128–159): tokenId
30+
const tokenIdBytes = extraDataBytes.slice(128, 160);
31+
const tokenId = BigInt("0x" + Buffer.from(tokenIdBytes).toString("hex"));
32+
33+
// Extract tokenGate: lower 160 bits
34+
const tokenGateBigInt = packed & ((1n << 160n) - 1n); // mask: 0x00..00ffffffffffffffffffffffffffffffffffffffff
35+
const tokenGate = `0x${tokenGateBigInt.toString(16).padStart(40, "0")}` as Address;
36+
37+
// Extract flag: bit 160
38+
const isERC1155 = ((packed >> 160n) & 1n) === 1n;
39+
40+
return {
41+
tokenGate,
42+
isERC1155,
43+
tokenId: tokenId.toString(),
44+
};
45+
}

web/src/utils/prepareArbitratorExtradata.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ export const prepareArbitratorExtradata = (
5050
[subcourtID, noOfVotes, disputeKit]
5151
) as `0x{string}`;
5252
if (!disputeKitData) {
53-
console.log("extraData", extraData);
5453
return extraData;
5554
}
5655

@@ -60,6 +59,5 @@ export const prepareArbitratorExtradata = (
6059
}
6160
const encodedDisputeKitData = encoder(disputeKitData as any);
6261
extraData = ethers.utils.hexConcat([extraData, encodedDisputeKitData]) as `0x{string}`;
63-
console.log("extraData", extraData);
6462
return extraData;
6563
};

0 commit comments

Comments
 (0)