-
Notifications
You must be signed in to change notification settings - Fork 34
/
LoginView.tsx
102 lines (94 loc) · 3.05 KB
/
LoginView.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
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
98
99
100
101
102
import * as React from 'react';
import { useState } from 'react';
import gql from 'graphql-tag';
import { useQuery } from 'react-apollo';
const QUERY_CRYPTKEY = gql`
query {
keyStore {
protectedPrivateKeys {
address
}
}
}
`
const GET_DECRYPTKEY = gql`
query decreyptedPrivateKey($address: Address, $passphrase: String){
keyStore {
decryptedPrivateKey(
address: $address,
passphrase: $passphrase,
)
}
}
`;
export default function LoginView(props: any) {
const { loading, error, data } = useQuery(QUERY_CRYPTKEY)
error != undefined ? console.log(error) : null
return (
<div>
<div className="login">
<div className="container">
<div className="header">
<h3>Login</h3>
</div>
{
loading || error != undefined ?
<WaitComponent
error={error}
loading={loading}
/> :
<LoginComponent
{...props}
keyStore={data.keyStore}
error={error}
/>
}
</div>
</div>
</div>
);
}
function WaitComponent(props: any) {
const errorHandler = (error: any) => {
console.log(error);
return (
<label>An Error Accupied.</label>
)
}
return (
<div>
{
props.error != undefined ?
<label>{errorHandler(props.error)}</label> :
<label>Now Loading...</label>
}
<label></label>
</div>
)
}
function LoginComponent(props: any) {
//TODO: 플레이스홀더로 대체하고, 밑에서 input이 아니라 select로 바꿔서 여러 키 다 보여줄 수 있게 변경
const [address, setAddress] = useState(props.keyStore.protectedPrivateKeys[0].address);
const [passphrase, setPassphrase] = useState('placeholder');
const { loading, error, data } = useQuery(GET_DECRYPTKEY, {
variables: {
address: address,
passphrase: passphrase
},
})
const handleAccount = () => {
props.setAddress(address);
props.setPrivateKey(data.keyStore.decryptPrivateKey);
props.setLogin(true);
}
return (
<div>
<form>
<label>Address</label> <input value={address} onChange={event => { setAddress(event.target.value); console.log(address) }} type="text"></input>
<br />
<label>Passphrase</label> <input type="password" onChange={event => { setPassphrase(event.target.value); }}></input>
</form>
<button disabled={data == undefined} onClick={event => { handleAccount() }}>Login </button>
</div>
)
}