From be2f4cbdcafa19cc8433ff2dc2f0ff6befd64578 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Mon, 27 Aug 2018 11:01:53 -0700 Subject: Add getBalanceAndAllowance to wrapper --- .../src/contract_wrappers/order_validator_wrapper.ts | 20 +++++++++++++++++++- packages/contract-wrappers/src/types.ts | 6 ++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/contract-wrappers/src/contract_wrappers/order_validator_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/order_validator_wrapper.ts index dac243434..3b83fc53b 100644 --- a/packages/contract-wrappers/src/contract_wrappers/order_validator_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/order_validator_wrapper.ts @@ -5,7 +5,7 @@ import { ContractAbi } from 'ethereum-types'; import * as _ from 'lodash'; import { artifacts } from '../artifacts'; -import { OrderAndTraderInfo, OrdersAndTradersInfo, TraderInfo } from '../types'; +import { BalanceAndAllowance, OrderAndTraderInfo, OrdersAndTradersInfo, TraderInfo } from '../types'; import { assert } from '../utils/assert'; import { ContractWrapper } from './contract_wrapper'; @@ -92,6 +92,24 @@ export class OrderValidatorWrapper extends ContractWrapper { const result = await OrderValidatorContractInstance.getTradersInfo.callAsync(orders, takerAddresses); return result; } + /** + * Get an object conforming to BalanceAndAllowance containing on-chain balance and allowance for some address and assetData + * @return BalanceAndAllowance + */ + public async getBalanceAndAllowanceAsync(address: string, assetData: string): Promise { + assert.isETHAddressHex('address', address); + assert.isHexString('assetData', assetData); + const OrderValidatorContractInstance = await this._getOrderValidatorContractAsync(); + const balanceAndAllowance = await OrderValidatorContractInstance.getBalanceAndAllowance.callAsync( + address, + assetData, + ); + const result = { + balance: balanceAndAllowance[0], + allowance: balanceAndAllowance[1], + }; + return result; + } // HACK: We don't want this method to be visible to the other units within that package but not to the end user. // TS doesn't give that possibility and therefore we make it private and access it over an any cast. Because of that tslint sees it as unused. // tslint:disable-next-line:no-unused-variable diff --git a/packages/contract-wrappers/src/types.ts b/packages/contract-wrappers/src/types.ts index e73a09fe3..c51e0ae48 100644 --- a/packages/contract-wrappers/src/types.ts +++ b/packages/contract-wrappers/src/types.ts @@ -204,7 +204,13 @@ export interface OrdersAndTradersInfo { ordersInfo: OrderInfo[]; tradersInfo: TraderInfo[]; } + export interface OrderAndTraderInfo { orderInfo: OrderInfo; traderInfo: TraderInfo; } + +export interface BalanceAndAllowance { + balance: BigNumber; + allowance: BigNumber; +} -- cgit v1.2.3