Adding STT Balance

This commit is contained in:
Richard Ramos 2018-08-06 14:10:25 -04:00
parent 1262299e77
commit 77e37eb872
1 changed files with 55 additions and 9 deletions

View File

@ -12,6 +12,7 @@ import ListItemIcon from '@material-ui/core/ListItemIcon';
import ListItemText from '@material-ui/core/ListItemText'; import ListItemText from '@material-ui/core/ListItemText';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import RefreshIcon from '@material-ui/icons/Refresh'; import RefreshIcon from '@material-ui/icons/Refresh';
import STT from 'Embark/contracts/STT';
import Typography from '@material-ui/core/Typography'; import Typography from '@material-ui/core/Typography';
import config from '../config'; import config from '../config';
import web3 from 'Embark/web3'; import web3 from 'Embark/web3';
@ -19,7 +20,10 @@ import {withStyles} from '@material-ui/core/styles';
const styles = theme => ({ const styles = theme => ({
button: { button: {
marginRight: theme.spacing.unit * 10 marginRight: theme.spacing.unit * 2
},
icon: {
marginRight: theme.spacing.unit
}, },
container: { container: {
width: '100%', width: '100%',
@ -43,12 +47,15 @@ class Status extends Component {
super(props); super(props);
this.state = { this.state = {
'identityEthBalance': 0, 'identityEthBalance': 0,
'identitySTTBalance': 0,
'relayerAddress': null, 'relayerAddress': null,
'relayerEthBalance': 0, 'relayerEthBalance': 0,
'relayerSTTBalance': 0,
'block': 0, 'block': 0,
'submitState': { 'submitState': {
'etherSend': false, 'etherSend': false,
'createIdentity': false 'createIdentity': false,
'generateSTT': false
} }
}; };
} }
@ -81,12 +88,45 @@ class Status extends Component {
.then(identityEthBalance => { .then(identityEthBalance => {
this.setState({identityEthBalance}); this.setState({identityEthBalance});
}); });
STT.methods.balanceOf(this.props.identityAddress)
.call()
.then(identitySTTBalance => {
this.setState({identitySTTBalance: web3.utils.fromWei(identitySTTBalance, 'ether')});
});
} }
web3.eth.getBalance(this.state.relayerAddress) web3.eth.getBalance(this.state.relayerAddress)
.then(relayerEthBalance => { .then(relayerEthBalance => {
this.setState({relayerEthBalance}); this.setState({relayerEthBalance});
}); });
STT.methods.balanceOf(this.state.relayerAddress)
.call()
.then(relayerSTTBalance => {
this.setState({relayerSTTBalance: web3.utils.fromWei(relayerSTTBalance, 'ether')});
});
}
generateSTT = (event) => {
event.preventDefault();
let submitState = this.state.submitState;
submitState.generateSTT = true;
this.setState({submitState});
let toSend = STT.methods.generateTokens(this.props.identityAddress, web3.utils.toWei(5000, 'ether'));
toSend.estimateGas()
.then(estimatedGas => {
return toSend.send({gas: estimatedGas + 10000});
})
.then((receipt) => {
console.log(receipt);
submitState = this.state.submitState;
submitState.generateSTT = false;
this.setState({submitState});
});
} }
createIdentity = (event) => { createIdentity = (event) => {
@ -121,19 +161,25 @@ class Status extends Component {
render(){ render(){
const {classes, identityAddress} = this.props; const {classes, identityAddress} = this.props;
const {identityEthBalance, relayerAddress, relayerEthBalance, submitState, block} = this.state; const {identityEthBalance, relayerAddress, relayerEthBalance, identitySTTBalance, relayerSTTBalance, submitState, block} = this.state;
return <div className={classes.container}> return <div className={classes.container}>
{ (submitState.createIdentity || submitState.etherSend) && <LinearProgress /> } { (submitState.createIdentity || submitState.etherSend || submitState.generateSTT) && <LinearProgress /> }
<List dense={true}> <List dense={true}>
<ListItem> <ListItem>
<Typography variant="display1"> <Typography variant="display1">
Identity Identity
</Typography> </Typography>
<Button className={classes.button} color="primary" aria-label="New Identity" onClick={this.createIdentity} disabled={submitState.createIdentity}> <Button className={classes.button} color="primary" aria-label="New Identity" onClick={this.createIdentity} disabled={submitState.createIdentity}>
<RefreshIcon /> <RefreshIcon className={classes.icon} />
Create new identity Create new identity
</Button> </Button>
{
<Button className={classes.button} color="primary" aria-label="Generate STT" onClick={this.generateSTT} disabled={submitState.generateSTT}>
<AddIcon className={classes.icon} />
Generate 5K STT (only on dev)
</Button>
}
</ListItem> </ListItem>
<ListItem className={classes.root}> <ListItem className={classes.root}>
<ListItemIcon> <ListItemIcon>
@ -153,8 +199,8 @@ class Status extends Component {
secondary="ETH Balance (wei)" secondary="ETH Balance (wei)"
/> />
<ListItemText <ListItemText
primary={0} primary={identitySTTBalance}
secondary="STT Balance (wei)" secondary="STT Balance"
/> />
</ListItem> </ListItem>
</List> </List>
@ -165,7 +211,7 @@ class Status extends Component {
Miner Miner
</Typography> </Typography>
<Button className={classes.button} color="primary" aria-label="Add ether" onClick={this.sendEther} disabled={submitState.etherSend}> <Button className={classes.button} color="primary" aria-label="Add ether" onClick={this.sendEther} disabled={submitState.etherSend}>
<AddIcon /> <AddIcon className={classes.icon} />
Send ether Send ether
</Button> </Button>
</ListItem> </ListItem>
@ -187,7 +233,7 @@ class Status extends Component {
secondary="ETH Balance (wei)" secondary="ETH Balance (wei)"
/> />
<ListItemText <ListItemText
primary={0} primary={relayerSTTBalance}
secondary="STT Balance (wei)" secondary="STT Balance (wei)"
/> />
</ListItem> </ListItem>