Commit 6dbf1fce authored by Simon de la Rouviere's avatar Simon de la Rouviere

Switched to async.

parent b9f511b8
......@@ -5,10 +5,12 @@ import ReactDOM from "react-dom";
import ReactRouter from "react-router";
import { Router, Route, IndexRoute, Link } from 'react-router';
import { TXActions } from 'reflux-tx';
import {TXComponent} from "reflux-tx";
//import TXActions from "reflux-tx".TXActions;
//import TXComponent from "reflux-tx".TXComponent;
//import AccountBadge from "react-account-badge";
var web3 = require("./web3_bootstrap.js");
window.web3 = web3; //hacky way to force checked web3 to be used everywhere vs accidentally using injected web3.
//import Web3 from "web3";
//web3? Apparently it is "provided"?
......@@ -31,7 +33,7 @@ var $ = require('jquery');
//window.TXActions = refluxTX.TXActions;
//window.TXComponent = refluxTX.TXComponent;
console.log(TXActions);
//console.log(TXActions);
TXActions.connect(web3, {confirmCount: 1, bufferSize: 5})
//window.web3_rab = new Web3();
......@@ -54,41 +56,30 @@ let history = createHistory({
let App = React.createClass({
getInitialState: function() {
return {
blockNumber: web3.eth.blockNumber,
blockNumber: 0,
offline_msg: ''
};
},
componentDidMount: function() {
var that = this;
if(window.offline == true) {
console.log('offline');
this.setState({offline_msg: "YOU ARE OFFLINE."});
this.setState({blockNumber: 'OFFLINE'});
}
//filter here seems like "non"-react way to do things.
//TXComponent inherits blocknumber. Use that instead.
web3.eth.filter('latest', function(error, result){
if (!error)
console.log('app watcher');
setTimeout(that.checkBlockNumber, 1000); //wait a bit
});
//TODO: log current address in here instead with a timeout
},
checkBlockNumber: function() {
//console.log(web3);
var nbn = web3.eth.blockNumber;
if(nbn > this.state.blockNumber) {
console.log(nbn);
this.setState({blockNumber: nbn});
}
},
render: function() {
return (
<div className="container">
<div className="row">
<div className="col-md-6 col-md-offset-3">
<NavBar blockNumber={this.state.blockNumber} offline_msg={this.state.offline_msg}/>
<TXComponent>
<NavBar offline_msg={this.state.offline_msg}/>
</TXComponent>
{this.props.children}
</div>
</div>
......
......@@ -26,21 +26,24 @@ var TokenPage = React.createClass({
window.token_c = web3_token;
this.setState({web3_token: web3_token});
var that = this;
web3.eth.getAccounts(function(err, accounts){
var addr = accounts[0];
console.log(addr);
var totalSupply = web3_token.totalSupply.call({from: addr});
console.log(totalSupply);
that.setState({totalSupply: totalSupply.c[0]});
that.setState({current_user_address: addr});
var decimals = web3_token.decimals.call({from: addr});
var symbol = web3_token.symbol.call({from: addr});
var name = web3_token.name.call({from: addr});
if(decimals) { that.setState({token_decimals: decimals}); }
if(symbol) { that.setState({token_symbol: symbol}); }
if(name) { that.setState({token_name: name}); }
console.log(decimals + symbol + name);
var accounts = web3.eth.accounts;
var addr = accounts[0];
web3_token.totalSupply.call({from: addr}, function(err, totalSupply) {
console.log(totalSupply);
that.setState({totalSupply: totalSupply.c[0]});
});
that.setState({current_user_address: addr});
web3_token.decimals.call({from: addr}, function(err, decimals) {
if(decimals) { that.setState({token_decimals: decimals}); }
});
web3_token.symbol.call({from: addr}, function(err, symbol) {
if(symbol) { that.setState({token_symbol: symbol}); }
});
web3_token.name.call({from: addr}, function(err, name) {
if(name) { that.setState({token_name: name}); }
});
},
successOnBalance: function(result, args) {
......
......@@ -12,8 +12,8 @@ if (typeof web3 !== 'undefined') {
exported = new Web3(web3.currentProvider);
window.offline = false; //there is a web3 available.
var other_web3 = new Web3(new Web3.providers.HttpProvider('https://rpc.metamask.io'));
window.web_l = other_web3;
//var other_web3 = new Web3(new Web3.providers.HttpProvider('https://rpc.metamask.io'));
//window.web_l = other_web3;
} else {
// Use the provider from the config.
// ENV and WEB3_PROVIDER_LOCATION are rewritten by webpack during build
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment