diff --git a/app/components/snt-ui.js b/app/components/snt-ui.js new file mode 100644 index 0000000..82be32a --- /dev/null +++ b/app/components/snt-ui.js @@ -0,0 +1,104 @@ +import EmbarkJS from 'Embark/EmbarkJS'; +import SNT from 'Embark/contracts/SNT'; +import React from 'react'; +import { Form, FormGroup, FormControl, HelpBlock, Button } from 'react-bootstrap'; +import web3 from "Embark/web3" + +class SNTUI extends React.Component { + + constructor(props) { + super(props); + this.state = { + address: "", + amountToMint: 100, + accountBalance: 0, + accountB: web3.eth.defaultAccount, + balanceOf: 0, + logs: [] + } + } + + componentDidMount(){ + __embarkContext.execWhenReady(async () => { + this.setState({address: web3.eth.defaultAccount}); + }); + } + + handleMintAmountChange(e){ + this.setState({amountToMint: e.target.value}); + } + + mint(e){ + e.preventDefault(); + + var value = parseInt(this.state.amountToMint, 10); + var address = this.state.address; + + SNT.methods.controller().call() + .then((controller) => { + return SNT.methods.generateTokens(address, value) + .send({from: controller, gasLimit: 1000000}); + }) + .then(console.log); + + this._addToLog(SNT.options.address +".mint("+value+").send({from: " + web3.eth.defaultAccount + "})"); + } + + getBalance(e){ + e.preventDefault(); + + if (EmbarkJS.isNewWeb3()) { + SNT.methods.balanceOf(web3.eth.defaultAccount).call() + .then(_value => this.setState({accountBalance: _value})) + } else { + SNT.balanceOf(web3.eth.defaultAccount) + .then(_value => this.x({valueGet: _value})) + } + this._addToLog(SNT.options.address + ".balanceOf(" + web3.eth.defaultAccount + ")"); + } + + _addToLog(txt){ + this.state.logs.push(txt); + this.setState({logs: this.state.logs}); + } + + render(){ + return ( +

1. Mint SNT Token

+
+ + this.setState({address: e.target.value}) } /> + + + this.handleMintAmountChange(e)} /> + + +
+ +

2. Read your account token balance

+
+ + Your test token balance is {this.state.accountBalance} + + +
+ +

3. Contract Calls

+

Javascript calls being made:

+
+ { + this.state.logs.map((item, i) =>

{item}

) + } +
+
+ ); + } + } + + export default SNTUI; \ No newline at end of file diff --git a/app/dapp.js b/app/dapp.js index 7a26b87..2a17365 100644 --- a/app/dapp.js +++ b/app/dapp.js @@ -8,6 +8,7 @@ import TestTokenUI from './components/testtoken'; import ERC20TokenUI from './components/erc20token'; import ProposalManager from './components/proposal-manager/proposal-manager' import VotingDapp from './components/voting-dapp/voting-dapp'; +import SNTUI from './components/snt-ui'; import SNT from 'Embark/contracts/SNT'; window['SNT'] = SNT; @@ -45,13 +46,16 @@ class App extends React.Component { - + - + + + + - +