1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

Prevent error messages on optional contracts.

This commit is contained in:
Pedro Gutiérrez 2019-06-25 12:00:22 +02:00
parent be95da79df
commit d6b601effd
3 changed files with 7 additions and 5 deletions

View File

@ -35,7 +35,7 @@ export default class ContractHandler extends Instantiable {
this.setInstanceConfig(config)
}
public async get(what: string): Promise<Contract> {
public async get(what: string, optional: boolean = false): Promise<Contract> {
const where = (await this.ocean.keeper.getNetworkName()).toLowerCase()
const networkId = await this.ocean.keeper.getNetworkId()
try {
@ -44,7 +44,9 @@ export default class ContractHandler extends Instantiable {
(await this.load(what, where, networkId))
)
} catch (err) {
this.logger.error('Failed to load', what, 'from', where, err)
if (!optional) {
this.logger.error('Failed to load', what, 'from', where, err)
}
throw err
}
}

View File

@ -14,7 +14,7 @@ export abstract class ContractBase extends Instantiable {
return this.contract.options.address
}
constructor(contractName) {
constructor(contractName, private optional: boolean = false) {
super()
this.contractName = contractName
}
@ -53,7 +53,7 @@ export abstract class ContractBase extends Instantiable {
protected async init(config: InstantiableConfig) {
this.setInstanceConfig(config)
const contractHandler = new ContractHandler(config)
this.contract = await contractHandler.get(this.contractName)
this.contract = await contractHandler.get(this.contractName, this.optional)
}
protected async getFromAddress(from?: string): Promise<string> {

View File

@ -5,7 +5,7 @@ export default class Dispenser extends ContractBase {
public static async getInstance(
config: InstantiableConfig
): Promise<Dispenser> {
const dispenser: Dispenser = new Dispenser('Dispenser')
const dispenser: Dispenser = new Dispenser('Dispenser', true)
await dispenser.init(config)
return dispenser
}