From be95da79df3c023a3a16afc715c928a001405514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Guti=C3=A9rrez?= Date: Tue, 25 Jun 2019 11:12:32 +0200 Subject: [PATCH] Allow Disenser as optional contract. --- src/keeper/Keeper.ts | 9 ++++++++- src/ocean/Account.ts | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/keeper/Keeper.ts b/src/keeper/Keeper.ts index 8c563a8..82164fc 100644 --- a/src/keeper/Keeper.ts +++ b/src/keeper/Keeper.ts @@ -49,7 +49,7 @@ export class Keeper extends Instantiable { try { keeper.instances = await objectPromiseAll({ // Main contracts - dispenser: Dispenser.getInstance(config), + dispenser: undefined, // Optional token: OceanToken.getInstance(config), didRegistry: DIDRegistry.getInstance(config), // Managers @@ -78,6 +78,13 @@ export class Keeper extends Instantiable { return } + // Optionals + try { + keeper.instances.dispenser = await Dispenser.getInstance(config) + } catch { + keeper.logger.warn('Dispenser not available on this network.') + } + // Main contracts keeper.dispenser = keeper.instances.dispenser keeper.token = keeper.instances.token diff --git a/src/ocean/Account.ts b/src/ocean/Account.ts index 01fbcfc..62c2d01 100644 --- a/src/ocean/Account.ts +++ b/src/ocean/Account.ts @@ -111,6 +111,9 @@ export default class Account extends Instantiable { */ public async requestTokens(amount: number | string): Promise { amount = String(amount) + if (!this.ocean.keeper.dispenser) { + throw new Error('Dispenser not available on this network.') + } try { await this.ocean.keeper.dispenser.requestTokens(amount, this.id) } catch (e) {