mirror of
https://github.com/status-im/snt-voting.git
synced 2025-02-23 23:58:13 +00:00
SNT minting
This commit is contained in:
parent
ad7afe0597
commit
c6f7e54cac
104
app/components/snt-ui.js
Normal file
104
app/components/snt-ui.js
Normal file
@ -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 (<React.Fragment>
|
||||||
|
<h3> 1. Mint SNT Token</h3>
|
||||||
|
<Form inline>
|
||||||
|
<FormGroup>
|
||||||
|
<FormControl
|
||||||
|
type="text"
|
||||||
|
value={this.state.address}
|
||||||
|
onChange={(e) => this.setState({address: e.target.value}) } />
|
||||||
|
</FormGroup>
|
||||||
|
<FormGroup>
|
||||||
|
<FormControl
|
||||||
|
type="text"
|
||||||
|
defaultValue={this.state.amountToMint}
|
||||||
|
onChange={(e) => this.handleMintAmountChange(e)} />
|
||||||
|
<Button bsStyle="primary" onClick={(e) => this.mint(e)}>Mint</Button>
|
||||||
|
</FormGroup>
|
||||||
|
</Form>
|
||||||
|
|
||||||
|
<h3> 2. Read your account token balance </h3>
|
||||||
|
<Form inline>
|
||||||
|
<FormGroup>
|
||||||
|
<HelpBlock>Your test token balance is <span className="accountBalance">{this.state.accountBalance}</span></HelpBlock>
|
||||||
|
<Button bsStyle="primary" onClick={(e) => this.getBalance(e)}>Get Balance</Button>
|
||||||
|
</FormGroup>
|
||||||
|
</Form>
|
||||||
|
|
||||||
|
<h3> 3. Contract Calls </h3>
|
||||||
|
<p>Javascript calls being made: </p>
|
||||||
|
<div className="logs">
|
||||||
|
{
|
||||||
|
this.state.logs.map((item, i) => <p key={i}>{item}</p>)
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SNTUI;
|
10
app/dapp.js
10
app/dapp.js
@ -8,6 +8,7 @@ import TestTokenUI from './components/testtoken';
|
|||||||
import ERC20TokenUI from './components/erc20token';
|
import ERC20TokenUI from './components/erc20token';
|
||||||
import ProposalManager from './components/proposal-manager/proposal-manager'
|
import ProposalManager from './components/proposal-manager/proposal-manager'
|
||||||
import VotingDapp from './components/voting-dapp/voting-dapp';
|
import VotingDapp from './components/voting-dapp/voting-dapp';
|
||||||
|
import SNTUI from './components/snt-ui';
|
||||||
|
|
||||||
import SNT from 'Embark/contracts/SNT';
|
import SNT from 'Embark/contracts/SNT';
|
||||||
window['SNT'] = SNT;
|
window['SNT'] = SNT;
|
||||||
@ -45,13 +46,16 @@ class App extends React.Component {
|
|||||||
<Tab eventKey={0} title="VotingDapp">
|
<Tab eventKey={0} title="VotingDapp">
|
||||||
<VotingDapp />
|
<VotingDapp />
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab eventKey={3} title="ProposalManager">
|
<Tab eventKey={1} title="ProposalManager">
|
||||||
<ProposalManager />
|
<ProposalManager />
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab eventKey={1} title="TestToken">
|
<Tab eventKey={2} title="SNT Token">
|
||||||
|
<SNTUI />
|
||||||
|
</Tab>
|
||||||
|
<Tab eventKey={3} title="TestToken">
|
||||||
<TestTokenUI />
|
<TestTokenUI />
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab eventKey={2} title="ERC20Token">
|
<Tab eventKey={4} title="ERC20Token">
|
||||||
<ERC20TokenUI />
|
<ERC20TokenUI />
|
||||||
</Tab>
|
</Tab>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user