Autoloading nonce, and allow changing the controller

This commit is contained in:
Richard Ramos 2018-08-10 14:25:39 -04:00
parent 23b22b39d5
commit 7355f73de8
4 changed files with 48 additions and 13 deletions

View File

@ -1,6 +1,7 @@
import React, {Component, Fragment} from 'react';
import Divider from '@material-ui/core/Divider';
import EmbarkJS from 'Embark/EmbarkJS';
import STT from 'Embark/contracts/STT';
import PropTypes from 'prop-types';
import Status from './status-sntcontroller';
import Tab from '@material-ui/core/Tab';
@ -12,6 +13,7 @@ import config from '../config';
import web3 from 'Embark/web3';
import {withStyles} from '@material-ui/core/styles';
window.STT = STT;
const styles = {};

View File

@ -14,6 +14,7 @@ import ListItemIcon from '@material-ui/core/ListItemIcon';
import ListItemText from '@material-ui/core/ListItemText';
import NumberIcon from '@material-ui/icons/ConfirmationNumber';
import PropTypes from 'prop-types';
import SNTController from 'Embark/contracts/SNTController';
import STT from 'Embark/contracts/STT';
import Typography from '@material-ui/core/Typography';
import config from '../config';
@ -101,15 +102,19 @@ class Status extends Component {
this.setState({addressSTTBalance: web3.utils.fromWei(addressSTTBalance, 'ether')});
});
/*Identity.options.address = this.props.walletAddress;
Identity.methods.nonce()
.call()
.then((nonce) => {
this.props.nonceUpdateFunction(nonce);
})
.catch(() => {
console.log("Address " + this.props.walletAddress + " is not a valid wallet");
});*/
web3.eth.getAccounts()
.then(accounts => {
SNTController.methods.signNonce(accounts[2])
.call()
.then((nonce) => {
this.props.nonceUpdateFunction(nonce);
return true;
})
.catch(() => {
console.log("Address " + this.props.walletAddress + " is not a valid wallet");
});
return true;
});
}
web3.eth.getBalance(this.state.relayerAddress)
@ -145,6 +150,19 @@ class Status extends Component {
});
}
changeSNTController = event => {
event.preventDefault();
const toSend = STT.methods.changeController(SNTController.options.address);
toSend.estimateGas()
.then(estimatedGas => {
return toSend.send({gasLimit: estimatedGas + 100000});
})
.then(receipt => {
console.log(receipt);
});
}
sendEther = (event) => {
event.preventDefault();
@ -182,12 +200,14 @@ class Status extends Component {
<Typography variant="display1">
Address
</Typography>
{
<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)
1. Generate 5K STT (only on dev)
</Button>
<Button className={classes.button} color="primary" aria-label="Generate STT" onClick={this.changeSNTController}>
<AddIcon className={classes.icon} />
2. Change SNT Controller
</Button>
}
</ListItem>
<ListItem className={classes.root}>
<ListItemIcon>

View File

@ -8,6 +8,8 @@ import Grid from '@material-ui/core/Grid';
import MySnackbarContentWrapper from './snackbar';
import PropTypes from 'prop-types';
import SNTController from 'Embark/contracts/SNTController';
import STT from 'Embark/contracts/STT';
import TestContract from 'Embark/contracts/TestContract';
import TextField from '@material-ui/core/TextField';
import config from '../config';
@ -52,6 +54,15 @@ class TransferSNT extends Component {
});
};
getBalance = (event) => {
event.preventDefault();
STT.methods.balanceOf(this.state.to)
.call()
.then(balance => {
console.log("Balance of " + this.state.to + ": " + balance + " STT");
});
}
sign = (event) => {
if(event) event.preventDefault();
@ -188,6 +199,8 @@ class TransferSNT extends Component {
<Button color="primary" onClick={this.sign}>
Sign Message
</Button>
<Button size="small" onClick={this.getBalance}>STT.methods.balanceOf(to).call()</Button>
</CardActions>
</Card>

View File

@ -456,7 +456,7 @@ contract MiniMeToken is MiniMeTokenInterface, Controlled {
uint _amount
)
public
onlyController
// onlyController TODO: UNCOMMENT THIS. THIS WAS DISABLED FOR DEMO PURPOSES
returns (bool)
{
uint curTotalSupply = totalSupplyAt(block.number);