-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContractTrades.js
93 lines (75 loc) · 2.01 KB
/
ContractTrades.js
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
import { TrademarkOutlined } from "@ant-design/icons";
import { Button, Modal, Skeleton, Tooltip } from "antd";
import { useEffect, useState } from "react";
import { getContractTrades } from "../utils";
import {
LineChart,
Line,
YAxis,
XAxis,
CartesianGrid,
Tooltip as ChartTooltip,
} from "recharts";
const ratio = 6900000000000000 / 1300;
const ModalContent = ({ tokenAddress }) => {
const [loading, setLoading] = useState(true);
const [data, setData] = useState([]);
useEffect(() => {
getContractTrades(tokenAddress)
.then((resp) => {
setData(
resp.result.reverse().map((item) => {
return {
...item,
price: Math.floor(Number(item.price) / ratio),
block_timestamp: new Date(
item.block_timestamp
).toLocaleDateString(),
};
})
);
})
.finally(() => {
setLoading(false);
});
}, []);
if (loading) {
return <Skeleton active />;
}
return (
<LineChart width={800} height={600} data={data} margin={{ left: 120 }}>
<Line type="monotone" dataKey="price" stroke="#8884d8" />
<CartesianGrid stroke="#ccc" strokeDasharray="5 5" />
<XAxis dataKey="block_timestamp" />
<YAxis />
<ChartTooltip />
</LineChart>
);
};
const ContractTrades = ({ tokenAddress }) => {
const [modalOpen, setModalOpen] = useState();
return (
<>
<Tooltip title="Trade(s) in this contract">
<Button
disabled={tokenAddress === ""}
style={{ border: "none" }}
shape="circle"
icon={<TrademarkOutlined />}
onClick={() => setModalOpen(true)}
/>
</Tooltip>
<Modal
width={1000}
title="Trade(s) Chart"
destroyOnClose
open={modalOpen}
footer={null}
onCancel={() => setModalOpen(false)}
>
<ModalContent tokenAddress={tokenAddress} />
</Modal>
</>
);
};
export default ContractTrades;