Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uport integration #62

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 46 additions & 45 deletions app/javascripts/tokenpage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,59 +39,60 @@ 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()});

//a check that if the address returns 0 here, it's either invalid or not usable and user gets notified.
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) {
Expand Down
13 changes: 6 additions & 7 deletions app/javascripts/web3_bootstrap.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"reflux-tx": "0.2.4",
"sass-loader": "^3.1.2",
"style-loader": "^0.13.0",
"uport-lib": "git+ssh://[email protected]:ConsenSys/uport-lib.git",
"web3": "0.16.0",
"webpack": "^1.12.12"
},
Expand Down