From 5355da6cad157bb67d1b55a2f8463efe3e072385 Mon Sep 17 00:00:00 2001 From: Ara Kevonian Date: Fri, 13 Apr 2018 03:17:09 -0700 Subject: Rename BalanceAndAllowanceFetchers to BalanceAndProxyAllowanceFetchers --- .../src/abstract/balance_and_allowance_fetcher.ts | 6 ----- .../balance_and_proxy_allowance_fetcher.ts | 6 +++++ .../src/contract_wrappers/exchange_wrapper.ts | 8 +++---- .../simple_balance_and_allowance_fetcher.ts | 26 ---------------------- .../simple_balance_and_proxy_allowance_fetcher.ts | 26 ++++++++++++++++++++++ .../stores/balance_proxy_allowance_lazy_store.ts | 4 ++-- packages/0x.js/src/utils/order_state_utils.ts | 16 ++++++------- 7 files changed, 46 insertions(+), 46 deletions(-) delete mode 100644 packages/0x.js/src/abstract/balance_and_allowance_fetcher.ts create mode 100644 packages/0x.js/src/abstract/balance_and_proxy_allowance_fetcher.ts delete mode 100644 packages/0x.js/src/fetchers/simple_balance_and_allowance_fetcher.ts create mode 100644 packages/0x.js/src/fetchers/simple_balance_and_proxy_allowance_fetcher.ts diff --git a/packages/0x.js/src/abstract/balance_and_allowance_fetcher.ts b/packages/0x.js/src/abstract/balance_and_allowance_fetcher.ts deleted file mode 100644 index f7b1183f1..000000000 --- a/packages/0x.js/src/abstract/balance_and_allowance_fetcher.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { BigNumber } from '@0xproject/utils'; - -export abstract class BalanceAndAllowanceFetcher { - public abstract async getBalanceAsync(tokenAddress: string, userAddress: string): Promise; - public abstract async getProxyAllowanceAsync(tokenAddress: string, userAddress: string): Promise; -} diff --git a/packages/0x.js/src/abstract/balance_and_proxy_allowance_fetcher.ts b/packages/0x.js/src/abstract/balance_and_proxy_allowance_fetcher.ts new file mode 100644 index 000000000..c357f8447 --- /dev/null +++ b/packages/0x.js/src/abstract/balance_and_proxy_allowance_fetcher.ts @@ -0,0 +1,6 @@ +import { BigNumber } from '@0xproject/utils'; + +export abstract class BalanceAndProxyAllowanceFetcher { + public abstract async getBalanceAsync(tokenAddress: string, userAddress: string): Promise; + public abstract async getProxyAllowanceAsync(tokenAddress: string, userAddress: string): Promise; +} diff --git a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts index 65b5a2e53..5dea70769 100644 --- a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts @@ -13,7 +13,7 @@ import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as _ from 'lodash'; import { artifacts } from '../artifacts'; -import { SimpleBalanceAndAllowanceFetcher } from '../fetchers/simple_balance_and_allowance_fetcher'; +import { SimpleBalanceAndProxyAllowanceFetcher } from '../fetchers/simple_balance_and_proxy_allowance_fetcher'; import { SimpleOrderFilledCancelledFetcher } from '../fetchers/simple_order_filled_cancelled_fetcher'; import { BlockRange, @@ -881,12 +881,12 @@ export class ExchangeWrapper extends ContractWrapper { * @param signedOrder The signedOrder */ public async getOrderStateAsync(signedOrder: SignedOrder): Promise { - const balanceAndProxyAllowanceLazyStore = new SimpleBalanceAndAllowanceFetcher( + const simpleBalanceAndProxyAllowanceFetcher = new SimpleBalanceAndProxyAllowanceFetcher( this._tokenWrapper, BlockParamLiteral.Latest, ); - const orderFilledCancelledLazyStore = new SimpleOrderFilledCancelledFetcher(this); - const orderStateUtils = new OrderStateUtils(balanceAndProxyAllowanceLazyStore, orderFilledCancelledLazyStore); + const simpleOrderFilledCancelledFetcher = new SimpleOrderFilledCancelledFetcher(this); + const orderStateUtils = new OrderStateUtils(simpleBalanceAndProxyAllowanceFetcher, simpleOrderFilledCancelledFetcher); return orderStateUtils.getOrderStateAsync(signedOrder); } /** diff --git a/packages/0x.js/src/fetchers/simple_balance_and_allowance_fetcher.ts b/packages/0x.js/src/fetchers/simple_balance_and_allowance_fetcher.ts deleted file mode 100644 index 2aa1cc2b7..000000000 --- a/packages/0x.js/src/fetchers/simple_balance_and_allowance_fetcher.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { BlockParamLiteral } from '@0xproject/types'; -import { BigNumber } from '@0xproject/utils'; - -import {BalanceAndAllowanceFetcher} from '../abstract/balance_and_allowance_fetcher'; -import {TokenWrapper} from '../contract_wrappers/token_wrapper'; - -export class SimpleBalanceAndAllowanceFetcher implements BalanceAndAllowanceFetcher { - private _token: TokenWrapper; - private _defaultBlock: BlockParamLiteral; - constructor(token: TokenWrapper, defaultBlock: BlockParamLiteral) { - this._token = token; - this._defaultBlock = defaultBlock; - } - public async getBalanceAsync(tokenAddress: string, userAddress: string): Promise { - const methodOpts = { - defaultBlock: this._defaultBlock, - }; - return this._token.getBalanceAsync(tokenAddress, userAddress, methodOpts); - } - public async getProxyAllowanceAsync(tokenAddress: string, userAddress: string): Promise { - const methodOpts = { - defaultBlock: this._defaultBlock, - }; - return this._token.getProxyAllowanceAsync(tokenAddress, userAddress, methodOpts); - } -} diff --git a/packages/0x.js/src/fetchers/simple_balance_and_proxy_allowance_fetcher.ts b/packages/0x.js/src/fetchers/simple_balance_and_proxy_allowance_fetcher.ts new file mode 100644 index 000000000..877f07a22 --- /dev/null +++ b/packages/0x.js/src/fetchers/simple_balance_and_proxy_allowance_fetcher.ts @@ -0,0 +1,26 @@ +import { BlockParamLiteral } from '@0xproject/types'; +import { BigNumber } from '@0xproject/utils'; + +import {BalanceAndProxyAllowanceFetcher} from '../abstract/balance_and_proxy_allowance_fetcher'; +import {TokenWrapper} from '../contract_wrappers/token_wrapper'; + +export class SimpleBalanceAndProxyAllowanceFetcher implements BalanceAndProxyAllowanceFetcher { + private _token: TokenWrapper; + private _defaultBlock: BlockParamLiteral; + constructor(token: TokenWrapper, defaultBlock: BlockParamLiteral) { + this._token = token; + this._defaultBlock = defaultBlock; + } + public async getBalanceAsync(tokenAddress: string, userAddress: string): Promise { + const methodOpts = { + defaultBlock: this._defaultBlock, + }; + return this._token.getBalanceAsync(tokenAddress, userAddress, methodOpts); + } + public async getProxyAllowanceAsync(tokenAddress: string, userAddress: string): Promise { + const methodOpts = { + defaultBlock: this._defaultBlock, + }; + return this._token.getProxyAllowanceAsync(tokenAddress, userAddress, methodOpts); + } +} diff --git a/packages/0x.js/src/stores/balance_proxy_allowance_lazy_store.ts b/packages/0x.js/src/stores/balance_proxy_allowance_lazy_store.ts index 9ca622a69..97739f969 100644 --- a/packages/0x.js/src/stores/balance_proxy_allowance_lazy_store.ts +++ b/packages/0x.js/src/stores/balance_proxy_allowance_lazy_store.ts @@ -3,12 +3,12 @@ import { BigNumber } from '@0xproject/utils'; import * as _ from 'lodash'; import { TokenWrapper } from '../contract_wrappers/token_wrapper'; -import { BalanceAndAllowanceFetcher } from '../abstract/balance_and_allowance_fetcher'; +import { BalanceAndProxyAllowanceFetcher } from '../abstract/balance_and_proxy_allowance_fetcher'; /** * Copy on read store for balances/proxyAllowances of tokens/accounts */ -export class BalanceAndProxyAllowanceLazyStore implements BalanceAndAllowanceFetcher { +export class BalanceAndProxyAllowanceLazyStore implements BalanceAndProxyAllowanceFetcher { private _token: TokenWrapper; private _defaultBlock: BlockParamLiteral; private _balance: { diff --git a/packages/0x.js/src/utils/order_state_utils.ts b/packages/0x.js/src/utils/order_state_utils.ts index d45b67dc2..d8d69185f 100644 --- a/packages/0x.js/src/utils/order_state_utils.ts +++ b/packages/0x.js/src/utils/order_state_utils.ts @@ -4,7 +4,7 @@ import * as _ from 'lodash'; import { ZeroEx } from '../0x'; import { ExchangeWrapper } from '../contract_wrappers/exchange_wrapper'; -import { BalanceAndAllowanceFetcher } from '../abstract/balance_and_allowance_fetcher'; +import { BalanceAndProxyAllowanceFetcher } from '../abstract/balance_and_proxy_allowance_fetcher'; import { OrderFilledCancelledFetcher } from '../abstract/order_filled_cancelled_fetcher'; import { RemainingFillableCalculator } from '../order_watcher/remaining_fillable_calculator'; import { ExchangeContractErrs, OrderRelevantState, OrderState, OrderStateInvalid, OrderStateValid } from '../types'; @@ -12,7 +12,7 @@ import { ExchangeContractErrs, OrderRelevantState, OrderState, OrderStateInvalid const ACCEPTABLE_RELATIVE_ROUNDING_ERROR = 0.0001; export class OrderStateUtils { - private _balanceAndAllowanceFetcher: BalanceAndAllowanceFetcher; + private _balanceAndProxyAllowanceFetcher: BalanceAndProxyAllowanceFetcher; private _orderFilledCancelledFetcher: OrderFilledCancelledFetcher; private static _validateIfOrderIsValid(signedOrder: SignedOrder, orderRelevantState: OrderRelevantState): void { const unavailableTakerTokenAmount = orderRelevantState.cancelledTakerTokenAmount.add( @@ -49,10 +49,10 @@ export class OrderStateUtils { } } constructor( - balanceAndProxyAllowanceFetcher: BalanceAndAllowanceFetcher, + balanceAndProxyAllowanceFetcher: BalanceAndProxyAllowanceFetcher, orderFilledCancelledFetcher: OrderFilledCancelledFetcher, ) { - this._balanceAndAllowanceFetcher = balanceAndProxyAllowanceFetcher; + this._balanceAndProxyAllowanceFetcher = balanceAndProxyAllowanceFetcher; this._orderFilledCancelledFetcher = orderFilledCancelledFetcher; } public async getOrderStateAsync(signedOrder: SignedOrder): Promise { @@ -83,19 +83,19 @@ export class OrderStateUtils { const exchange = (this._orderFilledCancelledFetcher as any)._exchange as ExchangeWrapper; const zrxTokenAddress = exchange.getZRXTokenAddress(); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - const makerBalance = await this._balanceAndAllowanceFetcher.getBalanceAsync( + const makerBalance = await this._balanceAndProxyAllowanceFetcher.getBalanceAsync( signedOrder.makerTokenAddress, signedOrder.maker, ); - const makerProxyAllowance = await this._balanceAndAllowanceFetcher.getProxyAllowanceAsync( + const makerProxyAllowance = await this._balanceAndProxyAllowanceFetcher.getProxyAllowanceAsync( signedOrder.makerTokenAddress, signedOrder.maker, ); - const makerFeeBalance = await this._balanceAndAllowanceFetcher.getBalanceAsync( + const makerFeeBalance = await this._balanceAndProxyAllowanceFetcher.getBalanceAsync( zrxTokenAddress, signedOrder.maker, ); - const makerFeeProxyAllowance = await this._balanceAndAllowanceFetcher.getProxyAllowanceAsync( + const makerFeeProxyAllowance = await this._balanceAndProxyAllowanceFetcher.getProxyAllowanceAsync( zrxTokenAddress, signedOrder.maker, ); -- cgit