diff --git a/Canvas.js b/Canvas.js index 0190e8448..0e720bd4a 100644 --- a/Canvas.js +++ b/Canvas.js @@ -107,7 +107,7 @@ function newCanvas () { } } - function initialize (callBackFunction) { + async function initialize (callBackFunction) { try { if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') } @@ -118,7 +118,7 @@ function newCanvas () { /* Instantiate all the children spaces of Canvas object */ thisObject.topSpace = newTopSpace() - thisObject.topSpace.initialize() + await thisObject.topSpace.initialize() thisObject.bottomSpace = newBottomSpace() thisObject.bottomSpace.initialize() diff --git a/Panels/ProductsPanel.js b/Panels/ProductsPanel.js index 924ca6c96..3cd7c8faf 100644 --- a/Panels/ProductsPanel.js +++ b/Panels/ProductsPanel.js @@ -59,7 +59,7 @@ for (let j = 0; j < devTeam.bots.length; j++) { let bot = devTeam.bots[j] - if (bot.type !== 'Indicator') { continue } + if (bot.type !== 'Indicator' && bot.cloneId === undefined) { continue } if (bot.products !== undefined) { for (let k = 0; k < bot.products.length; k++) { diff --git a/Spaces/TopSpace.js b/Spaces/TopSpace.js index 04ac158b9..f5d30814d 100644 --- a/Spaces/TopSpace.js +++ b/Spaces/TopSpace.js @@ -25,7 +25,7 @@ function newTopSpace () { return thisObject - function initialize () { + async function initialize () { let sharedStatus = { currentDevTeamIndex: 0, currentEventIndex: 0, @@ -36,8 +36,9 @@ function newTopSpace () { } thisObject.login = newLogin() - thisObject.login.initialize(sharedStatus, onLoginInitialized) + await thisObject.login.initialize(sharedStatus) +/* thisObject.companyLogo = newCompanyLogo() thisObject.endUser = newEndUser() thisObject.currentBot = newCurrentBot() @@ -45,18 +46,17 @@ function newTopSpace () { thisObject.currentStartMode = newCurrentStartMode() thisObject.currentEvent = newCurrentEvent() thisObject.devTeam = newDevTeam() - +*/ window.canvasApp.eventHandler.listenToEvent('Browser Resized', resize) - - function onLoginInitialized () { - thisObject.companyLogo.initialize() - thisObject.endUser.initialize() - thisObject.currentBot.initialize(sharedStatus) - thisObject.currentProcess.initialize(sharedStatus) - thisObject.currentStartMode.initialize(sharedStatus) - thisObject.currentEvent.initialize(sharedStatus) - thisObject.devTeam.initialize(sharedStatus) - } +/* + thisObject.companyLogo.initialize() + thisObject.endUser.initialize() + thisObject.currentBot.initialize(sharedStatus) + thisObject.currentProcess.initialize(sharedStatus) + thisObject.currentStartMode.initialize(sharedStatus) + thisObject.currentEvent.initialize(sharedStatus) + thisObject.devTeam.initialize(sharedStatus) +*/ } function resize () { @@ -69,6 +69,7 @@ function newTopSpace () { function getContainer (point) { let container + return container = thisObject.companyLogo.getContainer(point) if (container !== undefined) { return container } @@ -103,6 +104,8 @@ function newTopSpace () { thisObject.container.frame.draw(false, false) drawBackground() + return + thisObject.companyLogo.draw() thisObject.endUser.draw() thisObject.devTeam.draw() diff --git a/TopSpace/CurrentBot.js b/TopSpace/CurrentBot.js index 04f02ba92..845875d7c 100644 --- a/TopSpace/CurrentBot.js +++ b/TopSpace/CurrentBot.js @@ -28,6 +28,8 @@ function newCurrentBot () { function initialize (pSharedStatus) { sharedStatus = pSharedStatus + if (window.USER_PROFILE === undefined) { return } + if (window.USER_PROFILE.devTeams.length === 0) { window.CURRENT_BOT_DISPLAY_NAME = NOT_FOUND } else { diff --git a/TopSpace/Login.js b/TopSpace/Login.js index df00ee4ff..748b40ea7 100644 --- a/TopSpace/Login.js +++ b/TopSpace/Login.js @@ -26,7 +26,7 @@ function newLogin () { return thisObject - function initialize (pSharedStatus, callBackFunction) { + async function initialize (pSharedStatus) { const accessToken = window.localStorage.getItem('access_token') let user = window.localStorage.getItem('user') @@ -296,7 +296,21 @@ function newLogin () { }) .then(response => { window.localStorage.setItem('userClones', JSON.stringify(response.data.operations_Clones)) - resolve({ teams: response.data.operations_Clones}) + let clones = response.data.operations_Clones + for (let i = 0; i < clones.length; i++) { + let clone = clones[i] + if (clone.botType === 'Trading') { + let teamSlug = clone.teamName.toLowerCase() + teamSlug = teamSlug.replace(' ', '-') + let devTeam = ecosystem.getTeam(teamSlug) + let bot = ecosystem.getBot(devTeam, clone.botSlug) + if (bot !== undefined) { + bot.cloneId = clone.id + } + } + } + + resolve({ clones: response.data.operations_Clones}) }) .catch(error => { console.log('apolloClient error getting user clones', error) @@ -308,42 +322,42 @@ function newLogin () { // To avoid race conditions, add asynchronous fetches to array let fetchDataPromises = [] - fetchDataPromises.push(getUser(), getTeamByOwner(), getCurrentEvents(), getClones()) + fetchDataPromises.push(getUser(), getTeamByOwner(), getCurrentEvents(), getClones(), authenticateUser()) // When all asynchronous fetches resolve, authenticate user or throw error. - Promise.all(fetchDataPromises).then(result => { - /* this is the time to authenticate the user at AAWeb */ + await Promise.all(fetchDataPromises).then(result => { - authenticateUser() }, err => { - console.error('fetchData error', err) + console.error('[ERROR] Login -> GraphQL Fetch Error -> err = ', err) }) thisObject.container.eventHandler.listenToEvent('onMouseClick', onClick) - function authenticateUser () { + async function authenticateUser () { if (sessionToken === undefined) { sessionToken = '' } let path = window.canvasApp.urlPrefix + 'AABrowserAPI/authenticateUser/' + sessionToken - callServer(undefined, path, onServerReponded) + return new Promise( + function (resolve, reject) { + callServer(undefined, path, (result) => { + let responseFromServer = JSON.parse(result) - function onServerReponded (pResponseFromServer) { - let responseFromServer = JSON.parse(pResponseFromServer) + err = responseFromServer.err - err = responseFromServer.err + if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { + console.log('Please make sure you create a new team!') + reject(err) + } - if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { - console.log('Please make sure you create a new team!') - return - } + window.USER_PROFILE = responseFromServer.userProfile + window.localStorage.setItem('sessionToken', sessionToken) - window.USER_PROFILE = responseFromServer.userProfile - window.localStorage.setItem('sessionToken', sessionToken) - - currentLabel = 'Logged In' - callBackFunction() - } + currentLabel = 'Logged In' + resolve() + }) + } + ) } }