diff options
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | src/0x.ts | 14 | ||||
-rw-r--r-- | src/index.ts | 1 | ||||
-rw-r--r-- | src/types.ts | 7 | ||||
-rw-r--r-- | src/web3_wrapper.ts | 6 | ||||
-rw-r--r-- | test/0x.js_test.ts | 8 | ||||
-rw-r--r-- | test/assert_test.ts | 2 | ||||
-rw-r--r-- | test/exchange_wrapper_test.ts | 2 | ||||
-rw-r--r-- | test/token_registry_wrapper_test.ts | 2 | ||||
-rw-r--r-- | test/token_wrapper_test.ts | 2 | ||||
-rw-r--r-- | yarn.lock | 6 |
11 files changed, 29 insertions, 23 deletions
diff --git a/package.json b/package.json index 386a2e232..bd077ad30 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,7 @@ "typedoc": "^0.7.1", "typescript": "^2.3.3", "web3-provider-engine": "^13.0.1", - "web3-typescript-typings": "0.0.8", + "web3-typescript-typings": "^0.0.9", "webpack": "^2.6.0" }, "dependencies": { @@ -14,7 +14,7 @@ import {ExchangeWrapper} from './contract_wrappers/exchange_wrapper'; import {TokenRegistryWrapper} from './contract_wrappers/token_registry_wrapper'; import {ecSignatureSchema} from './schemas/ec_signature_schema'; import {TokenWrapper} from './contract_wrappers/token_wrapper'; -import {ECSignature, ZeroExError, Order, SignedOrder} from './types'; +import {ECSignature, ZeroExError, Order, SignedOrder, Web3Provider} from './types'; import * as ExchangeArtifacts from './artifacts/Exchange.json'; import {orderSchema} from './schemas/order_schemas'; @@ -122,12 +122,12 @@ export class ZeroEx { } /** * Instantiates a new ZeroEx instance that provides the public interface to the 0x.js library. - * @param web3 The Web3.js instance you would like the 0x.js library to use for interacting with - * the Ethereum network. + * @param provider The Web3.js Provider instance you would like the 0x.js library to use for interacting with + * the Ethereum network. * @return An instance of the 0x.js ZeroEx class. */ - constructor(web3: Web3) { - this._web3Wrapper = new Web3Wrapper(web3); + constructor(provider: Web3Provider) { + this._web3Wrapper = new Web3Wrapper(provider); this.token = new TokenWrapper(this._web3Wrapper); this.exchange = new ExchangeWrapper(this._web3Wrapper, this.token); this.tokenRegistry = new TokenRegistryWrapper(this._web3Wrapper); @@ -135,9 +135,9 @@ export class ZeroEx { /** * Sets a new provider for the web3 instance used by 0x.js. Updating the provider will stop all * subscriptions so you will need to re-subscribe to all events relevant to your app after this call. - * @param provider The Web3.Provider you would like the 0x.js library to use from now on. + * @param provider The Web3Provider you would like the 0x.js library to use from now on. */ - public async setProviderAsync(provider: Web3.Provider) { + public async setProviderAsync(provider: Web3Provider) { this._web3Wrapper.setProvider(provider); await this.exchange.invalidateContractInstanceAsync(); this.tokenRegistry.invalidateContractInstance(); diff --git a/src/index.ts b/src/index.ts index 48e83fc19..7b1a16125 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,4 +19,5 @@ export { OrderCancellationRequest, OrderFillRequest, ContractEventEmitter, + Web3Provider, } from './types'; diff --git a/src/types.ts b/src/types.ts index 11d3182d8..5be64da53 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,5 @@ import * as _ from 'lodash'; +import * as Web3 from 'web3'; // Utility function to create a K:V from a list of strings // Adapted from: https://basarat.gitbooks.io/typescript/content/docs/types/literal-types.html @@ -280,3 +281,9 @@ export interface ContractEventEmitter { watch: (eventCallback: EventCallback) => void; stopWatchingAsync: () => Promise<void>; } +/** + * We re-export the `Web3.Provider` type specified in the Web3 Typescript typings + * since it is the type of the `provider` argument to the `ZeroEx` constructor. + * It is however a `Web3` library type, not a native `0x.js` type. + */ +export type Web3Provider = Web3.Provider; diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts index 05a8dc063..6bdca499f 100644 --- a/src/web3_wrapper.ts +++ b/src/web3_wrapper.ts @@ -2,14 +2,12 @@ import * as _ from 'lodash'; import * as Web3 from 'web3'; import * as BigNumber from 'bignumber.js'; import promisify = require('es6-promisify'); -import {ZeroExError} from './types'; -import {assert} from './utils/assert'; export class Web3Wrapper { private web3: Web3; - constructor(web3: Web3) { + constructor(provider: Web3.Provider) { this.web3 = new Web3(); - this.web3.setProvider(web3.currentProvider); + this.web3.setProvider(provider); } public setProvider(provider: Web3.Provider) { this.web3.setProvider(provider); diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index 58f5c8533..9ec0a0c8e 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -15,7 +15,7 @@ describe('ZeroEx library', () => { describe('#setProvider', () => { it('overrides provider in nested web3s and invalidates contractInstances', async () => { const web3 = web3Factory.create(); - const zeroEx = new ZeroEx(web3); + const zeroEx = new ZeroEx(web3.currentProvider); // Instantiate the contract instances with the current provider await (zeroEx.exchange as any)._getExchangeContractAsync(); await (zeroEx.tokenRegistry as any)._getTokenRegistryContractAsync(); @@ -51,7 +51,7 @@ describe('ZeroEx library', () => { }; const address = '0x5409ed021d9299bf6814279a6a1411a7e866a631'; const web3 = web3Factory.create(); - const zeroEx = new ZeroEx(web3); + const zeroEx = new ZeroEx(web3.currentProvider); it('should return false if the data doesn\'t pertain to the signature & address', async () => { expect(ZeroEx.isValidSignature('0x0', signature, address)).to.be.false(); return expect( @@ -149,7 +149,7 @@ describe('ZeroEx library', () => { }); it('calculates the order hash', async () => { const web3 = web3Factory.create(); - const zeroEx = new ZeroEx(web3); + const zeroEx = new ZeroEx(web3.currentProvider); stubs = [ Sinon.stub((zeroEx as any), '_getExchangeAddressAsync') @@ -164,7 +164,7 @@ describe('ZeroEx library', () => { let stubs: Sinon.SinonStub[] = []; let makerAddress: string; const web3 = web3Factory.create(); - const zeroEx = new ZeroEx(web3); + const zeroEx = new ZeroEx(web3.currentProvider); before(async () => { const availableAddreses = await zeroEx.getAvailableAddressesAsync(); makerAddress = availableAddreses[0]; diff --git a/test/assert_test.ts b/test/assert_test.ts index 25d9a8d16..6a8d30716 100644 --- a/test/assert_test.ts +++ b/test/assert_test.ts @@ -8,7 +8,7 @@ const expect = chai.expect; describe('Assertion library', () => { const web3 = web3Factory.create(); - const zeroEx = new ZeroEx(web3); + const zeroEx = new ZeroEx(web3.currentProvider); describe('#isSenderAddressHexAsync', () => { it('throws when address is invalid', async () => { const address = '0xdeadbeef'; diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index 28a5c719e..e4b2e3f86 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -39,7 +39,7 @@ describe('ExchangeWrapper', () => { let fillScenarios: FillScenarios; before(async () => { web3 = web3Factory.create(); - zeroEx = new ZeroEx(web3); + zeroEx = new ZeroEx(web3.currentProvider); userAddresses = await promisify(web3.eth.getAccounts)(); tokens = await zeroEx.tokenRegistry.getTokensAsync(); tokenUtils = new TokenUtils(tokens); diff --git a/test/token_registry_wrapper_test.ts b/test/token_registry_wrapper_test.ts index 158a02596..da436161c 100644 --- a/test/token_registry_wrapper_test.ts +++ b/test/token_registry_wrapper_test.ts @@ -18,7 +18,7 @@ describe('TokenRegistryWrapper', () => { let zeroEx: ZeroEx; before(async () => { const web3 = web3Factory.create(); - zeroEx = new ZeroEx(web3); + zeroEx = new ZeroEx(web3.currentProvider); }); beforeEach(async () => { await blockchainLifecycle.startAsync(); diff --git a/test/token_wrapper_test.ts b/test/token_wrapper_test.ts index 308d3b634..a1c035672 100644 --- a/test/token_wrapper_test.ts +++ b/test/token_wrapper_test.ts @@ -21,7 +21,7 @@ describe('TokenWrapper', () => { let addressWithoutFunds: string; before(async () => { web3 = web3Factory.create(); - zeroEx = new ZeroEx(web3); + zeroEx = new ZeroEx(web3.currentProvider); userAddresses = await promisify(web3.eth.getAccounts)(); tokens = await zeroEx.tokenRegistry.getTokensAsync(); coinbase = userAddresses[0]; @@ -4467,9 +4467,9 @@ web3-provider-engine@~8.1.0: xhr "^2.2.0" xtend "^4.0.1" -web3-typescript-typings@0.0.8: - version "0.0.8" - resolved "https://registry.yarnpkg.com/web3-typescript-typings/-/web3-typescript-typings-0.0.8.tgz#96997eeaf670fbaaf28d8814a1c27dce1a07df66" +web3-typescript-typings@^0.0.9: + version "0.0.9" + resolved "https://registry.yarnpkg.com/web3-typescript-typings/-/web3-typescript-typings-0.0.9.tgz#f0c9e9bfcf0effaf16f3498b3d3883686451428b" dependencies: bignumber.js "^4.0.2" |