From 6edae865168dc86a5a3b39558158d22a4ff3bd99 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 10 Nov 2017 12:12:30 -0500 Subject: Make store configurable by blockParam --- src/stores/balance_proxy_allowance_lazy_store.ts | 15 ++++++++++++--- src/utils/exchange_transfer_simulator.ts | 4 ++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/stores/balance_proxy_allowance_lazy_store.ts b/src/stores/balance_proxy_allowance_lazy_store.ts index 7f392cb82..2580fd449 100644 --- a/src/stores/balance_proxy_allowance_lazy_store.ts +++ b/src/stores/balance_proxy_allowance_lazy_store.ts @@ -1,4 +1,5 @@ import * as _ from 'lodash'; +import * as Web3 from 'web3'; import {BigNumber} from 'bignumber.js'; import {TokenWrapper} from '../contract_wrappers/token_wrapper'; @@ -7,6 +8,7 @@ import {TokenWrapper} from '../contract_wrappers/token_wrapper'; */ export class BalanceAndProxyAllowanceLazyStore { private token: TokenWrapper; + private defaultBlock: Web3.BlockParam; private balance: { [tokenAddress: string]: { [userAddress: string]: BigNumber, @@ -17,14 +19,18 @@ export class BalanceAndProxyAllowanceLazyStore { [userAddress: string]: BigNumber, }, }; - constructor(token: TokenWrapper) { + constructor(token: TokenWrapper, defaultBlock: Web3.BlockParam) { this.token = token; + this.defaultBlock = defaultBlock; this.balance = {}; this.proxyAllowance = {}; } public async getBalanceAsync(tokenAddress: string, userAddress: string): Promise { if (_.isUndefined(this.balance[tokenAddress]) || _.isUndefined(this.balance[tokenAddress][userAddress])) { - const balance = await this.token.getBalanceAsync(tokenAddress, userAddress); + const methodOpts = { + defaultBlock: this.defaultBlock, + }; + const balance = await this.token.getBalanceAsync(tokenAddress, userAddress, methodOpts); this.setBalance(tokenAddress, userAddress, balance); } const cachedBalance = this.balance[tokenAddress][userAddress]; @@ -39,7 +45,10 @@ export class BalanceAndProxyAllowanceLazyStore { public async getProxyAllowanceAsync(tokenAddress: string, userAddress: string): Promise { if (_.isUndefined(this.proxyAllowance[tokenAddress]) || _.isUndefined(this.proxyAllowance[tokenAddress][userAddress])) { - const proxyAllowance = await this.token.getProxyAllowanceAsync(tokenAddress, userAddress); + const methodOpts = { + defaultBlock: this.defaultBlock, + }; + const proxyAllowance = await this.token.getProxyAllowanceAsync(tokenAddress, userAddress, methodOpts); this.setProxyAllowance(tokenAddress, userAddress, proxyAllowance); } const cachedProxyAllowance = this.proxyAllowance[tokenAddress][userAddress]; diff --git a/src/utils/exchange_transfer_simulator.ts b/src/utils/exchange_transfer_simulator.ts index ecdec0be0..56bd48f17 100644 --- a/src/utils/exchange_transfer_simulator.ts +++ b/src/utils/exchange_transfer_simulator.ts @@ -1,6 +1,6 @@ import * as _ from 'lodash'; import BigNumber from 'bignumber.js'; -import {ExchangeContractErrs, TradeSide, TransferType} from '../types'; +import {ExchangeContractErrs, TradeSide, TransferType, BlockParamLiteral} from '../types'; import {TokenWrapper} from '../contract_wrappers/token_wrapper'; import {BalanceAndProxyAllowanceLazyStore} from '../stores/balance_proxy_allowance_lazy_store'; @@ -36,7 +36,7 @@ export class ExchangeTransferSimulator { private store: BalanceAndProxyAllowanceLazyStore; private UNLIMITED_ALLOWANCE_IN_BASE_UNITS: BigNumber; constructor(token: TokenWrapper) { - this.store = new BalanceAndProxyAllowanceLazyStore(token); + this.store = new BalanceAndProxyAllowanceLazyStore(token, BlockParamLiteral.Latest); this.UNLIMITED_ALLOWANCE_IN_BASE_UNITS = token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS; } /** -- cgit v1.2.3