diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..8aa924d --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["@babel/preset-env"] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..f8ab647 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,9 @@ +{ + "extends": "airbnb", + "plugins": [ + "react" + ], + "rules": { + "react/prop-types": 0 + } +} diff --git a/.gitignore b/.gitignore index 5c20c22..2b75c2d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,8 +6,7 @@ __pycache__/ # embark .embark/ chains.json -config/production/password -config/livenet/password +.password # egg-related viper.egg-info/ diff --git a/README.md b/README.md index c767e1f..03c5c16 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ # status.im contracts - +Requires https://github.com/creationix/nvm Usage: ``` + nvm install v8.9.4 + nvm use v8.9.4 npm install -g embark git clone https://github.com/status-im/contracts.git cd contracts @@ -16,4 +18,4 @@ Usage: | token/TestToken | Yes | Yes | Yes | | token/ERC20Token | No | Yes | Yes | | deploy/Instance | No | No | No | -| deploy/Factory | No | No | No | \ No newline at end of file +| deploy/Factory | No | No | No | diff --git a/app/components/TestStatusNetwork.js b/app/components/TestStatusNetwork.js new file mode 100644 index 0000000..e974e51 --- /dev/null +++ b/app/components/TestStatusNetwork.js @@ -0,0 +1,50 @@ +import EmbarkJS from 'Embark/EmbarkJS'; +import StatusRoot from 'Embark/contracts/StatusRoot'; +import MiniMeToken from 'Embark/contracts/MiniMeToken'; +import React from 'react'; +import { Form, FormGroup, FormControl, HelpBlock, Button } from 'react-bootstrap'; +import ERC20TokenUI from './erc20token'; + +class TestTokenUI extends React.Component { + + constructor(props) { + super(props); + this.state = { + amountToMint: 100, + } + } + + handleMintAmountChange(e){ + this.setState({amountToMint: e.target.value}); + } + + async mint(e){ + e.preventDefault(); + await EmbarkJS.enableEthereum(); + var value = parseInt(this.state.amountToMint, 10); + StatusRoot.methods.mint(value).send({ gas: 1000000 }) + + console.log(StatusRoot.options.address +".mint("+value+").send({from: " + web3.eth.defaultAccount + "})"); + } + + render(){ + return ( + Test Status Network + + + this.handleMintAmountChange(e)} /> + this.mint(e)}>Mint + + + + + + + ); + } + } + +export default TestTokenUI; diff --git a/app/components/erc20token.js b/app/components/erc20token.js index 6695adf..7b8ffdf 100644 --- a/app/components/erc20token.js +++ b/app/components/erc20token.js @@ -7,21 +7,16 @@ class ERC20TokenUI extends React.Component { constructor(props) { super(props); + ERC20Token.options.address = props.address; this.state = { - balanceOf: 0, transferTo: "", transferAmount: 0, - logs: [] + accountBalance: 0, + accountB: web3.eth.defaultAccount, } } - contractAddress(e){ - e.preventDefault(); - var tokenAddress = e.target.value; - ERC20Token.options.address = tokenAddress; - } - update_transferTo(e){ this.setState({transferTo: e.target.value}); } @@ -33,99 +28,87 @@ class ERC20TokenUI extends React.Component { transfer(e){ var to = this.state.transferTo; var amount = this.state.transferAmount; - var tx = ERC20Token.methods.transfer(to, amount).send({from: web3.eth.defaultAccount}); - this._addToLog(ERC20Token.options.address+".transfer(" + to + ", "+amount+")"); + this._addToLog(ERC20Token.options.address+".methods.transfer(" + to + ", "+amount+").send({from: " + web3.eth.defaultAccount + "})"); + var tx = ERC20Token.methods.transfer(to, amount); + tx.estimateGas().then((r) => { + tx.send({gas: r, from: web3.eth.defaultAccount}); + }); + } approve(e){ var to = this.state.transferTo; var amount = this.state.transferAmount; + this._addToLog(ERC20Token.options.address+".methods.approve(" + to + ", "+amount+").send({from: " + web3.eth.defaultAccount + "})"); var tx = ERC20Token.methods.approve(to, amount).send({from: web3.eth.defaultAccount}); - this._addToLog(ERC20Token.options.address+".approve(" + to + ", "+amount+")"); + } balanceOf(e){ e.preventDefault(); var who = e.target.value; - if (EmbarkJS.isNewWeb3()) { - ERC20Token.methods.balanceOf(who).call() - .then(_value => this.setState({balanceOf: _value})) - - } else { - ERC20Token.balanceOf(who) - .then(_value => this.x({balanceOf: _value})); - } - this._addToLog(ERC20Token.options.address+".balanceOf(" + who + ")"); + this._addToLog(ERC20Token.options.address+".methods.balanceOf(" + who + ").call()"); + ERC20Token.methods.balanceOf(who).call() + .then(_value => this.setState({balanceOf: _value})) } + getDefaultAccountBalance(){ + this._addToLog(ERC20Token.options.address + ".methods.balanceOf(" + web3.eth.defaultAccount + ").call()"); + ERC20Token.methods.balanceOf(web3.eth.defaultAccount).call() + .then(_value => this.setState({accountBalance: _value})) + } _addToLog(txt){ - this.state.logs.push(txt); - this.setState({logs: this.state.logs}); + console.log(txt); } - render(){ - return ( - - Set token contract address - - + render() { + + return ( + + Read account token balance + + + + Of: this.contractAddress(e)} /> - - + defaultValue={this.state.accountB} + onChange={(e) => this.balanceOf(e)} /> + + + {this.state.balanceOf} + + + + - - Read account token balance - - - - Of: - this.balanceOf(e)} /> - - - {this.state.balanceOf} - - - - - - Transfer/Approve token balance - - - - To: - this.update_transferTo(e) } /> - - - Amount: - this.update_transferAmount(e) } /> - - this.transfer(e)}>Transfer - this.approve(e)}>Approve - - - - Contract Calls - Javascript calls being made: - - { - this.state.logs.map((item, i) => {item}) - } - + Transfer/Approve token balance + + + + To: + this.update_transferTo(e) } /> + + + Amount: + this.update_transferAmount(e) } /> + + this.transfer(e)}>Transfer + this.approve(e)}>Approve + + + - ); - } + ); } +} - export default ERC20TokenUI; \ No newline at end of file + +export default ERC20TokenUI; diff --git a/app/components/testtoken.js b/app/components/testtoken.js deleted file mode 100644 index 3618caa..0000000 --- a/app/components/testtoken.js +++ /dev/null @@ -1,88 +0,0 @@ -import EmbarkJS from 'Embark/EmbarkJS'; -import TestToken from 'Embark/contracts/TestToken'; -import React from 'react'; -import { Form, FormGroup, FormControl, HelpBlock, Button } from 'react-bootstrap'; - -class TestTokenUI extends React.Component { - - constructor(props) { - super(props); - this.state = { - amountToMint: 100, - accountBalance: 0, - accountB: web3.eth.defaultAccount, - balanceOf: 0, - logs: [] - } - } - - handleMintAmountChange(e){ - this.setState({amountToMint: e.target.value}); - } - - mint(e){ - e.preventDefault(); - - var value = parseInt(this.state.amountToMint, 10); - - if (EmbarkJS.isNewWeb3()) { - TestToken.methods.mint(value).send({from: web3.eth.defaultAccount}); - } else { - TestToken.mint(value); - this._addToLog("#blockchain", "TestToken.mint(" + value + ")"); - } - this._addToLog(TestToken.options.address +".mint("+value+").send({from: " + web3.eth.defaultAccount + "})"); - } - - getBalance(e){ - e.preventDefault(); - - if (EmbarkJS.isNewWeb3()) { - TestToken.methods.balanceOf(web3.eth.defaultAccount).call() - .then(_value => this.setState({accountBalance: _value})) - } else { - TestToken.balanceOf(web3.eth.defaultAccount) - .then(_value => this.x({valueGet: _value})) - } - this._addToLog(TestToken.options.address + ".balanceOf(" + web3.eth.defaultAccount + ")"); - } - - _addToLog(txt){ - this.state.logs.push(txt); - this.setState({logs: this.state.logs}); - } - - render(){ - return ( - 1. Mint Test Token - - - this.handleMintAmountChange(e)} /> - this.mint(e)}>Mint - - - - 2. Read your account token balance - - - Your test token balance is {this.state.accountBalance} - this.getBalance(e)}>Get Balance - - - - 3. Contract Calls - Javascript calls being made: - - { - this.state.logs.map((item, i) => {item}) - } - - - ); - } - } - - export default TestTokenUI; \ No newline at end of file diff --git a/app/dapp.css b/app/dapp.css index 49f1976..0fd02eb 100644 --- a/app/dapp.css +++ b/app/dapp.css @@ -1,8 +1,18 @@ - -div { - margin: 15px; +.navbar { + } +.accounts { + float: right; + margin-right: 17px; + font-family: monospace; +} + +.identicon { + border-radius: 50%; +} + + .logs { background-color: black; font-size: 14px; diff --git a/app/dapp.js b/app/dapp.js index 6df03e3..b2473b5 100644 --- a/app/dapp.js +++ b/app/dapp.js @@ -1,14 +1,11 @@ import React from 'react'; -import ReactDOM from 'react-dom'; import { Tabs, Tab } from 'react-bootstrap'; - import EmbarkJS from 'Embark/EmbarkJS'; -import TestTokenUI from './components/testtoken'; -import ERC20TokenUI from './components/erc20token'; +import TestStatusNetworkUI from './components/TestStatusNetwork'; import './dapp.css'; -class App extends React.Component { +class DApp extends React.Component { constructor(props) { super(props); @@ -17,13 +14,11 @@ class App extends React.Component { } componentDidMount(){ - __embarkContext.execWhenReady(() => { - - }); + } - _renderStatus(title, available){ + _renderStatus(title, available) { let className = available ? 'pull-right status-online' : 'pull-right status-offline'; return {title} @@ -32,17 +27,16 @@ class App extends React.Component { } render(){ - return (Status.im Contracts - - - - - - - - - ); + return ( + + + + + + + + ); } } -ReactDOM.render(, document.getElementById('app')); +export default DApp; diff --git a/app/index.html b/app/index.html index 1fb8607..43438ee 100644 --- a/app/index.html +++ b/app/index.html @@ -7,6 +7,6 @@ - +
Javascript calls being made:
{item}