From df1a8d8ea09cc344fd632dcfbad1147f66ad1fc7 Mon Sep 17 00:00:00 2001 From: Dan Lipert Date: Sun, 1 Sep 2019 20:13:02 +0900 Subject: [PATCH 1/2] catch infura/metamask error --- app/assets/v2/js/shared.js | 51 ++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/app/assets/v2/js/shared.js b/app/assets/v2/js/shared.js index 4d3cf469501..35768564aab 100644 --- a/app/assets/v2/js/shared.js +++ b/app/assets/v2/js/shared.js @@ -923,30 +923,43 @@ var listen_for_web3_changes = async function() { 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) { + } else if (typeof web3.eth == 'undefined') { currentNetwork('locked'); trigger_form_hooks(); } else { - is_metamask_unlocked = true; - web3.eth.getBalance(web3.eth.coinbase, function(errors, result) { - if (errors) { - return; - } - if (typeof result != 'undefined' && result !== null) { - document.balance = result.toNumber(); - } - }); + var cb; + try { + // invoke infura synchronous call, if it fails metamask is locked + cb = web3.eth.coinbase; + } catch (error) { + // catch error so sentry doesn't alert on metamask call failure + console.log('web3.eth.coinbase could not be loaded'); + } + if (typeof cb == 'undefined' || !cb) { + currentNetwork('locked'); + trigger_form_hooks(); + } else { + is_metamask_unlocked = true; + web3.eth.getBalance(web3.eth.coinbase, function(errors, result) { + if (errors) { + return; + } + if (typeof result != 'undefined' && result !== null) { + document.balance = result.toNumber(); + } + }); - web3.version.getNetwork(function(error, netId) { - if (error) { - currentNetwork(); - } else { - var network = getNetwork(netId); + web3.version.getNetwork(function(error, netId) { + if (error) { + currentNetwork(); + } else { + var network = getNetwork(netId); - currentNetwork(network); - trigger_form_hooks(); - } - }); + currentNetwork(network); + trigger_form_hooks(); + } + }); + } } } From 848cfafc7813a0c8824af412ed6e56e874423bbc Mon Sep 17 00:00:00 2001 From: Dan Lipert Date: Wed, 4 Sep 2019 23:06:00 +0900 Subject: [PATCH 2/2] fix linting --- app/assets/v2/js/shared.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/assets/v2/js/shared.js b/app/assets/v2/js/shared.js index 35768564aab..a22446e83fa 100644 --- a/app/assets/v2/js/shared.js +++ b/app/assets/v2/js/shared.js @@ -928,6 +928,7 @@ var listen_for_web3_changes = async function() { trigger_form_hooks(); } else { var cb; + try { // invoke infura synchronous call, if it fails metamask is locked cb = web3.eth.coinbase; @@ -936,8 +937,8 @@ var listen_for_web3_changes = async function() { console.log('web3.eth.coinbase could not be loaded'); } if (typeof cb == 'undefined' || !cb) { - currentNetwork('locked'); - trigger_form_hooks(); + currentNetwork('locked'); + trigger_form_hooks(); } else { is_metamask_unlocked = true; web3.eth.getBalance(web3.eth.coinbase, function(errors, result) {