From 6db0b2e39821f27f6f31a8247159864dacd1d2bd Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Fri, 9 Mar 2018 15:47:21 -0800 Subject: Address feedback and lint --- packages/contracts/src/utils/exchange_wrapper.ts | 94 ++++-------------------- 1 file changed, 15 insertions(+), 79 deletions(-) (limited to 'packages/contracts/src/utils/exchange_wrapper.ts') diff --git a/packages/contracts/src/utils/exchange_wrapper.ts b/packages/contracts/src/utils/exchange_wrapper.ts index b53519871..5996867cb 100644 --- a/packages/contracts/src/utils/exchange_wrapper.ts +++ b/packages/contracts/src/utils/exchange_wrapper.ts @@ -31,13 +31,7 @@ export class ExchangeWrapper { params.signature, { from }, ); - const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); - tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address); - tx.logs = _.map(tx.logs, log => { - const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log); - wrapLogBigNumbers(logWithDecodedArgs); - return logWithDecodedArgs; - }); + const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash); return tx; } public async cancelOrderAsync( @@ -51,13 +45,7 @@ export class ExchangeWrapper { params.takerTokenCancelAmount, { from }, ); - const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); - tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address); - tx.logs = _.map(tx.logs, log => { - const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log); - wrapLogBigNumbers(logWithDecodedArgs); - return logWithDecodedArgs; - }); + const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash); return tx; } public async fillOrKillOrderAsync( @@ -72,13 +60,7 @@ export class ExchangeWrapper { params.signature, { from }, ); - const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); - tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address); - tx.logs = _.map(tx.logs, log => { - const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log); - wrapLogBigNumbers(logWithDecodedArgs); - return logWithDecodedArgs; - }); + const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash); return tx; } public async fillOrderNoThrowAsync( @@ -93,13 +75,7 @@ export class ExchangeWrapper { params.signature, { from }, ); - const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); - tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address); - tx.logs = _.map(tx.logs, log => { - const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log); - wrapLogBigNumbers(logWithDecodedArgs); - return logWithDecodedArgs; - }); + const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash); return tx; } public async batchFillOrdersAsync( @@ -114,13 +90,7 @@ export class ExchangeWrapper { params.signatures, { from }, ); - const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); - tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address); - tx.logs = _.map(tx.logs, log => { - const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log); - wrapLogBigNumbers(logWithDecodedArgs); - return logWithDecodedArgs; - }); + const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash); return tx; } public async batchFillOrKillOrdersAsync( @@ -135,13 +105,7 @@ export class ExchangeWrapper { params.signatures, { from }, ); - const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); - tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address); - tx.logs = _.map(tx.logs, log => { - const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log); - wrapLogBigNumbers(logWithDecodedArgs); - return logWithDecodedArgs; - }); + const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash); return tx; } public async batchFillOrdersNoThrowAsync( @@ -156,13 +120,7 @@ export class ExchangeWrapper { params.signatures, { from }, ); - const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); - tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address); - tx.logs = _.map(tx.logs, log => { - const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log); - wrapLogBigNumbers(logWithDecodedArgs); - return logWithDecodedArgs; - }); + const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash); return tx; } public async marketFillOrdersAsync( @@ -177,13 +135,7 @@ export class ExchangeWrapper { params.signatures, { from }, ); - const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); - tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address); - tx.logs = _.map(tx.logs, log => { - const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log); - wrapLogBigNumbers(logWithDecodedArgs); - return logWithDecodedArgs; - }); + const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash); return tx; } public async marketFillOrdersNoThrowAsync( @@ -198,13 +150,7 @@ export class ExchangeWrapper { params.signatures, { from }, ); - const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); - tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address); - tx.logs = _.map(tx.logs, log => { - const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log); - wrapLogBigNumbers(logWithDecodedArgs); - return logWithDecodedArgs; - }); + const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash); return tx; } public async batchCancelOrdersAsync( @@ -218,13 +164,7 @@ export class ExchangeWrapper { params.takerTokenCancelAmounts, { from }, ); - const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); - tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address); - tx.logs = _.map(tx.logs, log => { - const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log); - wrapLogBigNumbers(logWithDecodedArgs); - return logWithDecodedArgs; - }); + const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash); return tx; } public async getOrderHashAsync(signedOrder: SignedOrder): Promise { @@ -262,14 +202,10 @@ export class ExchangeWrapper { const filledAmount = new BigNumber(await this._exchange.filled.callAsync(orderHashHex)); return filledAmount; } -} - -function wrapLogBigNumbers(log: any): any { - const argNames = _.keys(log.args); - for (const argName of argNames) { - const isWeb3BigNumber = _.startsWith(log.args[argName].constructor.toString(), 'function BigNumber('); - if (isWeb3BigNumber) { - log.args[argName] = new BigNumber(log.args[argName]); - } + private async _getTxWithDecodedExchangeLogsAsync(txHash: string) { + const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); + tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address); + tx.logs = _.map(tx.logs, log => this._logDecoder.decodeLogOrThrow(log)); + return tx; } } -- cgit