From 728718199e879f577554741699e90355ea43e946 Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Thu, 31 May 2018 20:38:21 -0300 Subject: [PATCH] embed erc20token inside testtoken --- app/components/erc20token.js | 46 ++++++++++++++++-------------------- app/components/testtoken.js | 46 +++++------------------------------- app/dapp.js | 4 ---- 3 files changed, 26 insertions(+), 70 deletions(-) diff --git a/app/components/erc20token.js b/app/components/erc20token.js index 6695adf..0b318b3 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}); } @@ -50,7 +45,6 @@ class ERC20TokenUI extends React.Component { if (EmbarkJS.isNewWeb3()) { ERC20Token.methods.balanceOf(who).call() .then(_value => this.setState({balanceOf: _value})) - } else { ERC20Token.balanceOf(who) .then(_value => this.x({balanceOf: _value})); @@ -58,25 +52,32 @@ class ERC20TokenUI extends React.Component { this._addToLog(ERC20Token.options.address+".balanceOf(" + who + ")"); } + getDefaultAccountBalance(){ + if (EmbarkJS.isNewWeb3()) { + ERC20Token.methods.balanceOf(web3.eth.defaultAccount).call() + .then(_value => this.setState({accountBalance: _value})) + } else { + ERC20Token.balanceOf(web3.eth.defaultAccount) + .then(_value => this.x({valueGet: _value})) + } + this._addToLog(ERC20Token.options.address + ".balanceOf(" + web3.eth.defaultAccount + ")"); + } _addToLog(txt){ - this.state.logs.push(txt); - this.setState({logs: this.state.logs}); + console.log(txt); } render(){ return ( - -

Set token contract address

+ +

Read your account token balance

- this.contractAddress(e)} /> + Your test token balance is {this.state.accountBalance} +
- - +

Read account token balance

@@ -115,14 +116,7 @@ class ERC20TokenUI extends React.Component {
- -

Contract Calls

-

Javascript calls being made:

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

{item}

) - } -
+
); } diff --git a/app/components/testtoken.js b/app/components/testtoken.js index 3618caa..4f4b19a 100644 --- a/app/components/testtoken.js +++ b/app/components/testtoken.js @@ -2,17 +2,14 @@ import EmbarkJS from 'Embark/EmbarkJS'; import TestToken from 'Embark/contracts/TestToken'; 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, - accountBalance: 0, - accountB: web3.eth.defaultAccount, - balanceOf: 0, - logs: [] } } @@ -33,28 +30,10 @@ class TestTokenUI extends React.Component { } 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

+

Mint Test Token

-

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}

) - } -
+ +
); } diff --git a/app/dapp.js b/app/dapp.js index a0744b3..381f900 100644 --- a/app/dapp.js +++ b/app/dapp.js @@ -5,7 +5,6 @@ import { Tabs, Tab } from 'react-bootstrap'; import EmbarkJS from 'Embark/EmbarkJS'; import TopNavbar from './components/topnavbar'; import TestTokenUI from './components/testtoken'; -import ERC20TokenUI from './components/erc20token'; import './dapp.css'; @@ -40,9 +39,6 @@ class App extends React.Component { - - - ); }