diff --git a/app/javascripts/tokenpage.jsx b/app/javascripts/tokenpage.jsx index b0e3731..314a713 100644 --- a/app/javascripts/tokenpage.jsx +++ b/app/javascripts/tokenpage.jsx @@ -39,9 +39,9 @@ var TokenPage = React.createClass({ this.setState({web3_token: web3_token}); var that = this; - var accounts = web3.eth.accounts; //get Metamask/Mist address - var addr = accounts[0]; //first account in metamask is one that's active. Might have to swop/change for Mist in the future. - web3_token.totalSupply.call({from: addr}, function(err, totalSupply) { + web3.eth.getAccounts(function (err, accounts) { //get Metamask/Mist address + var addr = accounts[0]; //first account in metamask is one that's active. Might have to swop/change for Mist in the future. + web3_token.totalSupply.call({from: addr}, function(err, totalSupply) { console.log(totalSupply); that.setState({totalSupply: totalSupply.toString()}); @@ -49,49 +49,50 @@ var TokenPage = React.createClass({ if(totalSupply.toString() === "0") { that.setState({valid: false}); } - }); + }); + + that.setState({current_user_address: addr}); + + //totalSupply is currently used to check if legitimate ERC20. + //optionals currently are the vanity vars: decimals, symbol and name. + //the token can still work, thus if not present they aren't currently shown or added to the UI. + + //decimals() signature: 0x313ce567 + //name() signature: 0x06fdde03 + //symbol() signature: 0x95d89b41 + var decimals_sig = "13ce567"; + var name_sig = "06fdde03"; + var symbol_sig = "95d89b41"; + - that.setState({current_user_address: addr}); - - //totalSupply is currently used to check if legitimate ERC20. - //optionals currently are the vanity vars: decimals, symbol and name. - //the token can still work, thus if not present they aren't currently shown or added to the UI. - - //decimals() signature: 0x313ce567 - //name() signature: 0x06fdde03 - //symbol() signature: 0x95d89b41 - var decimals_sig = "13ce567"; - var name_sig = "06fdde03"; - var symbol_sig = "95d89b41"; - - - web3.eth.getCode(this.props.params.contract_address, function(err, result) { - //console.log(result); - - if(result.indexOf(decimals_sig) >= 0) { - console.log("decimals present"); - web3_token.decimals.call({from: addr}, function(err, decimals) { - //ABI will force it to expect BigNumber. - //because it throws via fallback function if not present, it gets back 0. - if(err) { console.log(err); } - if(decimals) { console.log(decimals); that.setState({token_decimals: decimals}); } - }); - } - if(result.indexOf(name_sig) >= 0) { - console.log("name present"); - web3_token.name.call({from: addr}, function(err, name) { - if(err) { console.log(err); } - if(name) { console.log(name); that.setState({token_name: name}); } - }); - } - if(result.indexOf(symbol_sig) >= 0) { - console.log("symbol present"); - web3_token.symbol.call({from: addr}, function(err, symbol) { - //ABI expects string here, - if(err) { console.log(err); } - if(symbol) { console.log(symbol); that.setState({token_symbol: symbol}); } - }); - } + web3.eth.getCode(that.props.params.contract_address, function(err, result) { + //console.log(result); + + if(result.indexOf(decimals_sig) >= 0) { + console.log("decimals present"); + web3_token.decimals.call({from: addr}, function(err, decimals) { + //ABI will force it to expect BigNumber. + //because it throws via fallback function if not present, it gets back 0. + if(err) { console.log(err); } + if(decimals) { console.log(decimals); that.setState({token_decimals: decimals}); } + }); + } + if(result.indexOf(name_sig) >= 0) { + console.log("name present"); + web3_token.name.call({from: addr}, function(err, name) { + if(err) { console.log(err); } + if(name) { console.log(name); that.setState({token_name: name}); } + }); + } + if(result.indexOf(symbol_sig) >= 0) { + console.log("symbol present"); + web3_token.symbol.call({from: addr}, function(err, symbol) { + //ABI expects string here, + if(err) { console.log(err); } + if(symbol) { console.log(symbol); that.setState({token_symbol: symbol}); } + }); + } + }); }); }, successOnBalance: function(result, args) { diff --git a/app/javascripts/web3_bootstrap.js b/app/javascripts/web3_bootstrap.js index 9331ae1..057c668 100644 --- a/app/javascripts/web3_bootstrap.js +++ b/app/javascripts/web3_bootstrap.js @@ -1,6 +1,7 @@ //for Mist & Metamask support var Web3 = require("web3"); var Pudding = require("ether-pudding"); +var uportLib = require('uport-lib'); var exported_web3 = null; window.offline = true; //default is there is no web3 available. @@ -13,13 +14,11 @@ if (typeof web3 !== 'undefined') { window.offline = false; //there is a web3 available. } else { - - console.log("A web3 provider is NOT present. Telling user to get one."); - console.log("For now. NOT connected to a localhost."); - console.log("THUS. Offline flag remains TRUE."); - - //ONLY set web3 for its functions, not for its connection - exported_web3 = new Web3(); + // Use uPort if MetaMask is not available + var uport = new uportLib("Token Factory"); + var uportProvider = uport.getUportProvider(); + exported_web3 = new Web3(uportProvider); + window.offline = false; } Pudding.setWeb3(exported_web3); //Pudding requires a web3 connection diff --git a/package.json b/package.json index 890362b..16e7df5 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "reflux-tx": "0.2.4", "sass-loader": "^3.1.2", "style-loader": "^0.13.0", + "uport-lib": "git+ssh://git@github.com:ConsenSys/uport-lib.git", "web3": "0.16.0", "webpack": "^1.12.12" },