aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-watcher/src
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2019-01-05 06:31:25 +0800
committerAmir Bandeali <abandeali1@gmail.com>2019-01-08 02:31:11 +0800
commit24564b986daa703f66e54f85abf4782d99a40f94 (patch)
tree8fbe8caa669b773eafe10c68c5a1a8a08c4954c5 /packages/order-watcher/src
parenta91bc415ed3c9dc94dda2661c0d7ac13bcc58e08 (diff)
downloaddexon-sol-tools-24564b986daa703f66e54f85abf4782d99a40f94.tar
dexon-sol-tools-24564b986daa703f66e54f85abf4782d99a40f94.tar.gz
dexon-sol-tools-24564b986daa703f66e54f85abf4782d99a40f94.tar.bz2
dexon-sol-tools-24564b986daa703f66e54f85abf4782d99a40f94.tar.lz
dexon-sol-tools-24564b986daa703f66e54f85abf4782d99a40f94.tar.xz
dexon-sol-tools-24564b986daa703f66e54f85abf4782d99a40f94.tar.zst
dexon-sol-tools-24564b986daa703f66e54f85abf4782d99a40f94.zip
Minimize unnecessary type assertions
Diffstat (limited to 'packages/order-watcher/src')
-rw-r--r--packages/order-watcher/src/order_watcher/dependent_order_hashes_tracker.ts67
-rw-r--r--packages/order-watcher/src/order_watcher/order_watcher.ts33
2 files changed, 34 insertions, 66 deletions
diff --git a/packages/order-watcher/src/order_watcher/dependent_order_hashes_tracker.ts b/packages/order-watcher/src/order_watcher/dependent_order_hashes_tracker.ts
index 12723f73e..d1085014c 100644
--- a/packages/order-watcher/src/order_watcher/dependent_order_hashes_tracker.ts
+++ b/packages/order-watcher/src/order_watcher/dependent_order_hashes_tracker.ts
@@ -1,6 +1,5 @@
-// tslint:disable:no-unnecessary-type-assertion
import { assetDataUtils, orderHashUtils } from '@0x/order-utils';
-import { AssetProxyId, ERC20AssetData, ERC721AssetData, MultiAssetData, SignedOrder } from '@0x/types';
+import { AssetProxyId, SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';
import * as _ from 'lodash';
@@ -70,7 +69,10 @@ export class DependentOrderHashesTracker {
this._removeAssetDataFromDependentOrderHashes(signedOrder, signedOrder.makerAssetData);
// If makerToken === ZRX then we already removed it and we don't need to remove it again.
const decodedMakerAssetData = assetDataUtils.decodeAssetDataOrThrow(signedOrder.makerAssetData);
- if ((decodedMakerAssetData as ERC20AssetData).tokenAddress !== this._zrxTokenAddress) {
+ if (
+ assetDataUtils.isERC20AssetData(decodedMakerAssetData) &&
+ decodedMakerAssetData.tokenAddress !== this._zrxTokenAddress
+ ) {
this._removeFromERC20DependentOrderhashes(signedOrder, this._zrxTokenAddress);
}
this._removeFromMakerDependentOrderhashes(signedOrder);
@@ -149,24 +151,14 @@ export class DependentOrderHashesTracker {
}
private _addAssetDataToDependentOrderHashes(signedOrder: SignedOrder, assetData: string): void {
const decodedAssetData = assetDataUtils.decodeAssetDataOrThrow(assetData);
- switch (decodedAssetData.assetProxyId) {
- case AssetProxyId.ERC20:
- this._addToERC20DependentOrderHashes(signedOrder, (decodedAssetData as ERC20AssetData).tokenAddress);
- break;
- case AssetProxyId.ERC721:
- this._addToERC721DependentOrderHashes(
- signedOrder,
- (decodedAssetData as ERC721AssetData).tokenAddress,
- (decodedAssetData as ERC721AssetData).tokenId,
- );
- break;
- case AssetProxyId.MultiAsset:
- _.each((decodedAssetData as MultiAssetData).nestedAssetData, nestedAssetDataElement =>
- this._addAssetDataToDependentOrderHashes(signedOrder, nestedAssetDataElement),
- );
- break;
- default:
- break;
+ if (assetDataUtils.isERC20AssetData(decodedAssetData)) {
+ this._addToERC20DependentOrderHashes(signedOrder, decodedAssetData.tokenAddress);
+ } else if (assetDataUtils.isERC721AssetData(decodedAssetData)) {
+ this._addToERC721DependentOrderHashes(signedOrder, decodedAssetData.tokenAddress, decodedAssetData.tokenId);
+ } else if (assetDataUtils.isMultiAssetData(decodedAssetData)) {
+ _.each(decodedAssetData.nestedAssetData, nestedAssetDataElement =>
+ this._addAssetDataToDependentOrderHashes(signedOrder, nestedAssetDataElement),
+ );
}
}
private _addToMakerDependentOrderHashes(signedOrder: SignedOrder): void {
@@ -234,27 +226,18 @@ export class DependentOrderHashesTracker {
}
private _removeAssetDataFromDependentOrderHashes(signedOrder: SignedOrder, assetData: string): void {
const decodedAssetData = assetDataUtils.decodeAssetDataOrThrow(assetData);
- switch (decodedAssetData.assetProxyId) {
- case AssetProxyId.ERC20:
- this._removeFromERC20DependentOrderhashes(
- signedOrder,
- (decodedAssetData as ERC20AssetData).tokenAddress,
- );
- break;
- case AssetProxyId.ERC721:
- this._removeFromERC721DependentOrderhashes(
- signedOrder,
- (decodedAssetData as ERC721AssetData).tokenAddress,
- (decodedAssetData as ERC721AssetData).tokenId,
- );
- break;
- case AssetProxyId.MultiAsset:
- _.each((decodedAssetData as MultiAssetData).nestedAssetData, nestedAssetDataElement =>
- this._removeAssetDataFromDependentOrderHashes(signedOrder, nestedAssetDataElement),
- );
- break;
- default:
- break;
+ if (assetDataUtils.isERC20AssetData(decodedAssetData)) {
+ this._removeFromERC20DependentOrderhashes(signedOrder, decodedAssetData.tokenAddress);
+ } else if (assetDataUtils.isERC721AssetData(decodedAssetData)) {
+ this._removeFromERC721DependentOrderhashes(
+ signedOrder,
+ decodedAssetData.tokenAddress,
+ decodedAssetData.tokenId,
+ );
+ } else if (assetDataUtils.isMultiAssetData(decodedAssetData)) {
+ _.each(decodedAssetData.nestedAssetData, nestedAssetDataElement =>
+ this._removeAssetDataFromDependentOrderHashes(signedOrder, nestedAssetDataElement),
+ );
}
}
}
diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts
index c48606555..656f21a53 100644
--- a/packages/order-watcher/src/order_watcher/order_watcher.ts
+++ b/packages/order-watcher/src/order_watcher/order_watcher.ts
@@ -32,16 +32,7 @@ import {
orderHashUtils,
OrderStateUtils,
} from '@0x/order-utils';
-import {
- AssetProxyId,
- ERC20AssetData,
- ERC721AssetData,
- ExchangeContractErrs,
- MultiAssetData,
- OrderState,
- SignedOrder,
- Stats,
-} from '@0x/types';
+import { AssetProxyId, ExchangeContractErrs, OrderState, SignedOrder, Stats } from '@0x/types';
import { errorUtils, intervalUtils } from '@0x/utils';
import { BlockParamLiteral, LogEntryEvent, LogWithDecodedArgs, Provider } from 'ethereum-types';
import * as _ from 'lodash';
@@ -240,20 +231,14 @@ export class OrderWatcher {
}
private _addAssetDataToAbiDecoder(assetData: string): void {
const decodedAssetData = assetDataUtils.decodeAssetDataOrThrow(assetData);
- switch (decodedAssetData.assetProxyId) {
- case AssetProxyId.ERC20:
- this._collisionResistantAbiDecoder.addERC20Token((decodedAssetData as ERC20AssetData).tokenAddress);
- break;
- case AssetProxyId.ERC721:
- this._collisionResistantAbiDecoder.addERC721Token((decodedAssetData as ERC721AssetData).tokenAddress);
- break;
- case AssetProxyId.MultiAsset:
- _.each((decodedAssetData as MultiAssetData).nestedAssetData, nestedAssetDataElement =>
- this._addAssetDataToAbiDecoder(nestedAssetDataElement),
- );
- break;
- default:
- break;
+ if (assetDataUtils.isERC20AssetData(decodedAssetData)) {
+ this._collisionResistantAbiDecoder.addERC20Token(decodedAssetData.tokenAddress);
+ } else if (assetDataUtils.isERC721AssetData(decodedAssetData)) {
+ this._collisionResistantAbiDecoder.addERC721Token(decodedAssetData.tokenAddress);
+ } else if (assetDataUtils.isMultiAssetData(decodedAssetData)) {
+ _.each(decodedAssetData.nestedAssetData, nestedAssetDataElement =>
+ this._addAssetDataToAbiDecoder(nestedAssetDataElement),
+ );
}
}
private _deleteLazyStoreBalance(assetData: string, userAddress: string): void {