-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStatus.js
78 lines (65 loc) · 2.42 KB
/
Status.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
import React, { useState } from 'react'
import { TextField, Typography, Button } from '@material-ui/core'
import { useAccountEffect, useWeb3Context } from 'web3-react/hooks'
import { useGenericContract, useNamedContract } from '../../../../common/hooks'
import TransactionButton from '../../../common/TransactionButton'
import { ABI } from './index'
export default function Status ({ ein }) {
const context = useWeb3Context()
const [currentStatus, setCurrentStatus] = useState('')
const [newStatus, setNewStatus] = useState('')
const [lookupHydroId, setLookupHydroId] = useState('')
const [lookupStatus, setLookupStatus] = useState('')
const clientRaindropContract = useNamedContract('clientRaindrop')
const statusContract = useGenericContract('0x16fD6e2E1C4afB9C4e7B901141706596317e4ceB', ABI)
useAccountEffect(() => {
statusContract.methods.getStatus(ein).call().then(status => setCurrentStatus(status))
})
function checkStatus () {
clientRaindropContract.methods["getDetails(string)"](lookupHydroId).call()
.then(result => {
statusContract.methods.getStatus(result.ein).call()
.then(result => {
result === '' ? setLookupStatus('The given Hydro ID has not set a status yet.') : setLookupStatus(result)
})
})
.catch(() => {
setLookupStatus('The given Hydro ID does not exist.')
})
}
return (
<div>
<Typography variant='h2' gutterBottom align="center" color="textPrimary">
{currentStatus}
</Typography>
<TextField
label="New Status"
helperText="This will be public."
margin="normal"
value={newStatus}
onChange={e => setNewStatus(e.target.value)}
fullWidth
/>
<TransactionButton
readyText='Set Status'
method={() => statusContract.methods.setStatus(newStatus)}
onConfirmation={context.forceAccountReRender}
/>
<hr style={{marginTop: 30, marginBottom: 30}} />
<Typography variant='h2' gutterBottom align="center" color="textPrimary">
{lookupStatus}
</Typography>
<TextField
label="Hydro Id"
helperText="View a Hydro ID's status."
margin="normal"
value={lookupHydroId}
onChange={e => setLookupHydroId(e.target.value)}
fullWidth
/>
<Button variant='contained' color='primary' onClick={checkStatus}>
Look Up
</Button>
</div>
)
}