From 5a9e2ecfc16d13ea6aa01925110b91a837cce0a8 Mon Sep 17 00:00:00 2001 From: priecint Date: Tue, 26 Jul 2016 03:43:25 +0200 Subject: [PATCH] #29 Move cancelOrder selector to separate file --- src/selectors.js | 28 ++-------------------------- src/selectors/cancel-order.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 26 deletions(-) create mode 100644 src/selectors/cancel-order.js diff --git a/src/selectors.js b/src/selectors.js index c8aa066e..e5f18a8c 100644 --- a/src/selectors.js +++ b/src/selectors.js @@ -1,5 +1,6 @@ import activePage from './selectors/active-page'; import authForm from './selectors/auth-form'; +import { cancelOrder } from './selectors/cancel-order'; import createMarketForm from './selectors/create-market-form'; import filters from './selectors/filters'; import keywords from './selectors/keywords'; @@ -18,6 +19,7 @@ import url from './selectors/url'; const selectors = { activePage, authForm, + cancelOrder, createMarketForm, filters, keywords, @@ -66,32 +68,6 @@ selectors.selectedOutcome = { selectedOutcomeID: null }; -selectors.cancelOrder = (orderId) => { - setTimeout(() => { - selectors.markets.forEach((market) => { - market.outcomes.forEach(outcome => { - const order = outcome.userOpenOrders.find(openOrder => openOrder.id === orderId); - if (order != null) { - order.isCancelling = true; - module.exports.update({}); - } - }); - }); - setTimeout(() => { - 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); - module.exports.update({}); - } - }); - }); - }, 2000); - }, 1); -}; - selectors.searchSort.onChangeSort = (prop, isDesc) => { let isDescending = isDesc; if (isDesc !== false && isDesc !== true) { diff --git a/src/selectors/cancel-order.js b/src/selectors/cancel-order.js new file mode 100644 index 00000000..f20288f3 --- /dev/null +++ b/src/selectors/cancel-order.js @@ -0,0 +1,29 @@ +/* + * Author: priecint + */ + +export const cancelOrder = orderId => { + return setTimeout(() => { + require('../selectors').markets.forEach((market) => { + market.outcomes.forEach(outcome => { + const order = outcome.userOpenOrders.find(openOrder => openOrder.id === orderId); + if (order != null) { + order.isCancelling = true; + 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); + }, 1); +};