diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-11-11 01:12:30 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-11-13 09:03:18 +0800 |
commit | 6edae865168dc86a5a3b39558158d22a4ff3bd99 (patch) | |
tree | 9a22715c9b5d060dbac6d79f6c595e834e59a41f /src | |
parent | f163e6d8cc53dbbfd65168c977aa53c5ab9b3c08 (diff) | |
download | dexon-sol-tools-6edae865168dc86a5a3b39558158d22a4ff3bd99.tar dexon-sol-tools-6edae865168dc86a5a3b39558158d22a4ff3bd99.tar.gz dexon-sol-tools-6edae865168dc86a5a3b39558158d22a4ff3bd99.tar.bz2 dexon-sol-tools-6edae865168dc86a5a3b39558158d22a4ff3bd99.tar.lz dexon-sol-tools-6edae865168dc86a5a3b39558158d22a4ff3bd99.tar.xz dexon-sol-tools-6edae865168dc86a5a3b39558158d22a4ff3bd99.tar.zst dexon-sol-tools-6edae865168dc86a5a3b39558158d22a4ff3bd99.zip |
Make store configurable by blockParam
Diffstat (limited to 'src')
-rw-r--r-- | src/stores/balance_proxy_allowance_lazy_store.ts | 15 | ||||
-rw-r--r-- | 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<BigNumber> { 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<BigNumber> { 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; } /** |