-
Notifications
You must be signed in to change notification settings - Fork 702
Expand file tree
/
Copy pathWallet.jsx
More file actions
41 lines (32 loc) · 979 Bytes
/
Wallet.jsx
File metadata and controls
41 lines (32 loc) · 979 Bytes
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
import server from "./server";
const { secp256k1 } = require("ethereum-cryptography/secp256k1.js");
const { toHex } = require("ethereum-cryptography/utils");
function Wallet({ address, setAddress, balance, setBalance ,privateKey, setprivateKey }) {
async function onChange(evt) {
const privateKey = evt.target.value;
const address = toHex(secp256k1.getPublicKey(privateKey));
setAddress(address);
if (address) {
const {
data: { balance },
} = await server.get(`balance/${address}`);
setBalance(balance);
} else {
setBalance(0);
}
}
return (
<div className="container wallet">
<h1>Your Wallet</h1>
<label>
Private Key
<input placeholder="Type in your private key " value={privateKey} onChange={onChange}></input>
</label>
<div>
address: {address}
</div>
<div className="balance">balance: {balance}</div>
</div>
);
}
export default Wallet;