From d1360525e52f4e7290c0b3e7705c503820fb2b54 Mon Sep 17 00:00:00 2001 From: Barry Low Date: Fri, 24 May 2019 09:20:57 -0700 Subject: [PATCH 1/2] Auto-create team + fb --- client/src/auth/index.js | 47 +++++++++++++++++++++++++++++++++++- client/src/graphql/apollo.js | 2 +- client/src/utils/log.js | 2 +- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/client/src/auth/index.js b/client/src/auth/index.js index e616758b2..a84861444 100644 --- a/client/src/auth/index.js +++ b/client/src/auth/index.js @@ -2,7 +2,7 @@ import Auth0Lock from 'auth0-lock' import gql from 'graphql-tag' import { getItem, setItem } from '../utils/local-storage' -import { validObject, deleteCookie } from '../utils/js-helpers' +import { validObject, deleteCookie, slugify, isEmpty } from '../utils/js-helpers' import Log from '../utils/log' import { client } from '../graphql/apollo' @@ -28,6 +28,25 @@ const VERIFY_TEAM_INVITE = gql` } } ` +const GET_TEAMS_BY_OWNER = gql` + query teamsByOwnerQuery { + teams_TeamsByOwner { + id + name + slug + } + } +` + +const CREATE_TEAM = gql` + mutation CreateTeamMutation($name: String!, $slug: String!, $botName: String!, $botSlug: String!) { + teams_CreateTeam(name: $name, slug: $slug, botName: $botName, botSlug: $botSlug) { + id + name + slug + } + } +` export const defaultOptions = { oidcConformant: true, @@ -203,6 +222,32 @@ class Auth { authId: response.data.users_Authenticate.authId, alias: response.data.users_Authenticate.alias } + if (validObject(user, 'alias')) { + Log.info(user.alias) + const existingTeam = await client.query({ + query: GET_TEAMS_BY_OWNER + }) + Log.info(existingTeam) + Log.info(existingTeam.data.teams_TeamsByOwner) + if (validObject(existingTeam.data, 'teams_TeamsByOwner') && isEmpty(existingTeam.data.teams_TeamsByOwner)) { + const slug = slugify(user.alias) + const newTeam = await client.mutate({ + mutation: CREATE_TEAM, + variables: { + name: slug, + slug: slug, + botName: `bot-${slug}`, + botSlug: `bot-${slug}` + } + }) + Log.info(newTeam) + Log.info(newTeam.data.teams_CreateTeam) + if (!validObject(newTeam.data, 'teams_CreateTeam') || isEmpty(newTeam.data.teams_CreateTeam)) { + throw newTeam.data.error + } + Log.info('Team and Bot Creation Success') + } + } setItem('user', JSON.stringify(user)) window.location.href = '/' return response.data diff --git a/client/src/graphql/apollo.js b/client/src/graphql/apollo.js index 283cfc868..7a194d4cd 100644 --- a/client/src/graphql/apollo.js +++ b/client/src/graphql/apollo.js @@ -76,7 +76,7 @@ const defaultOptions = { errorPolicy: 'all' }, query: { - fetchPolicy: 'cache-and-network', + fetchPolicy: 'network-only', errorPolicy: 'all' }, mutate: { diff --git a/client/src/utils/log.js b/client/src/utils/log.js index d05bebc8a..69263820d 100644 --- a/client/src/utils/log.js +++ b/client/src/utils/log.js @@ -1,6 +1,6 @@ import debug from 'debug' -const BASE = 'advanced-algos' +const BASE = 'superalgos' const COLOURS = { info: 'blue', warn: 'orange', From c1656bbf332a083c8900a24ca390173ab8aa060b Mon Sep 17 00:00:00 2001 From: Barry Low Date: Fri, 24 May 2019 09:39:38 -0700 Subject: [PATCH 2/2] Simplify Menu --- client/src/views/home/index.js | 41 ++++------------------ client/src/views/layout/header/LoggedIn.js | 1 + client/src/views/layout/header/imports.js | 8 +++-- client/src/views/layout/header/index.js | 3 -- 4 files changed, 13 insertions(+), 40 deletions(-) diff --git a/client/src/views/home/index.js b/client/src/views/home/index.js index 9ecfbfa53..ebc655054 100644 --- a/client/src/views/home/index.js +++ b/client/src/views/home/index.js @@ -20,35 +20,14 @@ class Home extends Component { if (this.state.user !== undefined && this.state.user !== null) {} return ( - {this.state.user !== undefined && this.state.user !== null && ( - -
- - - - - - - -
-
- )} - {(this.state.user === undefined || this.state.user === null) && ( - - )} +
Welcome to the Superalgos Platform! - TRY OUT THE STRATEGIZER DEMO
Before you begin, please be aware this is an alpha stage deployment. @@ -56,20 +35,12 @@ class Home extends Component { However, you may encounter occasional instability and errors. - At this early stage, the focus of the Superalgos Platform is the Strategizer, a tool directed mostly at traders. To try out the Demo version hosted here you will need to Sign Up / Login. Once you are logged in, you will find basic instructions on how to proceed, at this home page (click the Superalgos logo to return to this home page).
- - If you are a developer, trying out the Strategizer may open your eyes as of what may be achieved with the - Strategizer and the Superalgos Platform in general. - - - The Strategizer is conceived to work with as many indicators and pre programmed strategies as developers are willing to program. - If you wish to set up your own indicators and strategies, please get in touch with us and we'll show you how (give us a shout in the Community Telegram) diff --git a/client/src/views/layout/header/LoggedIn.js b/client/src/views/layout/header/LoggedIn.js index 3c346c9fa..c638639e8 100644 --- a/client/src/views/layout/header/LoggedIn.js +++ b/client/src/views/layout/header/LoggedIn.js @@ -34,6 +34,7 @@ export const LoggedIn = props => { toggleMenuOpen(42, true)}> {displayName}
  • closeAll()}> Your Profile
  • +
  • closeAll()}> Your Team
  • auth.logout()}> Logout
  • Docs
  • Exit Platform
  • diff --git a/client/src/views/layout/header/imports.js b/client/src/views/layout/header/imports.js index 3f2f7aae0..1a8ad21df 100644 --- a/client/src/views/layout/header/imports.js +++ b/client/src/views/layout/header/imports.js @@ -25,6 +25,7 @@ const usersMenus = { ] } +/* const teamsMenus = { title: 'Teams', to: '/teams', @@ -36,6 +37,7 @@ const teamsMenus = { { title: 'Report a Bug', to: 'https://github.com/Superalgos/TeamsModule/issues/new', icon: BugReport, externalLink: true } ] } +*/ const eventsMenus = { title: 'Events', @@ -85,6 +87,7 @@ const cockpitMenus = { ] } +/* const strategizerMenus = { title: 'Strategizer', to: '/strategizer', @@ -92,14 +95,15 @@ const strategizerMenus = { authenticated: true, submenus: [] } +*/ const allMenus = [ usersMenus, - teamsMenus, + // teamsMenus, eventsMenus, keyvaultMenus, operationsMenus, - strategizerMenus, + // strategizerMenus, cockpitMenus ] diff --git a/client/src/views/layout/header/index.js b/client/src/views/layout/header/index.js index 224129f4a..39bc0528c 100644 --- a/client/src/views/layout/header/index.js +++ b/client/src/views/layout/header/index.js @@ -115,9 +115,6 @@ class Header extends Component {