From 60ad5024ce697c043c55005ffee0ab5319fc6f45 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 30 Aug 2017 11:12:28 +0200 Subject: Add assert.isWeb3Provider --- src/0x.ts | 1 + src/utils/assert.ts | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/0x.ts b/src/0x.ts index 9613df1be..a395d6dd7 100644 --- a/src/0x.ts +++ b/src/0x.ts @@ -163,6 +163,7 @@ export class ZeroEx { * @return An instance of the 0x.js ZeroEx class. */ constructor(provider: Web3Provider, config?: ZeroExConfig) { + assert.isWeb3Provider('provider', provider); if (_.isUndefined((provider as any).sendAsync)) { // Web3@1.0 provider doesn't support synchronous http requests, // so it only has `send` method, instead of `send and `sendAsync` in web3@0.x.x diff --git a/src/utils/assert.ts b/src/utils/assert.ts index a26b19311..eb084129c 100644 --- a/src/utils/assert.ts +++ b/src/utils/assert.ts @@ -61,6 +61,10 @@ export const assert = { isBoolean(variableName: string, value: boolean): void { this.assert(_.isBoolean(value), this.typeAssertionMessage(variableName, 'boolean', value)); }, + isWeb3Provider(variableName: string, value: Web3.Provider): void { + const isWeb3Provider = _.isFunction((value as any).send) || _.isFunction((value as any).sendAsync); + this.assert(isWeb3Provider, this.typeAssertionMessage(variableName, 'Web3.Provider', value)); + }, doesConformToSchema(variableName: string, value: any, schema: Schema): void { const schemaValidator = new SchemaValidator(); const validationResult = schemaValidator.validate(value, schema); -- cgit v1.2.3