Skip to content

Commit

Permalink
#29 Add order cancellation confirmation:
Browse files Browse the repository at this point in the history
 - change assertions
  • Loading branch information
priecint committed Aug 1, 2016
1 parent 1a4c144 commit 1b8b9f3
Show file tree
Hide file tree
Showing 16 changed files with 155 additions and 75 deletions.
2 changes: 1 addition & 1 deletion build/styles.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default function (appElement, selectors) {
<MarketPage
siteHeader={p.siteHeader}
selectedOutcome={p.selectedOutcome}
cancelOrder={p.cancelOrder}
orderCancellation={p.orderCancellation}
market={p.market}
numPendingReports={p.marketsTotals.numPendingReports}
/>
Expand Down
4 changes: 2 additions & 2 deletions src/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import transactions from '../test/assertions/transactions';
import transactionsTotals from '../test/assertions/transactions-totals';
import url from '../test/assertions/url';
import selectedUserOpenOrdersGroup from '../test/assertions/selected-user-open-orders-group';
import cancelOrder from '../test/assertions/cancel-order';
import orderCancellation from '../test/assertions/order-cancellation';

export default {
activePage,
Expand All @@ -47,5 +47,5 @@ export default {
transactionsTotals,
url,
selectedUserOpenOrdersGroup,
cancelOrder
orderCancellation
};
6 changes: 3 additions & 3 deletions src/modules/common/less/buttons.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.button, .button:visited, {
.button, .button:visited {
display: inline-block;
height: 2.8em;
line-height: 2.8em;
Expand Down Expand Up @@ -101,7 +101,7 @@
color: #aaaabb;
background: transparent;
}
&:hover, {
&:hover {
color: #ffda00;
background: transparent;
text-shadow: 0 0 1px #dddd00;
Expand Down Expand Up @@ -192,4 +192,4 @@
color: white;
background: @color-dark-normal;
}
}
}
4 changes: 2 additions & 2 deletions src/modules/market/components/market-open-orders.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const OpenOrders = (p) => (
id={outcome.id}
name={outcome.name}
userOpenOrders={outcome.userOpenOrders}
cancelOrder={p.cancelOrder}
orderCancellation={p.orderCancellation}
/>
))
}
Expand All @@ -28,7 +28,7 @@ const OpenOrders = (p) => (
OpenOrders.propTypes = {
userOpenOrdersSummary: React.PropTypes.object,
outcomes: React.PropTypes.array,
cancelOrder: React.PropTypes.func.isRequired
orderCancellation: React.PropTypes.object.isRequired
};

export default OpenOrders;
4 changes: 2 additions & 2 deletions src/modules/market/components/market-page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class MarketPage extends Component {
selectedOutcome: PropTypes.object,
priceTimeSeries: PropTypes.array,
numPendingReports: PropTypes.number,
cancelOrder: PropTypes.func.isRequired
orderCancellation: PropTypes.object.isRequired
};
constructor(props) {
super(props);
Expand Down Expand Up @@ -68,7 +68,7 @@ export default class MarketPage extends Component {
key="market-open-orders"
userOpenOrdersSummary={p.market.userOpenOrdersSummary}
outcomes={p.market.outcomes}
cancelOrder={p.cancelOrder}
orderCancellation={p.orderCancellation}
/>
);
}
Expand Down
59 changes: 49 additions & 10 deletions src/modules/open-orders/components/open-order.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import classnames from 'classnames';
import ValueDenomination from '../../common/components/value-denomination';

const OpenOrder = (p) => (
<tr className={classnames('open-order', { 'is-disabled': p.isCancelling || p.isCancelled })}>
<tr className={classnames('open-order', { 'is-disabled': [p.cancellationStatuses.CANCELLING, p.cancellationStatuses.CANCELLED].includes(p.status) })}>
<td className="outcome-name">
{p.outcomeName}
</td>
Expand All @@ -22,13 +22,9 @@ const OpenOrder = (p) => (
<ValueDenomination {...p.avgPrice} />
</td>
<td className="cancel">
<button
className="button cancel-order-action"
disabled={p.isCancelling || p.isCancelled}
title="Cancel order"
onClick={(event) => { p.cancelOrder(p.id, p.marketID, p.type); }}
>Cancel</button>

{
renderCancelNode(p.id, p.marketID, p.type, p.status, p.cancellationStatuses, p.cancelOrder, p.abortCancelOrderConfirmation, p.showCancelOrderConfirmation)
}
</td>
</tr>
);
Expand All @@ -40,9 +36,52 @@ OpenOrder.propTypes = {
type: React.PropTypes.string.isRequired,
avgPrice: React.PropTypes.object.isRequired,
unmatchedShares: React.PropTypes.object.isRequired,
isCancelling: React.PropTypes.bool.isRequired,
isCancelled: React.PropTypes.bool.isRequired,
cancellationStatuses: React.PropTypes.object.isRequired,
status: React.PropTypes.string,
abortCancelOrderConfirmation: React.PropTypes.func.isRequired,
showCancelOrderConfirmation: React.PropTypes.func.isRequired,
cancelOrder: React.PropTypes.func.isRequired
};

function renderCancelNode(orderID, marketID, type, status, cancellationStatuses, cancelOrder, abortCancelOrderConfirmation, showCancelOrderConfirmation) {
switch (status) {
case cancellationStatuses.CANCELLATION_CONFIRMATION:
return (
<span>
<button
className="button cancel-order-abort-confirmation"
title="No, don't cancel order"
onClick={(event) => {
abortCancelOrderConfirmation(orderID, marketID, type);
}}
>No</button>
<button
className="button cancel-order-action"
title="Yes, cancel order"
onClick={(event) => {
cancelOrder(orderID, marketID, type);
}}
>Yes</button>
</span>
);
case cancellationStatuses.CANCELLING:
return 'Cancelling';
case cancellationStatuses.CANCELLED:
return null;
default:
return (
<button
className="button cancel-order-action"
title="Cancel order"
onClick={(event) => {
showCancelOrderConfirmation(orderID, marketID, type);
}}
>
Cancel
</button>
);
}

}

export default OpenOrder;
8 changes: 6 additions & 2 deletions src/modules/open-orders/components/open-orders-group.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ const OpenOrdersGroup = (p) => {
key={openOrder.id}
outcomeName={p.name}
{...openOrder}
cancelOrder={p.cancelOrder}
status={p.orderCancellation[openOrder.id]}
cancellationStatuses={p.orderCancellation.cancellationStatuses}
cancelOrder={p.orderCancellation.cancelOrder}
abortCancelOrderConfirmation={p.orderCancellation.abortCancelOrderConfirmation}
showCancelOrderConfirmation={p.orderCancellation.showCancelOrderConfirmation}
/>
))}
</tbody>
Expand All @@ -37,7 +41,7 @@ const OpenOrdersGroup = (p) => {
OpenOrdersGroup.propTypes = {
userOpenOrders: React.PropTypes.arrayOf(React.PropTypes.object).isRequired,
name: React.PropTypes.string.isRequired,
cancelOrder: React.PropTypes.func.isRequired
orderCancellation: React.PropTypes.object.isRequired
};

export default OpenOrdersGroup;
19 changes: 17 additions & 2 deletions src/modules/open-orders/less/open-order.less
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
text-align: right;
}
.cancel {
padding: 0.1em 0em;
padding: 0.1em 0;
text-align: left;
min-width: 4.6em;
font-size: 0.6em;

.cancel-order-action {
padding: 0;
Expand All @@ -38,7 +40,6 @@
text-align: left;
color: @color-danger-active;
background: transparent;
font-size: 0.6em;

&:before {
content: '\f00d';
Expand All @@ -58,6 +59,20 @@
background: transparent !important;
}
}

.cancel-order-abort-confirmation {
padding: 0;
height: unset;
line-height: unset;
text-align: left;
background-color: transparent;
color: inherit;
margin-right: 1.4em;

&:hover {
font-weight: 700;
}
}
}

