Created
March 26, 2020 15:48
-
-
Save pi0neerpat/11a2a48a203172527db174a668385794 to your computer and use it in GitHub Desktop.
load wallet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async loadContracts({ | |
walletProvider, | |
contractNames, | |
allowancesRequested, | |
balancesRequested, | |
}) { | |
console.log("lol") | |
try { | |
ethers.errors.setLogLevel("error") // "debug", "default", "info", "warn", "off" | |
const loadedContracts = {} | |
const { name: networkName } = await walletProvider.getNetwork() | |
contractNames.forEach(name => { | |
loadedContracts[name] = new ethers.Contract( | |
CONTRACTS[name][networkName], | |
CONTRACTS[name].abi, | |
walletProvider.getSigner() | |
) | |
}) | |
const owner = await walletProvider | |
.listAccounts() | |
.then(accounts => accounts[0]) | |
let allowancesObj | |
if (allowancesRequested) { | |
const allowances = await this.getAllowances({ | |
contracts: loadedContracts, | |
owner, | |
allowancesRequested, | |
}) | |
allowancesObj = allowances | |
} | |
const balances = await this.getBalances({ | |
contracts: loadedContracts, | |
balancesRequested, | |
owner, | |
}) | |
// eslint-disable-next-line no-console | |
console.log( | |
`Loaded contracts ${Object.keys(loadedContracts)} on ${networkName}` | |
) | |
return { contracts: loadedContracts, allowances: allowancesObj, balances } | |
} catch (error) { | |
return this.getErrorResponse(error, "loadContracts") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment