Skip to content

Commit

Permalink
Merge pull request #5113 from gitcoinco/json-sentry-undefined
Browse files Browse the repository at this point in the history
catch infura/metamask errors before they alert sentry
  • Loading branch information
thelostone-mc authored Sep 4, 2019
2 parents ff37104 + f6d6ec4 commit 185b0a5
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions app/assets/v2/js/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -923,30 +923,44 @@ 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();
}
});
}
}
}

Expand Down

0 comments on commit 185b0a5

Please sign in to comment.