aboutsummaryrefslogtreecommitdiffstats
path: root/packages/fill-scenarios/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/fill-scenarios/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/fill-scenarios/src')
-rw-r--r--packages/fill-scenarios/src/fill_scenarios.ts59
1 files changed, 17 insertions, 42 deletions
diff --git a/packages/fill-scenarios/src/fill_scenarios.ts b/packages/fill-scenarios/src/fill_scenarios.ts
index 2e87e60cc..ce1f7f9ff 100644
--- a/packages/fill-scenarios/src/fill_scenarios.ts
+++ b/packages/fill-scenarios/src/fill_scenarios.ts
@@ -2,14 +2,7 @@ import { DummyERC20TokenContract, DummyERC721TokenContract, ExchangeContract } f
import * as artifacts from '@0x/contract-artifacts';
import { assetDataUtils } from '@0x/order-utils';
import { orderFactory } from '@0x/order-utils/lib/src/order_factory';
-import {
- AssetProxyId,
- ERC20AssetData,
- ERC721AssetData,
- MultiAssetData,
- OrderWithoutExchangeAddress,
- SignedOrder,
-} from '@0x/types';
+import { OrderWithoutExchangeAddress, SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import { Provider } from 'ethereum-types';
@@ -280,42 +273,24 @@ export class FillScenarios {
amount: BigNumber,
): Promise<void> {
const decodedAssetData = assetDataUtils.decodeAssetDataOrThrow(assetData);
- switch (decodedAssetData.assetProxyId) {
- case AssetProxyId.ERC20:
- await this._increaseERC20BalanceAndAllowanceAsync(
- // tslint:disable-next-line:no-unnecessary-type-assertion
- (decodedAssetData as ERC20AssetData).tokenAddress,
- userAddress,
- amount,
- );
- break;
- case AssetProxyId.ERC721:
- await this._increaseERC721BalanceAndAllowanceAsync(
- // tslint:disable-next-line:no-unnecessary-type-assertion
- (decodedAssetData as ERC721AssetData).tokenAddress,
+ if (assetDataUtils.isERC20AssetData(decodedAssetData)) {
+ await this._increaseERC20BalanceAndAllowanceAsync(decodedAssetData.tokenAddress, userAddress, amount);
+ } else if (assetDataUtils.isERC721AssetData(decodedAssetData)) {
+ await this._increaseERC721BalanceAndAllowanceAsync(
+ decodedAssetData.tokenAddress,
+ userAddress,
+ decodedAssetData.tokenId,
+ );
+ } else if (assetDataUtils.isMultiAssetData(decodedAssetData)) {
+ for (const [index, nestedAssetDataElement] of decodedAssetData.nestedAssetData.entries()) {
+ const amountsElement = decodedAssetData.amounts[index];
+ const totalAmount = amount.times(amountsElement);
+ await this._increaseBalanceAndAllowanceWithAssetDataAsync(
+ nestedAssetDataElement,
userAddress,
- // tslint:disable-next-line:no-unnecessary-type-assertion
- (decodedAssetData as ERC721AssetData).tokenId,
+ totalAmount,
);
- break;
- case AssetProxyId.MultiAsset:
- for (const [
- index,
- nestedAssetDataElement,
- // tslint:disable-next-line:no-unnecessary-type-assertion
- ] of (decodedAssetData as MultiAssetData).nestedAssetData.entries()) {
- // tslint:disable-next-line:no-unnecessary-type-assertion
- const amountsElement = (decodedAssetData as MultiAssetData).amounts[index];
- const totalAmount = amount.times(amountsElement);
- await this._increaseBalanceAndAllowanceWithAssetDataAsync(
- nestedAssetDataElement,
- userAddress,
- totalAmount,
- );
- }
- break;
- default:
- throw new Error(`Proxy with id ${decodedAssetData.assetProxyId} not supported`);
+ }
}
}
}