Pass networkId on provider update
This commit is contained in:
@@ -205,12 +205,13 @@ export class ZeroEx {
|
|||||||
* Sets a new web3 provider for 0x.js. Updating the provider will stop all
|
* 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.
|
* 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 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) {
|
public setProvider(provider: Web3Provider, networkId: number): void {
|
||||||
this._web3Wrapper.setProvider(provider);
|
this._web3Wrapper.setProvider(provider, networkId);
|
||||||
await (this.exchange as any)._invalidateContractInstancesAsync();
|
(this.exchange as any)._invalidateContractInstances();
|
||||||
(this.tokenRegistry as any)._invalidateContractInstance();
|
(this.tokenRegistry as any)._invalidateContractInstance();
|
||||||
await (this.token as any)._invalidateContractInstancesAsync();
|
(this.token as any)._invalidateContractInstances();
|
||||||
(this.proxy as any)._invalidateContractInstance();
|
(this.proxy as any)._invalidateContractInstance();
|
||||||
(this.etherToken as any)._invalidateContractInstance();
|
(this.etherToken as any)._invalidateContractInstance();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -827,7 +827,7 @@ export class ExchangeWrapper extends ContractWrapper {
|
|||||||
);
|
);
|
||||||
return contractAddress;
|
return contractAddress;
|
||||||
}
|
}
|
||||||
private async _invalidateContractInstancesAsync(): Promise<void> {
|
private _invalidateContractInstances(): void {
|
||||||
this.unsubscribeAll();
|
this.unsubscribeAll();
|
||||||
delete this._exchangeContractIfExists;
|
delete this._exchangeContractIfExists;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -293,7 +293,7 @@ export class TokenWrapper extends ContractWrapper {
|
|||||||
);
|
);
|
||||||
return logs;
|
return logs;
|
||||||
}
|
}
|
||||||
private _invalidateContractInstancesAsync(): void {
|
private _invalidateContractInstances(): void {
|
||||||
this.unsubscribeAll();
|
this.unsubscribeAll();
|
||||||
this._tokenContractsByAddress = {};
|
this._tokenContractsByAddress = {};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ export class Web3Wrapper {
|
|||||||
private web3: Web3;
|
private web3: Web3;
|
||||||
private networkId: number;
|
private networkId: number;
|
||||||
private defaults: Partial<Web3.TxData>;
|
private defaults: Partial<Web3.TxData>;
|
||||||
private networkIdIfExists?: number;
|
|
||||||
private jsonRpcRequestId: number;
|
private jsonRpcRequestId: number;
|
||||||
constructor(provider: Web3.Provider, networkId: number, defaults?: Partial<Web3.TxData>) {
|
constructor(provider: Web3.Provider, networkId: number, defaults?: Partial<Web3.TxData>) {
|
||||||
if (_.isUndefined((provider as any).sendAsync)) {
|
if (_.isUndefined((provider as any).sendAsync)) {
|
||||||
@@ -36,8 +35,8 @@ export class Web3Wrapper {
|
|||||||
this.defaults = defaults || {};
|
this.defaults = defaults || {};
|
||||||
this.jsonRpcRequestId = 0;
|
this.jsonRpcRequestId = 0;
|
||||||
}
|
}
|
||||||
public setProvider(provider: Web3.Provider) {
|
public setProvider(provider: Web3.Provider, networkId: number) {
|
||||||
delete this.networkIdIfExists;
|
this.networkId = networkId;
|
||||||
this.web3.setProvider(provider);
|
this.web3.setProvider(provider);
|
||||||
}
|
}
|
||||||
public isAddress(address: string): boolean {
|
public isAddress(address: string): boolean {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ describe('ZeroEx library', () => {
|
|||||||
const newProvider = web3Factory.getRpcProvider();
|
const newProvider = web3Factory.getRpcProvider();
|
||||||
// Add property to newProvider so that we can differentiate it from old provider
|
// Add property to newProvider so that we can differentiate it from old provider
|
||||||
(newProvider as any).zeroExTestId = 1;
|
(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
|
// Check that contractInstances with old provider are removed after provider update
|
||||||
expect((zeroEx.exchange as any)._exchangeContractIfExists).to.be.undefined();
|
expect((zeroEx.exchange as any)._exchangeContractIfExists).to.be.undefined();
|
||||||
|
|||||||
@@ -691,7 +691,7 @@ describe('ExchangeWrapper', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const newProvider = web3Factory.getRpcProvider();
|
const newProvider = web3Factory.getRpcProvider();
|
||||||
await zeroEx.setProviderAsync(newProvider);
|
zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID);
|
||||||
|
|
||||||
const callback = (err: Error, logEvent: DecodedLogEvent<LogFillContractEventArgs>) => {
|
const callback = (err: Error, logEvent: DecodedLogEvent<LogFillContractEventArgs>) => {
|
||||||
expect(logEvent.log.event).to.be.equal(ExchangeEvents.LogFill);
|
expect(logEvent.log.event).to.be.equal(ExchangeEvents.LogFill);
|
||||||
|
|||||||
@@ -410,7 +410,7 @@ describe('TokenWrapper', () => {
|
|||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
const newProvider = web3Factory.getRpcProvider();
|
const newProvider = web3Factory.getRpcProvider();
|
||||||
await zeroEx.setProviderAsync(newProvider);
|
zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID);
|
||||||
zeroEx.token.subscribe(
|
zeroEx.token.subscribe(
|
||||||
tokenAddress, TokenEvents.Transfer, indexFilterValues, callbackToBeCalled,
|
tokenAddress, TokenEvents.Transfer, indexFilterValues, callbackToBeCalled,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user