Refactor getContractAddress to contractWrapper
This commit is contained in:
@@ -141,7 +141,7 @@ export class ContractWrapper {
|
||||
// We need to coerce to Block type cause Web3.Block includes types for mempool blocks
|
||||
if (!_.isUndefined(this._blockAndLogStreamer)) {
|
||||
// If we clear the interval while fetching the block - this._blockAndLogStreamer will be undefined
|
||||
await this._blockAndLogStreamer.reconcileNewBlock(latestBlock as any as Block);
|
||||
this._blockAndLogStreamer.reconcileNewBlock(latestBlock as any as Block);
|
||||
}
|
||||
} catch (err) {
|
||||
const filterTokens = _.keys(this._filterCallbacks);
|
||||
|
@@ -70,16 +70,10 @@ export class EtherTokenWrapper extends ContractWrapper {
|
||||
* @return The Wrapped Ether token contract address
|
||||
*/
|
||||
public getContractAddress(): string {
|
||||
const networkId = this._web3Wrapper.getNetworkId();
|
||||
if (_.isUndefined(this._contractAddressIfExists)) {
|
||||
const contractAddress = artifacts.EtherTokenArtifact.networks[networkId].address;
|
||||
if (_.isUndefined(contractAddress)) {
|
||||
throw new Error(ZeroExError.ExchangeContractDoesNotExist);
|
||||
}
|
||||
return contractAddress;
|
||||
} else {
|
||||
return this._contractAddressIfExists;
|
||||
}
|
||||
const contractAddress = this._getContractAddress(
|
||||
artifacts.EtherTokenArtifact, this._contractAddressIfExists,
|
||||
);
|
||||
return contractAddress;
|
||||
}
|
||||
private _invalidateContractInstance(): void {
|
||||
delete this._etherTokenContractIfExists;
|
||||
|
@@ -830,16 +830,10 @@ export class ExchangeWrapper extends ContractWrapper {
|
||||
* @return Address of ZRX token
|
||||
*/
|
||||
public getZRXTokenAddress(): string {
|
||||
const networkId = this._web3Wrapper.getNetworkId();
|
||||
if (_.isUndefined(this._zrxContractAddressIfExists)) {
|
||||
const zrxTokenAddress = artifacts.ZRXArtifact.networks[networkId].address;
|
||||
if (_.isUndefined(zrxTokenAddress)) {
|
||||
throw new Error(ZeroExError.ZRXContractDoesNotExist);
|
||||
}
|
||||
return zrxTokenAddress;
|
||||
} else {
|
||||
return this._zrxContractAddressIfExists;
|
||||
}
|
||||
const contractAddress = this._getContractAddress(
|
||||
artifacts.ZRXArtifact, this._zrxContractAddressIfExists,
|
||||
);
|
||||
return contractAddress;
|
||||
}
|
||||
private async _invalidateContractInstancesAsync(): Promise<void> {
|
||||
this.unsubscribeAll();
|
||||
|
@@ -104,16 +104,10 @@ export class TokenRegistryWrapper extends ContractWrapper {
|
||||
* @returns The Ethereum address of the TokenRegistry contract being used.
|
||||
*/
|
||||
public getContractAddress(): string {
|
||||
const networkId = this._web3Wrapper.getNetworkId();
|
||||
if (_.isUndefined(this._contractAddressIfExists)) {
|
||||
const contractAddress = artifacts.TokenRegistryArtifact.networks[networkId].address;
|
||||
if (_.isUndefined(contractAddress)) {
|
||||
throw new Error(ZeroExError.ExchangeContractDoesNotExist);
|
||||
}
|
||||
return contractAddress;
|
||||
} else {
|
||||
return this._contractAddressIfExists;
|
||||
}
|
||||
const contractAddress = this._getContractAddress(
|
||||
artifacts.TokenRegistryArtifact, this._contractAddressIfExists,
|
||||
);
|
||||
return contractAddress;
|
||||
}
|
||||
private _invalidateContractInstance(): void {
|
||||
delete this._tokenRegistryContractIfExists;
|
||||
|
@@ -41,16 +41,10 @@ export class TokenTransferProxyWrapper extends ContractWrapper {
|
||||
* @returns The Ethereum address of the TokenTransferProxy contract being used.
|
||||
*/
|
||||
public getContractAddress(): string {
|
||||
const networkId = this._web3Wrapper.getNetworkId();
|
||||
if (_.isUndefined(this._contractAddressIfExists)) {
|
||||
const contractAddress = artifacts.TokenTransferProxyArtifact.networks[networkId].address;
|
||||
if (_.isUndefined(contractAddress)) {
|
||||
throw new Error(ZeroExError.ExchangeContractDoesNotExist);
|
||||
}
|
||||
return contractAddress;
|
||||
} else {
|
||||
return this._contractAddressIfExists;
|
||||
}
|
||||
const contractAddress = this._getContractAddress(
|
||||
artifacts.TokenTransferProxyArtifact, this._contractAddressIfExists,
|
||||
);
|
||||
return contractAddress;
|
||||
}
|
||||
private _invalidateContractInstance(): void {
|
||||
delete this._tokenTransferProxyContractIfExists;
|
||||
|
Reference in New Issue
Block a user