-
Notifications
You must be signed in to change notification settings - Fork 701
Expand file tree
/
Copy pathWallet.jsx
More file actions
49 lines (39 loc) · 1.07 KB
/
Wallet.jsx
File metadata and controls
49 lines (39 loc) · 1.07 KB
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
import server from "./server";
import { secp256k1 } from "@noble/curves/secp256k1";
import { bytesToHex } from "@noble/hashes/utils";
function Wallet({ address, setAddress, balance, setBalance, privateKey, setPrivateKey }) {
async function onChange(evt) {
const privateKey = evt.target.value;
setPrivateKey(privateKey);
const address = bytesToHex(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 a private key..."
value={privateKey}
onChange={onChange}
></input>
</label>
<div>
Public Key: {address ?
address.slice(0, 10) + "..." + address.slice(-10) :
"Invalid address"}
</div>
<div className="balance">Balance: {balance}</div>
</div>
);
}
export default Wallet;