diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-11-24 03:56:28 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-11-24 05:15:47 +0800 |
commit | 062f85e5069d0c2d56cd10bdb8a31a6d0a6c88dc (patch) | |
tree | 26223d066ed15aec3e50eca1ecb4da0fa649cef7 /packages/0x.js | |
parent | b3c0d54acd1f4853f3b9dfbcf68bc90d17d586e0 (diff) | |
download | dexon-sol-tools-062f85e5069d0c2d56cd10bdb8a31a6d0a6c88dc.tar dexon-sol-tools-062f85e5069d0c2d56cd10bdb8a31a6d0a6c88dc.tar.gz dexon-sol-tools-062f85e5069d0c2d56cd10bdb8a31a6d0a6c88dc.tar.bz2 dexon-sol-tools-062f85e5069d0c2d56cd10bdb8a31a6d0a6c88dc.tar.lz dexon-sol-tools-062f85e5069d0c2d56cd10bdb8a31a6d0a6c88dc.tar.xz dexon-sol-tools-062f85e5069d0c2d56cd10bdb8a31a6d0a6c88dc.tar.zst dexon-sol-tools-062f85e5069d0c2d56cd10bdb8a31a6d0a6c88dc.zip |
Pass networkId on provider update
Diffstat (limited to 'packages/0x.js')
-rw-r--r-- | packages/0x.js/src/0x.ts | 9 | ||||
-rw-r--r-- | packages/0x.js/src/contract_wrappers/exchange_wrapper.ts | 2 | ||||
-rw-r--r-- | packages/0x.js/src/contract_wrappers/token_wrapper.ts | 2 | ||||
-rw-r--r-- | packages/0x.js/src/web3_wrapper.ts | 5 | ||||
-rw-r--r-- | packages/0x.js/test/0x.js_test.ts | 2 | ||||
-rw-r--r-- | packages/0x.js/test/exchange_wrapper_test.ts | 2 | ||||
-rw-r--r-- | packages/0x.js/test/token_wrapper_test.ts | 2 |
7 files changed, 12 insertions, 12 deletions
diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts index 3dc98d5da..0616b3078 100644 --- a/packages/0x.js/src/0x.ts +++ b/packages/0x.js/src/0x.ts @@ -205,12 +205,13 @@ export class ZeroEx { * Sets a new web3 provider for 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 Web3Provider you would like the 0x.js library to use from now on. + * @param networkId The id of the network your provider is connected to */ - public async setProviderAsync(provider: Web3Provider) { - this._web3Wrapper.setProvider(provider); - await (this.exchange as any)._invalidateContractInstancesAsync(); + public setProvider(provider: Web3Provider, networkId: number): void { + this._web3Wrapper.setProvider(provider, networkId); + (this.exchange as any)._invalidateContractInstances(); (this.tokenRegistry as any)._invalidateContractInstance(); - await (this.token as any)._invalidateContractInstancesAsync(); + (this.token as any)._invalidateContractInstances(); (this.proxy as any)._invalidateContractInstance(); (this.etherToken as any)._invalidateContractInstance(); } diff --git a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts index 637c27361..1ff9ace3b 100644 --- a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts @@ -827,7 +827,7 @@ export class ExchangeWrapper extends ContractWrapper { ); return contractAddress; } - private async _invalidateContractInstancesAsync(): Promise<void> { + private _invalidateContractInstances(): void { this.unsubscribeAll(); delete this._exchangeContractIfExists; } diff --git a/packages/0x.js/src/contract_wrappers/token_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_wrapper.ts index cd1104580..5c6cfeaed 100644 --- a/packages/0x.js/src/contract_wrappers/token_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/token_wrapper.ts @@ -293,7 +293,7 @@ export class TokenWrapper extends ContractWrapper { ); return logs; } - private _invalidateContractInstancesAsync(): void { + private _invalidateContractInstances(): void { this.unsubscribeAll(); this._tokenContractsByAddress = {}; } diff --git a/packages/0x.js/src/web3_wrapper.ts b/packages/0x.js/src/web3_wrapper.ts index 00f91106b..557cd28e5 100644 --- a/packages/0x.js/src/web3_wrapper.ts +++ b/packages/0x.js/src/web3_wrapper.ts @@ -21,7 +21,6 @@ export class Web3Wrapper { private web3: Web3; private networkId: number; private defaults: Partial<Web3.TxData>; - private networkIdIfExists?: number; private jsonRpcRequestId: number; constructor(provider: Web3.Provider, networkId: number, defaults?: Partial<Web3.TxData>) { if (_.isUndefined((provider as any).sendAsync)) { @@ -36,8 +35,8 @@ export class Web3Wrapper { this.defaults = defaults || {}; this.jsonRpcRequestId = 0; } - public setProvider(provider: Web3.Provider) { - delete this.networkIdIfExists; + public setProvider(provider: Web3.Provider, networkId: number) { + this.networkId = networkId; this.web3.setProvider(provider); } public isAddress(address: string): boolean { diff --git a/packages/0x.js/test/0x.js_test.ts b/packages/0x.js/test/0x.js_test.ts index cb4753248..6b7a70699 100644 --- a/packages/0x.js/test/0x.js_test.ts +++ b/packages/0x.js/test/0x.js_test.ts @@ -33,7 +33,7 @@ describe('ZeroEx library', () => { const newProvider = web3Factory.getRpcProvider(); // Add property to newProvider so that we can differentiate it from old provider (newProvider as any).zeroExTestId = 1; - await zeroEx.setProviderAsync(newProvider); + zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID); // Check that contractInstances with old provider are removed after provider update expect((zeroEx.exchange as any)._exchangeContractIfExists).to.be.undefined(); diff --git a/packages/0x.js/test/exchange_wrapper_test.ts b/packages/0x.js/test/exchange_wrapper_test.ts index 43dfeb425..6fe52a75a 100644 --- a/packages/0x.js/test/exchange_wrapper_test.ts +++ b/packages/0x.js/test/exchange_wrapper_test.ts @@ -691,7 +691,7 @@ describe('ExchangeWrapper', () => { ); const newProvider = web3Factory.getRpcProvider(); - await zeroEx.setProviderAsync(newProvider); + zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID); const callback = (err: Error, logEvent: DecodedLogEvent<LogFillContractEventArgs>) => { expect(logEvent.log.event).to.be.equal(ExchangeEvents.LogFill); diff --git a/packages/0x.js/test/token_wrapper_test.ts b/packages/0x.js/test/token_wrapper_test.ts index 49af19a25..abd4243c3 100644 --- a/packages/0x.js/test/token_wrapper_test.ts +++ b/packages/0x.js/test/token_wrapper_test.ts @@ -410,7 +410,7 @@ describe('TokenWrapper', () => { done(); }; const newProvider = web3Factory.getRpcProvider(); - await zeroEx.setProviderAsync(newProvider); + zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID); zeroEx.token.subscribe( tokenAddress, TokenEvents.Transfer, indexFilterValues, callbackToBeCalled, ); |