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

Allow Disenser as optional contract.

This commit is contained in:
Pedro Gutiérrez 2019-06-25 11:12:32 +02:00
parent 13287d1706
commit be95da79df
2 changed files with 11 additions and 1 deletions

View File

@ -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

View File

@ -111,6 +111,9 @@ export default class Account extends Instantiable {
*/
public async requestTokens(amount: number | string): Promise<string> {
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) {