Skip to content

Commit

Permalink
Merge pull request #50 from bitshares/36-open-orders
Browse files Browse the repository at this point in the history
36-open-orders
  • Loading branch information
roma219 committed Nov 29, 2018
2 parents f01eada + 5d2c91a commit d04102d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/modules/acc/getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const getters = {
return nonZeroBalances;
},
isLocked: state => {
return !state.wallet.aesPrivate && (!state.keys.active || !state.keys.owner);;
return !state.wallet.aesPrivate && (!state.keys.active || !state.keys.owner);
},
isLoggedIn: state => !!state.userId,
isValidPassword: state => {
Expand Down
27 changes: 27 additions & 0 deletions src/modules/operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,33 @@ const actions = {

const getters = {
getOperations: state => state.list,
getActiveOrders: state => {
const openedOrder = state.list.filter(x => x.type === 'limit_order_create');
const canceledOrders = state.list.filter(x => x.type === 'limit_order_cancel');
const filledOrders = state.list.filter(x => x.type === 'fill_order');
const notCanceledOrders = openedOrder.filter(x => !canceledOrders.some(y => y.orderId === x.orderId));
notCanceledOrders.forEach(notCancelOrder => {
let percentFilled = 0;
filledOrders.forEach(filledOrder => {
if (filledOrder.orderId === notCancelOrder.orderId) {
const remain = notCancelOrder.payload.amount_to_sell.amount - filledOrder.payload.pays.amount;
percentFilled = +(
((notCancelOrder.payload.amount_to_sell.amount - remain)
/ notCancelOrder.payload.amount_to_sell.amount)
* 100);
}
});
if (percentFilled < 100) {
notCancelOrder.percentFilled = percentFilled;
}
});


const activeOrders = notCanceledOrders.filter(
x => Object.prototype.hasOwnProperty.call(x, 'percentFilled')
);
return activeOrders;
},
isFetching: state => state.pending,
isError: state => state.error,
isSubscribed: state => state.subscribed
Expand Down
16 changes: 15 additions & 1 deletion src/services/api/operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,23 @@ const Operations = {
let isBid = false;
let otherUserName = null;

let orderId;
if (operationType === 'fill_order' || operationType === 'limit_order_create') {
isBid = await Operations._checkIfBidOperation(operation);
}

if (operationType === 'limit_order_create') {
[, orderId] = operation.result;
}

if (operationType === 'limit_order_cancel') {
orderId = operation.op[1].order;
}

if (operationType === 'fill_order') {
orderId = operation.op[1].order_id;
}

if (operationType === 'transfer') {
otherUserName = await Operations._getOperationOtherUserName(userId, payload);
}
Expand All @@ -71,7 +84,8 @@ const Operations = {
payload,
date,
buyer: isBid,
otherUserName
otherUserName,
orderId
};
},

Expand Down

0 comments on commit d04102d

Please sign in to comment.