Skip to content

Commit

Permalink
migrate gitcoin from web3js 0.2 to 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad Usman committed Oct 18, 2018
1 parent 13bc312 commit 84aab9e
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions app/assets/v2/js/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -824,29 +824,37 @@ var listen_for_web3_changes = function() {
document.listen_for_web3_iterations += 1;
}

if (typeof web3 == 'undefined') {
currentNetwork();
trigger_form_hooks();
} else if (typeof web3 == 'undefined' || typeof web3.eth == 'undefined' || typeof web3.eth.coinbase == 'undefined' || !web3.eth.coinbase) {
currentNetwork('locked');
trigger_form_hooks();
} else {
web3.eth.getBalance(web3.eth.coinbase, function(errors, result) {
if (typeof result != 'undefined') {
document.balance = result.toNumber();
}
});

web3.version.getNetwork(function(error, netId) {
if (error) {
currentNetwork();
} else {
var network = getNetwork(netId);

currentNetwork(network);
trigger_form_hooks();
}
});
if (typeof web3 !== 'undefined') {
if (typeof web3.currentProvider.isMetaMask == 'undefined') {
currentNetwork();
trigger_form_hooks();
} else {
web3.eth.getAccounts(function(error, accounts) {
if (accounts.length == 0) {
currentNetwork('locked');
trigger_form_hooks();
} else {
web3.eth.getCoinbase(function(error, coinbase) {
web3.eth.getBalance(coinbase, function(error, result) {
if (typeof result != 'undefined') {
document.balance = result.toNumber;
}
});
});
web3.eth.net.getNetworkType().then(function(callback, error) {
if (error) {
currentNetwork();
} else if (callback != 'private') {
currentNetwork(callback);
trigger_form_hooks();
} else {
currentNetwork('custom network');
trigger_form_hooks();
}
});
}
});
}
}
};

Expand Down

0 comments on commit 84aab9e

Please sign in to comment.