/
Home.tsx
64 lines (57 loc) · 1.62 KB
/
Home.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
import React, { useState } from 'react';
import { signWithPrivateKey, useApiService } from '@app/services';
import { makeTx } from '@utils';
export const Home = () => {
const { approveCurrent, denyCurrent, currentTx, txQueueLength } = useApiService();
const [privKey, setPrivKey] = useState('');
const [error, setError] = useState('');
const handleDeny = async () => {
if (currentTx) {
denyCurrent();
setError('');
}
};
const handleAccept = async () => {
if (privKey.length > 0 && currentTx) {
try {
const formattedTx = makeTx(currentTx);
const signed = await signWithPrivateKey(privKey, formattedTx);
approveCurrent(signed);
setError('');
} catch (err) {
setError(err.message);
}
}
};
const changePrivateKey = (e: React.ChangeEvent<HTMLInputElement>) =>
setPrivKey(e.currentTarget.value);
return (
<div>
{txQueueLength > 1 && (
<>
{`TXs in queue: ${txQueueLength}`}
<br />
</>
)}
{currentTx ? <pre>{JSON.stringify(currentTx, null, 2)}</pre> : 'Nothing to sign'}
<br />
<label htmlFor="privkey">Private Key</label>
<br />
<input id="privkey" name="privkey" type="text" onChange={changePrivateKey} />
<br />
<button id="deny_button" type="button" disabled={!currentTx} onClick={handleDeny}>
Deny
</button>
<button
id="accept_button"
type="button"
disabled={!currentTx || privKey.length === 0}
onClick={handleAccept}
>
Accept
</button>
<br />
{error}
</div>
);
};