diff --git a/app/assets/v2/js/shared.js b/app/assets/v2/js/shared.js index ad6bb829547..317ca8dfc21 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.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 { + currentNetwork(callback); + trigger_form_hooks(); + } + }); + } + }); + } } };