.open-order {
Expand Down
4 changes: 2 additions & 2 deletions src/selectors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import activePage from './selectors/active-page';
import authForm from './selectors/auth-form';
import { cancelOrder } from './selectors/cancel-order';
import orderCancellation from './selectors/order-cancellation';
import createMarketForm from './selectors/create-market-form';
import filters from './selectors/filters';
import keywords from './selectors/keywords';
Expand All @@ -19,7 +19,7 @@ import url from './selectors/url';
const selectors = {
activePage,
authForm,
cancelOrder,
orderCancellation,
createMarketForm,
filters,
keywords,
Expand Down
27 changes: 0 additions & 27 deletions src/selectors/cancel-order.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/selectors/markets.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,6 @@ function makeMarkets(numMarkets = 50) {
id: `${m.id}${outcome.id}order${index}`,
type: parseInt(index, 10) % 2 === 1 ? 'buy' : 'sell',
marketID: m.id,
isCancelling: false,
isCancelled: false,
avgPrice: makeNumber(parseFloat(Math.random().toFixed(2)), 'eth'),
unmatchedShares: makeNumber(parseInt(Math.random() * 10, 10), 'shares'),
outcome: outcomeID,
Expand Down
39 changes: 39 additions & 0 deletions src/selectors/order-cancellation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Author: priecint
*/

export default {
cancellationStatuses: {
CANCELLATION_CONFIRMATION: 'CANCELLATION_CONFIRMATION',
CANCELLING: 'CANCELLING',
CANCELLED: 'CANCELLED',
CANCELLATION_FAILED: 'CANCELLATION_FAILED'
},
cancelOrder: orderID => {
require('../selectors').orderCancellation[orderID] = require('../selectors').orderCancellation.cancellationStatuses.CANCELLING;
require('../selectors').update({});

setTimeout(() => {
require('../selectors').markets.forEach((market) => {
market.outcomes.forEach(outcome => {
const order = outcome.userOpenOrders.find(openOrder => openOrder.id === orderID);
if (order != null) {
const index = outcome.userOpenOrders.findIndex(openOrder => openOrder.id === orderID);
outcome.userOpenOrders.splice(index, 1);
require('../selectors').update({});
}
});
});
}, 2000);
},
showCancelOrderConfirmation: orderID => {
setTimeout(() => {
require('../selectors').orderCancellation[orderID] = require('../selectors').orderCancellation.cancellationStatuses.CANCELLATION_CONFIRMATION;
require('../selectors').update({});
}, 300);
},
abortCancelOrderConfirmation: orderID => {
delete require('../selectors').orderCancellation[orderID];
require('../selectors').update({});
}
};
9 changes: 0 additions & 9 deletions test/assertions/cancel-order.js

This file was deleted.

10 changes: 0 additions & 10 deletions test/assertions/market.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,6 @@ export default function (market) {
assert.isObject(openOrder.unmatchedShares);
assertFormattedNumber(openOrder.unmatchedShares);
});

it(`market.outcomes[${i}].userOpenOrders[${j}].isCancelling`, () => {
assert.isDefined(openOrder.isCancelling);
assert.isBoolean(openOrder.isCancelling);
});

it(`market.outcomes[${i}].userOpenOrders[${j}].isCancelled`, () => {
assert.isDefined(openOrder.isCancelled);
assert.isBoolean(openOrder.isCancelled);
});
});
});
});
Expand Down
31 changes: 31 additions & 0 deletions test/assertions/order-cancellation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { assert } from 'chai';

export default function (orderCancellation) {
describe('augur-ui-react-components orderCancellation', () => {
it('orderCancellation', () => {
assert.isObject(orderCancellation);
});

it('orderCancellation.cancelOrder', () => {
assert.isFunction(orderCancellation.cancelOrder);
});

it('orderCancellation.abortCancelOrderConfirmation', () => {
assert.isFunction(orderCancellation.abortCancelOrderConfirmation);
});

it('orderCancellation.showCancelOrderConfirmation', () => {
assert.isFunction(orderCancellation.showCancelOrderConfirmation);
});

it('orderCancellation.cancellationStatuses', () => {
assert.isObject(orderCancellation.cancellationStatuses);
assert.deepEqual(orderCancellation.cancellationStatuses, {
CANCELLATION_CONFIRMATION: 'CANCELLATION_CONFIRMATION',
CANCELLING: 'CANCELLING',
CANCELLED: 'CANCELLED',
CANCELLATION_FAILED: 'CANCELLATION_FAILED'
});
});
});
};

0 comments on commit 1b8b9f3

Please sign in to comment.