From 7355f73de89871d46438f9312d625accba8b4557 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Fri, 10 Aug 2018 14:25:39 -0400 Subject: [PATCH] Autoloading nonce, and allow changing the controller --- .../app/components/body-sntcontroller.js | 2 + .../app/components/status-sntcontroller.js | 44 ++++++++++++++----- test-dapp/app/components/transfersnt.js | 13 ++++++ test-dapp/contracts/token/MiniMeToken.sol | 2 +- 4 files changed, 48 insertions(+), 13 deletions(-) diff --git a/test-dapp/app/components/body-sntcontroller.js b/test-dapp/app/components/body-sntcontroller.js index c2b316e..e608071 100644 --- a/test-dapp/app/components/body-sntcontroller.js +++ b/test-dapp/app/components/body-sntcontroller.js @@ -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 = {}; diff --git a/test-dapp/app/components/status-sntcontroller.js b/test-dapp/app/components/status-sntcontroller.js index 2919f47..b49bb6d 100644 --- a/test-dapp/app/components/status-sntcontroller.js +++ b/test-dapp/app/components/status-sntcontroller.js @@ -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 { Address - { + - } diff --git a/test-dapp/app/components/transfersnt.js b/test-dapp/app/components/transfersnt.js index 8ba208e..df50d4c 100644 --- a/test-dapp/app/components/transfersnt.js +++ b/test-dapp/app/components/transfersnt.js @@ -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 { + + diff --git a/test-dapp/contracts/token/MiniMeToken.sol b/test-dapp/contracts/token/MiniMeToken.sol index 9ca777d..b84444e 100644 --- a/test-dapp/contracts/token/MiniMeToken.sol +++ b/test-dapp/contracts/token/MiniMeToken.sol @@ -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);