-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.tsx
67 lines (55 loc) · 1.57 KB
/
index.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
import { FormEvent, useCallback, useEffect, useState } from 'react'
import '../../pageStyles.css'
import { OrderBookApi, EnrichedOrder, Address } from '@cowprotocol/cow-sdk'
import { useWeb3Info } from '../../hooks/useWeb3Info'
import { useCurrentChainId } from '../../hooks/useCurrentChainId'
import { JsonContent } from '../../components/jsonContent'
import { ResultContent } from '../../components/resultContent'
const orderBookApi = new OrderBookApi()
export function GetOrdersPage() {
const { account } = useWeb3Info()
const chainId = useCurrentChainId()
const [input, setInput] = useState<{
owner: Address
offset?: number
limit?: number
} | null>(null)
const [output, setOutput] = useState<Array<EnrichedOrder> | string>('')
useEffect(() => {
orderBookApi.context.chainId = chainId
}, [chainId])
const getOrders = useCallback(
(event: FormEvent) => {
event.preventDefault()
if (!input) return
setOutput('Loading...')
orderBookApi
.getOrders(input)
.then(setOutput)
.catch((error) => {
console.error(error)
setOutput(error.toString())
})
},
[input]
)
const defaultValue = {
owner: account,
limit: 10,
offset: 0,
}
return (
<div>
<div className="form">
<div>
<h1>Params:</h1>
<JsonContent defaultValue={defaultValue} onChange={setInput} />
</div>
<div>
<button onClick={getOrders}>Get orders</button>
</div>
</div>
<ResultContent data={output} />
</div>
)
}