From 2904585abcbbaf039c3e92b2dfe7cfce42bff88b Mon Sep 17 00:00:00 2001 From: ololokiras Date: Wed, 28 Nov 2018 01:40:23 +0500 Subject: [PATCH 1/3] add getter for open orders with percent --- src/modules/operations.js | 25 +++++++++++++++++++++++++ src/services/api/operations.js | 19 ++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/modules/operations.js b/src/modules/operations.js index b465ef5..c7d5d5f 100644 --- a/src/modules/operations.js +++ b/src/modules/operations.js @@ -1,4 +1,5 @@ import Vue from 'vue'; +import { ChainTypes } from 'bitsharesjs'; import * as types from '../mutations'; import API from '../services/api'; import Subscriptions from '../services/api/subscriptions'; @@ -98,6 +99,30 @@ const actions = { const getters = { getOperations: state => state.list, + getActiveOrders: state => { + const openOrders = state.list.filter(x => x.type === 'limit_order_create'); + const cancelOrders = state.list.filter(x => x.type === 'limit_order_cancel'); + const filledOrders = state.list.filter(x => x.type === 'fill_order'); + const notCanceledOrders = openOrders.filter(x => !cancelOrders.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) + .toFixed(2); + } + }); + if (percentFilled < 100) { + notCancelOrder.percentFilled = percentFilled; + } + }); + const activeOrders = notCanceledOrders.filter(x => x.hasOwnProperty('percentFilled')); + return activeOrders; + }, isFetching: state => state.pending, isError: state => state.error, isSubscribed: state => state.subscribed diff --git a/src/services/api/operations.js b/src/services/api/operations.js index 6b7fc1b..ccc0aa1 100644 --- a/src/services/api/operations.js +++ b/src/services/api/operations.js @@ -57,13 +57,29 @@ 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[1]; + } + + + 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); } + // console.log(operation) return { id: operation.id, @@ -71,7 +87,8 @@ const Operations = { payload, date, buyer: isBid, - otherUserName + otherUserName, + orderId }; }, From cc0decbe167eb0f827f1801d395e809a456d3314 Mon Sep 17 00:00:00 2001 From: ololokiras Date: Wed, 28 Nov 2018 01:43:17 +0500 Subject: [PATCH 2/3] lil clean --- src/services/api/operations.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/services/api/operations.js b/src/services/api/operations.js index ccc0aa1..68376b6 100644 --- a/src/services/api/operations.js +++ b/src/services/api/operations.js @@ -66,12 +66,10 @@ const Operations = { orderId = operation.result[1]; } - if (operationType === 'limit_order_cancel') { orderId = operation.op[1].order; } - if (operationType === 'fill_order') { orderId = operation.op[1].order_id; } @@ -79,7 +77,6 @@ const Operations = { if (operationType === 'transfer') { otherUserName = await Operations._getOperationOtherUserName(userId, payload); } - // console.log(operation) return { id: operation.id, From 5d2c91a50ea54647884dad270d8a30241032e468 Mon Sep 17 00:00:00 2001 From: ololokiras Date: Thu, 29 Nov 2018 16:56:14 +0500 Subject: [PATCH 3/3] linted --- src/modules/acc/getters.js | 2 +- src/modules/operations.js | 16 +++++++++------- src/services/api/operations.js | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/modules/acc/getters.js b/src/modules/acc/getters.js index 989d13e..078685d 100644 --- a/src/modules/acc/getters.js +++ b/src/modules/acc/getters.js @@ -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 => { diff --git a/src/modules/operations.js b/src/modules/operations.js index c7d5d5f..5da9e63 100644 --- a/src/modules/operations.js +++ b/src/modules/operations.js @@ -1,5 +1,4 @@ import Vue from 'vue'; -import { ChainTypes } from 'bitsharesjs'; import * as types from '../mutations'; import API from '../services/api'; import Subscriptions from '../services/api/subscriptions'; @@ -100,10 +99,10 @@ const actions = { const getters = { getOperations: state => state.list, getActiveOrders: state => { - const openOrders = state.list.filter(x => x.type === 'limit_order_create'); - const cancelOrders = state.list.filter(x => x.type === 'limit_order_cancel'); + 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 = openOrders.filter(x => !cancelOrders.some(y => y.orderId === x.orderId)); + const notCanceledOrders = openedOrder.filter(x => !canceledOrders.some(y => y.orderId === x.orderId)); notCanceledOrders.forEach(notCancelOrder => { let percentFilled = 0; filledOrders.forEach(filledOrder => { @@ -112,15 +111,18 @@ const getters = { percentFilled = +( ((notCancelOrder.payload.amount_to_sell.amount - remain) / notCancelOrder.payload.amount_to_sell.amount) - * 100) - .toFixed(2); + * 100); } }); if (percentFilled < 100) { notCancelOrder.percentFilled = percentFilled; } }); - const activeOrders = notCanceledOrders.filter(x => x.hasOwnProperty('percentFilled')); + + + const activeOrders = notCanceledOrders.filter( + x => Object.prototype.hasOwnProperty.call(x, 'percentFilled') + ); return activeOrders; }, isFetching: state => state.pending, diff --git a/src/services/api/operations.js b/src/services/api/operations.js index 68376b6..e2c4221 100644 --- a/src/services/api/operations.js +++ b/src/services/api/operations.js @@ -63,7 +63,7 @@ const Operations = { } if (operationType === 'limit_order_create') { - orderId = operation.result[1]; + [, orderId] = operation.result; } if (operationType === 'limit_order_cancel') {