Implement getUnavailableTakerAmountAsync, getFilledTakerAmountAsync and getCanceledTakerAmountAsync

This commit is contained in:
Fabio Berger
2017-05-31 20:10:09 +02:00
parent 595656d3fc
commit 52c3330487
2 changed files with 42 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
import * as _ from 'lodash';
import * as BigNumber from 'bignumber.js';
import {Web3Wrapper} from '../web3_wrapper';
import {ECSignature, ZeroExError, ExchangeContract} from '../types';
import {assert} from '../utils/assert';
@@ -37,6 +38,38 @@ export class ExchangeWrapper extends ContractWrapper {
);
return isValidSignature;
}
/**
* Returns the unavailable takerAmount of an order. Unavailable amount is defined as the total
* amount that has been filled or cancelled. The remaining takerAmount can be calculated by
* subtracting the unavailable amount from the total order takerAmount.
*/
public async getUnavailableTakerAmountAsync(orderHashHex: string): Promise<BigNumber.BigNumber> {
assert.isValidOrderHash('orderHashHex', orderHashHex);
const exchangeContract = await this.getExchangeContractAsync();
const unavailableAmountInBaseUnits = await exchangeContract.getUnavailableValueT.call(orderHashHex);
return unavailableAmountInBaseUnits;
}
/**
* Retrieve the takerAmount of an order that has already been filled.
*/
public async getFilledTakerAmountAsync(orderHashHex: string): Promise<BigNumber.BigNumber> {
assert.isValidOrderHash('orderHashHex', orderHashHex);
const exchangeContract = await this.getExchangeContractAsync();
const fillAmountInBaseUnits = await exchangeContract.filled.call(orderHashHex);
return fillAmountInBaseUnits;
}
/**
* Retrieve the takerAmount of an order that has been cancelled.
*/
public async getCanceledTakerAmountAsync(orderHashHex: string): Promise<BigNumber.BigNumber> {
assert.isValidOrderHash('orderHashHex', orderHashHex);
const exchangeContract = await this.getExchangeContractAsync();
const cancelledAmountInBaseUnits = await exchangeContract.cancelled.call(orderHashHex);
return cancelledAmountInBaseUnits;
}
private async getExchangeContractAsync(): Promise<ExchangeContract> {
if (!_.isUndefined(this.exchangeContractIfExists)) {
return this.exchangeContractIfExists;

View File

@@ -29,6 +29,15 @@ export interface ECSignature {
export interface ExchangeContract {
isValidSignature: any;
getUnavailableValueT: {
call: (orderHash: string) => BigNumber.BigNumber;
};
filled: {
call: (orderHash: string) => BigNumber.BigNumber;
};
cancelled: {
call: (orderHash: string) => BigNumber.BigNumber;
};
}
export interface TokenContract {