Skip to content

Commit

Permalink
try catch on listing accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
azf20 committed Mar 24, 2023
1 parent 0686ef1 commit 9d4e9e8
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions packages/react-app/src/hooks/ContractLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const loadContract = (contractName, signer) => {
const newContract = new Contract(
require(`../contracts/${contractName}.address.js`),
require(`../contracts/${contractName}.abi.js`),
signer,
signer
);
try {
newContract.bytecode = require(`../contracts/${contractName}.bytecode.js`);
Expand All @@ -43,8 +43,15 @@ export default function useContractLoader(providerOrSigner) {
// we need to check to see if this providerOrSigner has a signer or not
let signer;
let accounts;
if (providerOrSigner && typeof providerOrSigner.listAccounts === "function") {
accounts = await providerOrSigner.listAccounts();
if (
providerOrSigner &&
typeof providerOrSigner.listAccounts === "function"
) {
try {
accounts = await providerOrSigner.listAccounts();
} catch (e) {
console.log("ERROR LISTING ACCOUNTS!!", e);
}
}

if (accounts && accounts.length > 0) {
Expand All @@ -55,10 +62,13 @@ export default function useContractLoader(providerOrSigner) {

const contractList = require("../contracts/contracts.js");

const newContracts = contractList.reduce((accumulator, contractName) => {
accumulator[contractName] = loadContract(contractName, signer);
return accumulator;
}, {});
const newContracts = contractList.reduce(
(accumulator, contractName) => {
accumulator[contractName] = loadContract(contractName, signer);
return accumulator;
},
{}
);
setContracts(newContracts);
} catch (e) {
console.log("ERROR LOADING CONTRACTS!!", e);
Expand Down

0 comments on commit 9d4e9e8

Please sign in to comment.