-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathFetchDisputeRequestInput.tsx
139 lines (124 loc) · 3.67 KB
/
FetchDisputeRequestInput.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import React, { useEffect, useState } from "react";
import styled from "styled-components";
import { useDebounce } from "react-use";
import { GetEventArgs } from "viem";
import { Field } from "@kleros/ui-components-library";
import { DEFAULT_CHAIN } from "consts/chains";
import { iArbitrableV2Abi } from "hooks/contracts/generated";
import { getDisputeRequestParamsFromTxn } from "utils/getDisputeRequestParamsFromTxn";
import { isUndefined } from "utils/isUndefined";
const Container = styled.div`
display: flex;
flex-direction: column;
margin-top: 24px;
margin-left: 24px;
`;
const InputContainer = styled.div`
display: flex;
flex-wrap: wrap;
gap: 8px;
`;
const StyledChainInput = styled(Field)`
width: 120px;
`;
const StyledHeader = styled.h2`
margin-top: 24px;
`;
const StyledH3 = styled.h3`
margin-top: 28px;
`;
const PresetsContainer = styled.div`
display: flex;
gap: 16px;
flex-wrap: wrap;
`;
const StyledA = styled.a`
cursor: pointer;
`;
const presets = [
{
title: "Escrow",
txnHash: "0x2565b756e500240544f7fc36f938462c7efbbd2e343c57979f81fecdf1054e23",
chainId: 421614,
},
{
title: "Curated Lists",
txnHash: "0xa7981830bf8144ab2070f3a639bd36b204c4c48ee1fafef66abaf60272418ed4",
chainId: 421614,
},
{
title: "Trump-Harris",
txnHash: "0x86db91678cf3f8c4503e37340cf2cd93bffcba84f9c43a98c090f6a4c76d8793",
chainId: 421614,
},
];
export type DisputeRequest = GetEventArgs<typeof iArbitrableV2Abi, "DisputeRequest", { IndexedOnly: false }> & {
_arbitrable: `0x${string}`;
};
interface IFetchDisputeRequestInput {
setParams: (params: DisputeRequest) => void;
}
const FetchDisputeRequestInput: React.FC<IFetchDisputeRequestInput> = ({ setParams }) => {
const [chainId, setChainId] = useState<number>(DEFAULT_CHAIN);
const [txnHash, setTxnHash] = useState<string>("");
const [debouncedTxnHash, setDebouncedTxnHash] = useState<string>("");
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
useDebounce(
() => {
setDebouncedTxnHash(txnHash);
},
1000,
[txnHash]
);
useEffect(() => {
const fetchData = async () => {
setLoading(true);
try {
const params = await getDisputeRequestParamsFromTxn(debouncedTxnHash as `0x${string}`, chainId);
if (!isUndefined(params)) setParams(params);
setError(null);
} catch (error) {
console.error("Error fetching dispute request params:", error);
setError("Failed to fetch dispute request parameters");
} finally {
setLoading(false);
}
};
if (debouncedTxnHash && chainId) fetchData();
}, [debouncedTxnHash, chainId]);
return (
<Container>
<StyledHeader>Fetch Dispute Request params from transaction</StyledHeader>
<InputContainer>
<Field
value={txnHash}
placeholder="Enter transaction hash"
onChange={(e) => setTxnHash(e.target.value)}
message={loading ? "fetching ..." : error || ""}
/>
<StyledChainInput
value={chainId}
placeholder="Enter chain Id"
type="number"
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setChainId(Number(e.target.value))}
/>
</InputContainer>
<StyledH3>Presets</StyledH3>
<PresetsContainer>
{presets.map((preset) => (
<StyledA
key={preset.txnHash}
onClick={() => {
setTxnHash(preset.txnHash);
setChainId(preset.chainId);
}}
>
{preset.title}
</StyledA>
))}
</PresetsContainer>
</Container>
);
};
export default FetchDisputeRequestInput;