From eb59fab26098fc2a9503083ce9c681c4d1005e41 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 12 May 2019 14:26:19 +0200 Subject: [PATCH] Access to Strategy System only when logged in --- Globals.js | 2 +- Spaces/BottomSpace.js | 13 +++++++++++-- Spaces/StrategySpace.js | 3 ++- StrategySpace/TradingSystemWorkspace.js | 13 +++++++++---- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Globals.js b/Globals.js index 6e72065c2..79694da26 100644 --- a/Globals.js +++ b/Globals.js @@ -121,7 +121,7 @@ function convertTimePeriodToName(pTimePeriod) { window.AT_BREAKPOINT = false; - +const LOGGED_IN_USER_LOCAL_STORAGE = "xuser" const USDT_BTC_HTH = 19900; // This is needed to know the scale of the market time line. const WIDHTER_VOLUME_BAR_BASE_FACTOR = 2.5; diff --git a/Spaces/BottomSpace.js b/Spaces/BottomSpace.js index 5e6ae3b05..3e03f4c77 100644 --- a/Spaces/BottomSpace.js +++ b/Spaces/BottomSpace.js @@ -60,6 +60,13 @@ thisObject.status = 'MIDDLE' + let user = window.localStorage.getItem(LOGGED_IN_USER_LOCAL_STORAGE) + if (user !== null) { // Only if user is logged in + thisObject.container.isDraggeable = true + } else { + thisObject.container.isDraggeable = false + } + if (thisObject.container.frame.position.y > browserCanvas.height * 99.5 / 100 - BOTTOM_SPACE_HEIGHT) { thisObject.container.frame.position.y = browserCanvas.height - BOTTOM_SPACE_HEIGHT thisObject.status = 'BOTTOM' @@ -204,7 +211,10 @@ browserCanvasContext.closePath() browserCanvasContext.fill() - arrow() + let user = window.localStorage.getItem(LOGGED_IN_USER_LOCAL_STORAGE) + if (user !== null) { // Only if user is logged in + arrow() + } } function arrow () { @@ -295,4 +305,3 @@ browserCanvasContext.stroke() } } - diff --git a/Spaces/StrategySpace.js b/Spaces/StrategySpace.js index 0d4264972..86bc7b275 100644 --- a/Spaces/StrategySpace.js +++ b/Spaces/StrategySpace.js @@ -26,7 +26,8 @@ function newStrategySpace () { thisObject.tradingSystemWorkspace = newTradingSystemWorkspace() // thisObject.tradingSystemWorkspace.container.connectToParent(thisObject.sidePanel.container, true, true) - await thisObject.tradingSystemWorkspace.initialize() + thisObject.tradingSystemWorkspace.initialize() + await thisObject.tradingSystemWorkspace.loadFromStrategyzer() // thisObject.sidePanel.areas.push(thisObject.tradingSystemWorkspace) } diff --git a/StrategySpace/TradingSystemWorkspace.js b/StrategySpace/TradingSystemWorkspace.js index a8ee995e4..f5be5854a 100644 --- a/StrategySpace/TradingSystemWorkspace.js +++ b/StrategySpace/TradingSystemWorkspace.js @@ -9,6 +9,7 @@ function newTradingSystemWorkspace () { isDeployed: false, strategies: undefined, container: undefined, + loadFromStrategyzer: loadFromStrategyzer, deploydTradingSystem: deploydTradingSystem, draw: draw, getContainer: getContainer, @@ -33,10 +34,14 @@ function newTradingSystemWorkspace () { return thisObject async function initialize () { + + } + + async function loadFromStrategyzer () { try { const accessToken = window.localStorage.getItem('xaccess_token') - let user = window.localStorage.getItem('xuser') + let user = window.localStorage.getItem(LOGGED_IN_USER_LOCAL_STORAGE) if (user === null) { // if there is no user that means that we are logged off, which means this object can not be used. return @@ -100,7 +105,7 @@ function newTradingSystemWorkspace () { resolve({ strategies: response.data.strategizer_StrategyByFb.subStrategies}) }) .catch(error => { - console.log('apolloClient error getting user strategies', error.graphQLErrors, error.stack) + if (ERROR_LOG === true) { logger.write('[ERROR] ApolloClient error getting user strategies -> err = ' + err.stack) } reject(error) }) }) @@ -115,10 +120,10 @@ function newTradingSystemWorkspace () { await Promise.all(fetchDataPromises).then(result => { }, err => { - console.error('[ERROR] Login -> GraphQL Fetch Error -> err = ', err.stack) + if (ERROR_LOG === true) { logger.write('[ERROR] GraphQL Fetch Error -> err = ' + err.stack) } }) } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err.stack) } + if (ERROR_LOG === true) { logger.write('[ERROR] loadFromStrategyzer -> err = ' + err.stack) } } }