Skip to content

Commit

Permalink
Fix error handling issues - Issue compound-finance#65
Browse files Browse the repository at this point in the history
  • Loading branch information
0xzoz committed Mar 28, 2022
1 parent 04a029f commit b1e2aa7
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions src/js/sharedEth/eth.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,16 @@ function withWeb3Eth(eth) {
}

function withTrxWeb3(eth, fnTrxWeb3, fnEls) {
if (eth.trxEth) {
let res = fnTrxWeb3(eth.trxEth, eth.trxEth.trxPromise);
eth.trxEth.trxPromise = res;
return res;
} else {
return fnEls();
try{
if (eth.trxEth) {
let res = fnTrxWeb3(eth.trxEth, eth.trxEth.trxPromise);
eth.trxEth.trxPromise = res;
return res;
} else {
return fnEls();
}
}catch(e){
console.log(e);
}
}

Expand Down Expand Up @@ -463,11 +467,18 @@ function setNetworkId(eth, networkId) {
}

async function getNetworkId(eth) {
return withTrxWeb3(
eth,
(trxEth) => trxEth.net.getId(),
() => eth.defaultNetworkId
);
try{
let networkId = await withTrxWeb3(
eth,
(trxEth) => trxEth.net.getId(),
() => eth.defaultNetworkId
);
return networkId;
}catch(e){
console.log(e)
return eth.defaultNetworkId;

}
}

async function getBalance(eth, address) {
Expand All @@ -483,11 +494,18 @@ async function getBlockNumber(eth) {
}

async function getAccounts(eth) {
return withTrxWeb3(
eth,
(trxEth) => trxEth.getAccounts(),
() => (eth.showAccount ? [eth.showAccount] : [])
);
try{
let accs = await withTrxWeb3(
eth,
(trxEth) => trxEth.getAccounts(),
() => (eth.showAccount ? [eth.showAccount] : [])
)
return accs;

}catch(e){
console.log(e)
return [];
}
}

async function getTransaction(eth, trxHash) {
Expand Down

0 comments on commit b1e2aa7

Please sign in to comment.