/
main.js
97 lines (89 loc) · 2.7 KB
/
main.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
92
93
94
95
96
97
import { useState } from "react";
import axios from "axios";
import Select from "react-select";
import styles from "../styles/Home.module.css";
export default function Header() {
const [showResult, setShowResult] = useState(false);
const [result, setResult] = useState([]);
const [chainValue, setChainValue] = useState("");
let txHash;
const valueOptions = [
{ value: "0x1", label: "Ethereum" },
{ value: "0x5", label: "Goerli" },
{ value: "0x13881", label: "Mumbai" },
];
const customStyles = {
option: (provided) => ({
...provided,
color: "#000000",
backgroundColor: "#ffffff",
borderColor: "#00c3f8",
}),
};
const changeHandler = (chainValue) => {
setChainValue(chainValue);
};
const handleSubmit = async () => {
txHash = document.querySelector("#txHash").value;
const chain = chainValue.value;
const response = await axios.get(`http://localhost:5001/txhash`, {
params: { txHash, chain },
});
console.log(response);
setResult(response.data);
setShowResult(true);
document.querySelector("#txHash").value = "";
setChainValue("");
};
return (
<section className={styles.main}>
<form
className={styles.getForm}
name="create-profile-form"
method="POST"
action="#"
>
<label className={styles.label} htmlFor="txHash">
Add Transaction Hash
</label>
<input
className={styles.txHash}
type="text"
id="txHash"
name="txHash"
maxLength="120"
required
/>
<label className={styles.label} htmlFor="txHash">
Select Chain
</label>
<Select
styles={(customStyles, { borderColor: "#00c3f8" })}
options={valueOptions}
value={chainValue}
instanceId="long-value-select"
onChange={changeHandler}
/>
</form>
<button className={styles.form_btn} onClick={handleSubmit}>
Submit
</button>
<section className={styles.result}>
{showResult && (
<section className={styles.resultContainer}>
<section className={styles.resultContainer_header}>
<span>Time: {result.block_timestamp.split("T", 1)[0]}</span>
<span>Block Number: {result.block_number}</span>
</section>
<section className={styles.resultContainer_data}>
<p>From: {result.from_address}</p>
<p>To: {result.to_address}</p>
<p>Gas Price: {result.gas_price / 10 ** 9} Gwei</p>
<p>Transaction Hash: {result.hash}</p>
</section>
</section>
)}
</section>
</section>
);
}