diff options
-rw-r--r-- | src/stores/balance_proxy_allowance_lazy_store.ts | 15 | ||||
-rw-r--r-- | src/stores/order_filled_cancelled_lazy_store.ts | 15 |
2 files changed, 20 insertions, 10 deletions
diff --git a/src/stores/balance_proxy_allowance_lazy_store.ts b/src/stores/balance_proxy_allowance_lazy_store.ts index 92a6aaa51..a2b8fcf67 100644 --- a/src/stores/balance_proxy_allowance_lazy_store.ts +++ b/src/stores/balance_proxy_allowance_lazy_store.ts @@ -2,13 +2,15 @@ import * as _ from 'lodash'; import * as Web3 from 'web3'; import {BigNumber} from 'bignumber.js'; import {TokenWrapper} from '../contract_wrappers/token_wrapper'; +import {BlockStore} from './block_store'; /** * Copy on read store for balances/proxyAllowances of tokens/accounts */ export class BalanceAndProxyAllowanceLazyStore { private token: TokenWrapper; - private defaultBlock: Web3.BlockParam; + private numConfirmations: number; + private blockStore: BlockStore; private balance: { [tokenAddress: string]: { [userAddress: string]: BigNumber, @@ -19,16 +21,18 @@ export class BalanceAndProxyAllowanceLazyStore { [userAddress: string]: BigNumber, }, }; - constructor(token: TokenWrapper, defaultBlock: Web3.BlockParam) { + constructor(token: TokenWrapper, blockStore: BlockStore, numConfirmations: number) { this.token = token; - this.defaultBlock = defaultBlock; + this.numConfirmations = numConfirmations; + this.blockStore = blockStore; this.balance = {}; this.proxyAllowance = {}; } public async getBalanceAsync(tokenAddress: string, userAddress: string): Promise<BigNumber> { if (_.isUndefined(this.balance[tokenAddress]) || _.isUndefined(this.balance[tokenAddress][userAddress])) { + const defaultBlock = this.blockStore.getBlockNumberWithNConfirmations(this.numConfirmations); const methodOpts = { - defaultBlock: this.defaultBlock, + defaultBlock, }; const balance = await this.token.getBalanceAsync(tokenAddress, userAddress, methodOpts); this.setBalance(tokenAddress, userAddress, balance); @@ -50,8 +54,9 @@ export class BalanceAndProxyAllowanceLazyStore { public async getProxyAllowanceAsync(tokenAddress: string, userAddress: string): Promise<BigNumber> { if (_.isUndefined(this.proxyAllowance[tokenAddress]) || _.isUndefined(this.proxyAllowance[tokenAddress][userAddress])) { + const defaultBlock = this.blockStore.getBlockNumberWithNConfirmations(this.numConfirmations); const methodOpts = { - defaultBlock: this.defaultBlock, + defaultBlock, }; const proxyAllowance = await this.token.getProxyAllowanceAsync(tokenAddress, userAddress, methodOpts); this.setProxyAllowance(tokenAddress, userAddress, proxyAllowance); diff --git a/src/stores/order_filled_cancelled_lazy_store.ts b/src/stores/order_filled_cancelled_lazy_store.ts index cb4c786f3..978de0b18 100644 --- a/src/stores/order_filled_cancelled_lazy_store.ts +++ b/src/stores/order_filled_cancelled_lazy_store.ts @@ -2,29 +2,33 @@ import * as _ from 'lodash'; import * as Web3 from 'web3'; import {BigNumber} from 'bignumber.js'; import {ExchangeWrapper} from '../contract_wrappers/exchange_wrapper'; +import {BlockStore} from './block_store'; /** * Copy on read store for filled/cancelled taker amounts */ export class OrderFilledCancelledLazyStore { private exchange: ExchangeWrapper; - private defaultBlock: Web3.BlockParam; + private numConfirmations: number; + private blockStore: BlockStore; private filledTakerAmount: { [orderHash: string]: BigNumber, }; private cancelledTakerAmount: { [orderHash: string]: BigNumber, }; - constructor(exchange: ExchangeWrapper, defaultBlock: Web3.BlockParam) { + constructor(exchange: ExchangeWrapper, blockStore: BlockStore, numConfirmations: number) { this.exchange = exchange; - this.defaultBlock = defaultBlock; + this.numConfirmations = numConfirmations; + this.blockStore = blockStore; this.filledTakerAmount = {}; this.cancelledTakerAmount = {}; } public async getFilledTakerAmountAsync(orderHash: string): Promise<BigNumber> { if (_.isUndefined(this.filledTakerAmount[orderHash])) { + const defaultBlock = this.blockStore.getBlockNumberWithNConfirmations(this.numConfirmations); const methodOpts = { - defaultBlock: this.defaultBlock, + defaultBlock, }; const filledTakerAmount = await this.exchange.getFilledTakerAmountAsync(orderHash, methodOpts); this.setFilledTakerAmount(orderHash, filledTakerAmount); @@ -40,8 +44,9 @@ export class OrderFilledCancelledLazyStore { } public async getCancelledTakerAmountAsync(orderHash: string): Promise<BigNumber> { if (_.isUndefined(this.cancelledTakerAmount[orderHash])) { + const defaultBlock = this.blockStore.getBlockNumberWithNConfirmations(this.numConfirmations); const methodOpts = { - defaultBlock: this.defaultBlock, + defaultBlock, }; const cancelledTakerAmount = await this.exchange.getCanceledTakerAmountAsync(orderHash, methodOpts); this.setCancelledTakerAmount(orderHash, cancelledTakerAmount); |