Skip to content

Commit

Permalink
#29 Improve open orders:
Browse files Browse the repository at this point in the history
 - add cancel all orders/asks/bids buttons
 - add assertions
  • Loading branch information
priecint committed Jul 13, 2016
1 parent b26ccec commit 9497d66
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 44 deletions.
40 changes: 20 additions & 20 deletions build/components.jsx

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/styles.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/modules/market/components/market-page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default class MarketPage extends Component {
);
}

if (p.market.openOrders && p.market.openOrders.length > 0) {
if (p.market.openOrders && p.market.openOrders.items.length > 0) {
nodes.push(
<OpenOrders
key="open-orders"
Expand Down
29 changes: 25 additions & 4 deletions src/modules/market/components/open-orders.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,49 @@ const OpenOrders = (p) => (
<tbody>
<tr>
<th>Type</th>
<th>Qty.</th>
<th>Shares</th>
<th>Price</th>
<th>Matched</th>
<th>Unmatched</th>
<th>&nbsp;</th>
</tr>
{
p.openOrders.map(openOrder => (
p.openOrders.items.map(openOrder => (
<OpenOrder
key={openOrder.id}
{...openOrder}
onCancelOrder={p.onCancelOrder}
onCancelOrder={p.openOrders.onCancelOrder}
/>
)
)
}
</tbody>
<tfoot>
{
p.openOrders.items.length > 0 &&
<button className="button" onClick={(event) => { p.openOrders.onCancelAllOrders(); }}>
Cancel all
</button>
}
{
p.openOrders.bidsCount > 0 &&
<button className="button" onClick={(event) => { p.openOrders.onCancelAllBids(); }}>
Cancel all bids
</button>
}
{
p.openOrders.asksCount > 0 &&
<button className="button" onClick={(event) => { p.openOrders.onCancelAllAsks(); }}>
Cancel all asks
</button>
}
</tfoot>
</table>
</div>
);

OpenOrders.propTypes = {
openOrders: React.PropTypes.array
openOrders: React.PropTypes.object
};

export default OpenOrders;
23 changes: 16 additions & 7 deletions src/modules/open-orders/components/open-order.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,35 @@
*/

import React from 'react';
import classnames from 'classnames';

import ValueDenomination from '../../common/components/value-denomination';

const OpenOrder = (p) => (
<tr className="open-order">
<tr className={classnames('open-order', { isCancelling: p.isCancelling })}>
<td>
{p.type}
</td>
<td>
<ValueDenomination {...p.originalShares}/>
<ValueDenomination {...p.originalShares} />
</td>
<td>
<ValueDenomination {...p.avgPrice}/>
<ValueDenomination {...p.avgPrice} />
</td>
<td>
<ValueDenomination {...p.matchedShares}/>
<ValueDenomination {...p.matchedShares} />
</td>
<td>
<ValueDenomination {...p.unmatchedShares}/>
<button className="cancel-order-action" disabled={p.isCancelling} title="Cancel order" onClick={p.onCancelOrder(p.id)}>x</button>
<ValueDenomination {...p.unmatchedShares} />
</td>
<td>
<button
className="button cancel-order-action"
disabled={p.isCancelling}
title="Cancel order"
onClick={(event) => { p.onCancelOrder(p.id); }}
>x</button>

</td>
</tr>
);
Expand All @@ -37,4 +46,4 @@ OpenOrder.propTypes = {
isCancelling: React.PropTypes.bool
};

export default OpenOrder;
export default OpenOrder;
5 changes: 5 additions & 0 deletions src/modules/open-orders/less/open-order.less
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@

.open-order:not(:hover) .cancel-order-action {
display: none;
}

.open-order.isCancelling {
text-decoration: line-through;
}
38 changes: 27 additions & 11 deletions src/selectors/markets.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function makeMarkets(numMarkets = 25) {
makerFeePercent: makeNumber(randomInt(1, 5), '%', true),
volume: makeNumber(randomInt(0, 10000), 'shares', true),
isOpen: Math.random() > 0.1,
isPendingReport: false,
isPendingReport: Math.random() < 0.5,
marketLink: {
text: 'Trade',
className: 'trade',
Expand Down Expand Up @@ -129,8 +129,31 @@ function makeMarkets(numMarkets = 25) {
}
];

m.openOrders = [
{
m.openOrders = {
onCancelOrder: (orderId) => {
console.log('cancelling order %o', orderId);
setTimeout(() => {
require('../selectors').market.openOrders.items.find(openOrder => openOrder.id === orderId).isCancelling = true;
require('../selectors').update({});
setTimeout(() => {
const index = require('../selectors').market.openOrders.items.findIndex(openOrder => openOrder.id === orderId);
require('../selectors').market.openOrders.items.splice(index, 1);
require('../selectors').update({});
}, 2000);
}, 1);
},
onCancelAllOrders: () => {
console.log('todo: onCancelAllOrders');
},
onCancelAllBids: () => {
console.log('todo: onCancelAllBids');
},
onCancelAllAsks: () => {
console.log('todo: onCancelAllAsks');
},
bidsCount: 2,
asksCount: 1,
items: [{
id: 'order1',
type: 'sell',
originalShares: makeNumber(5, 'shares'),
Expand Down Expand Up @@ -159,14 +182,7 @@ function makeMarkets(numMarkets = 25) {
unmatchedShares: makeNumber(2, 'shares'),
outcome: 'outcomeasdf123',
owner: '0x45a153fdd97836c2b349a5f53970dc44b0ef1efa'
},
];

m.onCancelOrder = (orderId) => {
setTimeout(() => {
require('../selectors').market.openOrders.find(openOrder => openOrder.id === orderId).isCancelling = true;
require('../selectors').update({});
}, 1);
}]
};

// positions summary
Expand Down
42 changes: 42 additions & 0 deletions test/assertions/market.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,49 @@ export default function(market) {
});

describe('openOrders', () => {
it('should exist', () => {
assert.isDefined(market.openOrders);
});

it('should be object', () => {
assert.isObject(market.openOrders);
});

describe('onCancelOrder', () => {
it('should be function', () => {
assert.isFunction(market.openOrders.onCancelOrder);
});
});

describe('onCancelAllOrders', () => {
it('should be function', () => {
assert.isFunction(market.openOrders.onCancelAllOrders);
});
});

describe('onCancelAllBids', () => {
it('should be function', () => {
assert.isFunction(market.openOrders.onCancelAllBids);
});
});

describe('onCancelAllAsks', () => {
it('should be function', () => {
assert.isFunction(market.openOrders.onCancelAllAsks);
});
});

describe('items', () => {
assert.isArray(market.openOrders.items);
});

describe('asksCount', () => {
assert.isNumber(market.openOrders.asksCount);
});

describe('bidsCount', () => {
assert.isNumber(market.openOrders.bidsCount);
});
});

describe('priceTimeSeries', () => {
Expand Down

0 comments on commit 9497d66

Please sign in to comment.