Add getBalanceAndAllowance to wrapper

This commit is contained in:
Brandon Millman
2018-08-27 11:01:53 -07:00
parent 68f2dc11b4
commit be2f4cbdca
2 changed files with 25 additions and 1 deletions

View File

@@ -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<BalanceAndAllowance> {
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

View File

@@ -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;
}