diff options
author | Leonid <logvinov.leon@gmail.com> | 2017-08-30 17:24:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-30 17:24:15 +0800 |
commit | 5f44b5f7111873a3958050503fff0ed098b65b04 (patch) | |
tree | f19caa7d2718c2506699e6c804ac6f837b197c5a /src | |
parent | 6e34cf2c3bdba83460fc4356ec2e62e712119ec9 (diff) | |
parent | c83e1d57fce55efe5e85221d0442d5f4c0fa0514 (diff) | |
download | dexon-sol-tools-5f44b5f7111873a3958050503fff0ed098b65b04.tar dexon-sol-tools-5f44b5f7111873a3958050503fff0ed098b65b04.tar.gz dexon-sol-tools-5f44b5f7111873a3958050503fff0ed098b65b04.tar.bz2 dexon-sol-tools-5f44b5f7111873a3958050503fff0ed098b65b04.tar.lz dexon-sol-tools-5f44b5f7111873a3958050503fff0ed098b65b04.tar.xz dexon-sol-tools-5f44b5f7111873a3958050503fff0ed098b65b04.tar.zst dexon-sol-tools-5f44b5f7111873a3958050503fff0ed098b65b04.zip |
Merge pull request #142 from 0xProject/feature/support_web3@1.0_provider
Feature/support web3@1.0 provider
Diffstat (limited to 'src')
-rw-r--r-- | src/0x.ts | 7 | ||||
-rw-r--r-- | src/globals.d.ts | 1 | ||||
-rw-r--r-- | src/utils/assert.ts | 4 |
3 files changed, 12 insertions, 0 deletions
@@ -163,6 +163,13 @@ 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 an async `send` method, instead of a `send` and `sendAsync` in web3@0.x.x` + // We re-assign the send method so that Web3@1.0 providers work with 0x.js + (provider as any).sendAsync = (provider as any).send; + } this._web3Wrapper = new Web3Wrapper(provider); const gasPrice = _.isUndefined(config) ? undefined : config.gasPrice; this.token = new TokenWrapper(this._web3Wrapper, gasPrice); diff --git a/src/globals.d.ts b/src/globals.d.ts index 1ef70d679..9230ab02d 100644 --- a/src/globals.d.ts +++ b/src/globals.d.ts @@ -1,5 +1,6 @@ /// <reference types='chai-typescript-typings' /> /// <reference types='chai-as-promised-typescript-typings' /> +declare module 'web3_beta'; declare module 'chai-bignumber'; declare module 'dirty-chai'; declare module 'request-promise-native'; 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); |