diff options
author | Ara Kevonian <ara@dextroid.io> | 2018-04-13 18:04:51 +0800 |
---|---|---|
committer | Ara Kevonian <ara@dextroid.io> | 2018-04-13 18:04:51 +0800 |
commit | 38f7c4a0d2d9269b5fd185b303ede7a44ab78c99 (patch) | |
tree | 901387c575cd38968bb5dbe58c34fccd7a7bf9eb /packages/0x.js/src | |
parent | bf0ef055fbd4f5f798ea56868ad0beddf1111e7f (diff) | |
download | dexon-0x-contracts-38f7c4a0d2d9269b5fd185b303ede7a44ab78c99.tar dexon-0x-contracts-38f7c4a0d2d9269b5fd185b303ede7a44ab78c99.tar.gz dexon-0x-contracts-38f7c4a0d2d9269b5fd185b303ede7a44ab78c99.tar.bz2 dexon-0x-contracts-38f7c4a0d2d9269b5fd185b303ede7a44ab78c99.tar.lz dexon-0x-contracts-38f7c4a0d2d9269b5fd185b303ede7a44ab78c99.tar.xz dexon-0x-contracts-38f7c4a0d2d9269b5fd185b303ede7a44ab78c99.tar.zst dexon-0x-contracts-38f7c4a0d2d9269b5fd185b303ede7a44ab78c99.zip |
Implement Simple Fetchers
Diffstat (limited to 'packages/0x.js/src')
-rw-r--r-- | packages/0x.js/src/abstract/balance_and_allowance_fetcher.ts (renamed from packages/0x.js/src/fetchers/balance_and_allowance_fetcher.ts) | 0 | ||||
-rw-r--r-- | packages/0x.js/src/abstract/order_filled_cancelled_fetcher.ts (renamed from packages/0x.js/src/fetchers/order_filled_cancelled_fetcher.ts) | 0 | ||||
-rw-r--r-- | packages/0x.js/src/contract_wrappers/exchange_wrapper.ts | 8 | ||||
-rw-r--r-- | packages/0x.js/src/fetchers/simple_balance_and_allowance_fetcher.ts | 26 | ||||
-rw-r--r-- | packages/0x.js/src/fetchers/simple_order_filled_cancelled_fetcher.ts | 24 | ||||
-rw-r--r-- | packages/0x.js/src/stores/balance_proxy_allowance_lazy_store.ts | 2 | ||||
-rw-r--r-- | packages/0x.js/src/stores/order_filled_cancelled_lazy_store.ts | 2 | ||||
-rw-r--r-- | packages/0x.js/src/utils/order_state_utils.ts | 4 |
8 files changed, 58 insertions, 8 deletions
diff --git a/packages/0x.js/src/fetchers/balance_and_allowance_fetcher.ts b/packages/0x.js/src/abstract/balance_and_allowance_fetcher.ts index f7b1183f1..f7b1183f1 100644 --- a/packages/0x.js/src/fetchers/balance_and_allowance_fetcher.ts +++ b/packages/0x.js/src/abstract/balance_and_allowance_fetcher.ts diff --git a/packages/0x.js/src/fetchers/order_filled_cancelled_fetcher.ts b/packages/0x.js/src/abstract/order_filled_cancelled_fetcher.ts index 81ae04b9c..81ae04b9c 100644 --- a/packages/0x.js/src/fetchers/order_filled_cancelled_fetcher.ts +++ b/packages/0x.js/src/abstract/order_filled_cancelled_fetcher.ts diff --git a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts index b6949e465..65b5a2e53 100644 --- a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts @@ -13,8 +13,8 @@ import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as _ from 'lodash'; import { artifacts } from '../artifacts'; -import { BalanceAndProxyAllowanceLazyStore } from '../stores/balance_proxy_allowance_lazy_store'; -import { OrderFilledCancelledLazyStore } from '../stores/order_filled_cancelled_lazy_store'; +import { SimpleBalanceAndAllowanceFetcher } from '../fetchers/simple_balance_and_allowance_fetcher'; +import { SimpleOrderFilledCancelledFetcher } from '../fetchers/simple_order_filled_cancelled_fetcher'; import { BlockRange, EventCallback, @@ -881,11 +881,11 @@ export class ExchangeWrapper extends ContractWrapper { * @param signedOrder The signedOrder */ public async getOrderStateAsync(signedOrder: SignedOrder): Promise<OrderState> { - const balanceAndProxyAllowanceLazyStore = new BalanceAndProxyAllowanceLazyStore( + const balanceAndProxyAllowanceLazyStore = new SimpleBalanceAndAllowanceFetcher( this._tokenWrapper, BlockParamLiteral.Latest, ); - const orderFilledCancelledLazyStore = new OrderFilledCancelledLazyStore(this); + const orderFilledCancelledLazyStore = new SimpleOrderFilledCancelledFetcher(this); const orderStateUtils = new OrderStateUtils(balanceAndProxyAllowanceLazyStore, orderFilledCancelledLazyStore); 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 new file mode 100644 index 000000000..2aa1cc2b7 --- /dev/null +++ b/packages/0x.js/src/fetchers/simple_balance_and_allowance_fetcher.ts @@ -0,0 +1,26 @@ +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<BigNumber> { + const methodOpts = { + defaultBlock: this._defaultBlock, + }; + return this._token.getBalanceAsync(tokenAddress, userAddress, methodOpts); + } + public async getProxyAllowanceAsync(tokenAddress: string, userAddress: string): Promise<BigNumber> { + const methodOpts = { + defaultBlock: this._defaultBlock, + }; + return this._token.getProxyAllowanceAsync(tokenAddress, userAddress, methodOpts); + } +} diff --git a/packages/0x.js/src/fetchers/simple_order_filled_cancelled_fetcher.ts b/packages/0x.js/src/fetchers/simple_order_filled_cancelled_fetcher.ts new file mode 100644 index 000000000..e24f02726 --- /dev/null +++ b/packages/0x.js/src/fetchers/simple_order_filled_cancelled_fetcher.ts @@ -0,0 +1,24 @@ +import { BlockParamLiteral } from '@0xproject/types'; +import { BigNumber } from '@0xproject/utils'; + +import {OrderFilledCancelledFetcher} from '../abstract/order_filled_cancelled_fetcher'; +import {ExchangeWrapper} from '../contract_wrappers/exchange_wrapper'; + +export class SimpleOrderFilledCancelledFetcher implements OrderFilledCancelledFetcher { + private _exchange: ExchangeWrapper; + constructor(exchange: ExchangeWrapper) { + this._exchange = exchange; + } + public async getFilledTakerAmountAsync(orderHash: string): Promise<BigNumber> { + const methodOpts = { + defaultBlock: BlockParamLiteral.Pending, + }; + return this._exchange.getFilledTakerAmountAsync(orderHash, methodOpts); + } + public async getCancelledTakerAmountAsync(orderHash: string): Promise<BigNumber> { + const methodOpts = { + defaultBlock: BlockParamLiteral.Pending, + }; + return this._exchange.getCancelledTakerAmountAsync(orderHash, 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 610385356..9ca622a69 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,7 +3,7 @@ import { BigNumber } from '@0xproject/utils'; import * as _ from 'lodash'; import { TokenWrapper } from '../contract_wrappers/token_wrapper'; -import { BalanceAndAllowanceFetcher } from '../fetchers/balance_and_allowance_fetcher'; +import { BalanceAndAllowanceFetcher } from '../abstract/balance_and_allowance_fetcher'; /** * Copy on read store for balances/proxyAllowances of tokens/accounts diff --git a/packages/0x.js/src/stores/order_filled_cancelled_lazy_store.ts b/packages/0x.js/src/stores/order_filled_cancelled_lazy_store.ts index 9ed4d3bf4..134508057 100644 --- a/packages/0x.js/src/stores/order_filled_cancelled_lazy_store.ts +++ b/packages/0x.js/src/stores/order_filled_cancelled_lazy_store.ts @@ -3,7 +3,7 @@ import { BigNumber } from '@0xproject/utils'; import * as _ from 'lodash'; import { ExchangeWrapper } from '../contract_wrappers/exchange_wrapper'; -import { OrderFilledCancelledFetcher } from '../fetchers/order_filled_cancelled_fetcher'; +import { OrderFilledCancelledFetcher } from '../abstract/order_filled_cancelled_fetcher'; /** * Copy on read store for filled/cancelled taker amounts diff --git a/packages/0x.js/src/utils/order_state_utils.ts b/packages/0x.js/src/utils/order_state_utils.ts index 6dbf7e572..d45b67dc2 100644 --- a/packages/0x.js/src/utils/order_state_utils.ts +++ b/packages/0x.js/src/utils/order_state_utils.ts @@ -4,8 +4,8 @@ import * as _ from 'lodash'; import { ZeroEx } from '../0x'; import { ExchangeWrapper } from '../contract_wrappers/exchange_wrapper'; -import { BalanceAndAllowanceFetcher } from '../fetchers/balance_and_allowance_fetcher'; -import { OrderFilledCancelledFetcher } from '../fetchers/order_filled_cancelled_fetcher'; +import { BalanceAndAllowanceFetcher } from '../abstract/balance_and_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'; |