From f64c17fd33b9ba09d4e6e53b3f287cb3d100dac1 Mon Sep 17 00:00:00 2001 From: Muhammad Usman Date: Tue, 9 Oct 2018 22:23:22 +0530 Subject: [PATCH] migrate gitcoin from web3js 0.2 to 1.0 --- app/assets/v2/js/shared.js | 51 +++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/app/assets/v2/js/shared.js b/app/assets/v2/js/shared.js index ad6bb829547..d21d90723bb 100644 --- a/app/assets/v2/js/shared.js +++ b/app/assets/v2/js/shared.js @@ -824,29 +824,34 @@ 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.net.getNetworkType().then(function(callback, error) { + if (error) { + currentNetwork(); + } else { + currentNetwork(callback); + trigger_form_hooks(); + } + }); + } + }); + } + /*else { + web3.eth.getBalance(web3.eth.coinbase, function(errors, result) { + if (typeof result != 'undefined') { + document.balance = result.toNumber(); + } + }); + */ } };