From 866911abfe66c2f5c1861686b7ed3e6538b899ce Mon Sep 17 00:00:00 2001 From: NAmorim Date: Wed, 24 Nov 2021 16:31:52 +0000 Subject: [PATCH 1/4] Contribution - Automatic fork creation - Setup of basic liquidity profile --- Platform/Client/githubServer.js | 46 +++++++++++++++ Platform/Client/httpInterface.js | 11 ++++ .../Function-Libraries/ProfileConstructor.js | 57 ++++++++++++++++++- 3 files changed, 113 insertions(+), 1 deletion(-) diff --git a/Platform/Client/githubServer.js b/Platform/Client/githubServer.js index eff3ebc8d..f245239f1 100644 --- a/Platform/Client/githubServer.js +++ b/Platform/Client/githubServer.js @@ -4,6 +4,7 @@ exports.newGithubServer = function newGithubServer() { getGithubStars: getGithubStars, getGithubWatchers: getGithubWatchers, getGithubForks: getGithubForks, + createGithubFork: createGithubFork, mergePullRequests: mergePullRequests, initialize: initialize, finalize: finalize, @@ -162,6 +163,51 @@ exports.newGithubServer = function newGithubServer() { } } + async function createGithubFork(repository, username, token) { + try { + username = unescape(username) + token = unescape(token) + + let error + + await doGithub() + + async function doGithub() { + try { + //const repo = 'Superalgos' + //const owner = username + const { Octokit } = SA.nodeModules.octokit + const octokit = new Octokit({ + auth: token, + userAgent: 'Superalgos ' + SA.version + }) + + await octokit.repos.createFork({ + owner: 'Superalgos', + repo: "Superalgos" + }) + } catch (err) { + if (err === undefined) { return } + console.log('[ERROR] Github Server -> createGithubFork -> doGithub -> err.stack = ' + err.stack) + } + } + } catch (err) { + console.log('[ERROR] Github Server -> createGithubFork -> Method call produced an error.') + console.log('[ERROR] Github Server -> createGithubFork -> err.stack = ' + err.stack) + console.log('[ERROR] Github Server -> createGithubFork -> repository = ' + repository) + console.log('[ERROR] Github Server -> createGithubFork -> username = ' + username) + console.log('[ERROR] Github Server -> createGithubFork -> token starts with = ' + token.substring(0, 10) + '...') + console.log('[ERROR] Github Server -> createGithubFork -> token ends with = ' + '...' + token.substring(token.length - 10)) + + let error = { + result: 'Fail Because', + message: err.message, + stack: err.stack + } + return error + } + } + async function mergeGithubPullRequests(commitMessage, username, token) { try { commitMessage = unescape(commitMessage) diff --git a/Platform/Client/httpInterface.js b/Platform/Client/httpInterface.js index d58c87151..e54dddf6f 100644 --- a/Platform/Client/httpInterface.js +++ b/Platform/Client/httpInterface.js @@ -1286,6 +1286,17 @@ exports.newHttpInterface = function newHttpInterface() { SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify(serverResponse), httpResponse) return } + case 'createGithubFork': { + + let serverResponse = await PL.servers.GITHUB_SERVER.createGithubFork( + params.repository, + params.username, + params.token + ) + + SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify(serverResponse), httpResponse) + return + } case 'mergePullRequests': { let serverResponse = await PL.servers.GITHUB_SERVER.mergePullRequests( diff --git a/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js b/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js index 285c171e5..6f742ceda 100644 --- a/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js +++ b/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js @@ -125,6 +125,60 @@ function newGovernanceFunctionLibraryProfileConstructor() { UI.projects.foundations.spaces.designSpace.workspace.workspaceNode.rootNodes ) /* + Set up a basic profile to start receiving benefits + */ + let finServices = UI.projects.visualScripting.functionLibraries.uiObjectsFromNodes.addUIObject(userProfile.tokenPowerSwitch, "Financial Programs", userProfile) + finServices.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 + finServices.payload.uiObject.menu.internalClick("Add Financial Program") + + let stakeProg = UI.projects.visualScripting.functionLibraries.uiObjectsFromNodes.addUIObject(finServices, "Staking Program", userProfile) + stakeProg.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 + stakeProg.payload.uiObject.menu.internalClick("Add Tokens Awarded") + + let liquidProgs = UI.projects.visualScripting.functionLibraries.uiObjectsFromNodes.addUIObject(userProfile.tokenPowerSwitch, "Liquidity Programs", userProfile) + liquidProgs.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 + liquidProgs.payload.uiObject.menu.internalClick('Add Liquidity Program') + + let liquidProg = UI.projects.visualScripting.functionLibraries.uiObjectsFromNodes.addUIObject(liquidProgs, "Liquidity Program", userProfile) + liquidProgs.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 + liquidProgs.payload.uiObject.menu.internalClick('Add Tokens Awarded') + + /* + Check if the user already has the SA fork. If not, do it for them. + */ + + const hasFork = UI.projects.governance.spaces.userProfileSpace.githubForks.get(githubUsername) + if(hasFork === undefined) { + // New user! Probably doesn't have a fork, so let's create it. + let params = { + method: 'createGithubFork', + username: config.username, + token: config.token, + } + + let url = 'GOV' // We will access the default Client GOV endpoint. + + httpRequest(JSON.stringify(params), url, onResponse) + + function onResponse(err, data) { + + data = JSON.parse(data) + if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result && data.result === GLOBAL.DEFAULT_OK_RESPONSE.result) { + UI.projects.education.spaces.docsSpace.navigateTo('Governance', 'Topic', 'Gov Message - Automated User Profile Creation Done') + } else { + if (data.docs === undefined) {return} + UI.projects.education.spaces.docsSpace.navigateTo( + data.docs.project, + data.docs.category, + data.docs.type, + data.docs.anchor, + undefined, + data.docs.placeholder + ) + } + } + } + /* We store at the User Profile the Signed githubUsername */ UI.projects.visualScripting.utilities.nodeConfig.saveConfigProperty(userProfile.payload, 'signature', response.signature) @@ -138,11 +192,12 @@ function newGovernanceFunctionLibraryProfileConstructor() { We also Install the User Profile as a Plugin, which in turns saves it. */ userProfile.payload.uiObject.menu.internalClick('Install as Plugin') - userProfile.payload.uiObject.menu.internalClick('Install as Plugin') + userProfile.payload.uiObject.menu.internalClick('Install as Plugin') /* Show nice message. */ if (mnemonic === undefined || mnemonic === "") { + // TODO link to some wallet and setup the token node.payload.uiObject.setInfoMessage( "Profile Private Key has been successfully created. User Profile installed as a plugin and saved. Use the Private Key at a crypto wallet and delete this node once done.", UI.projects.governance.globals.designer.SET_INFO_COUNTER_FACTOR From 63e0a2342ead4f90f2fc9ca99dbb5e3eeba3ad52 Mon Sep 17 00:00:00 2001 From: NAmorim Date: Wed, 24 Nov 2021 16:33:29 +0000 Subject: [PATCH 2/4] Fix typo --- Projects/Governance/UI/Function-Libraries/LiquidityProgram.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Projects/Governance/UI/Function-Libraries/LiquidityProgram.js b/Projects/Governance/UI/Function-Libraries/LiquidityProgram.js index 1b6eae61a..1b676b970 100644 --- a/Projects/Governance/UI/Function-Libraries/LiquidityProgram.js +++ b/Projects/Governance/UI/Function-Libraries/LiquidityProgram.js @@ -108,7 +108,7 @@ function newGovernanceFunctionLibraryLiquidityProgram() { ) { node.payload.liquidityProgram.isActive = false userProfile.payload.uiObject.setErrorMessage( - "Waiting for liquidity balance. It takes 1 minute to load the liquidity provided by each profile, bacause you are using a free API provided by BSC Scan.", + "Waiting for liquidity balance. It takes 1 minute to load the liquidity provided by each profile, because you are using a free API provided by BSC Scan.", UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR ) return From f99f4d6f878e7e2e9dda7b084ccd711c42318815 Mon Sep 17 00:00:00 2001 From: NAmorim Date: Wed, 24 Nov 2021 21:36:59 +0000 Subject: [PATCH 3/4] Correction bad copy & paste --- .../Function-Libraries/ProfileConstructor.js | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js b/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js index 6f742ceda..54766d23b 100644 --- a/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js +++ b/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js @@ -150,6 +150,26 @@ function newGovernanceFunctionLibraryProfileConstructor() { const hasFork = UI.projects.governance.spaces.userProfileSpace.githubForks.get(githubUsername) if(hasFork === undefined) { // New user! Probably doesn't have a fork, so let's create it. + let apisNode = UI.projects.foundations.spaces.designSpace.workspace.getHierarchyHeadByNodeType('APIs') + if (apisNode === undefined) { + UI.projects.education.spaces.docsSpace.navigateTo('Governance', 'Topic', 'Gov Error - Github Credentials Missing', 'Anchor Github Credentials Missing') + return + } + if (apisNode.githubAPI === undefined) { + UI.projects.education.spaces.docsSpace.navigateTo('Governance', 'Topic', 'Gov Error - Github Credentials Missing', 'Anchor Github Credentials Missing') + return + } + + let config = JSON.parse(apisNode.githubAPI.config) + if (config.username === undefined || config.username === "") { + UI.projects.education.spaces.docsSpace.navigateTo('Governance', 'Topic', 'Gov Error - Github Credentials Missing', 'Anchor Github Credentials Missing') + return + } + if (config.token === undefined || config.token === "") { + UI.projects.education.spaces.docsSpace.navigateTo('Governance', 'Topic', 'Gov Error - Github Credentials Missing', 'Anchor Github Credentials Missing') + return + } + let params = { method: 'createGithubFork', username: config.username, @@ -164,7 +184,7 @@ function newGovernanceFunctionLibraryProfileConstructor() { data = JSON.parse(data) if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result && data.result === GLOBAL.DEFAULT_OK_RESPONSE.result) { - UI.projects.education.spaces.docsSpace.navigateTo('Governance', 'Topic', 'Gov Message - Automated User Profile Creation Done') + UI.projects.education.spaces.docsSpace.navigateTo('Governance', 'Topic', 'Gov Message - Automated User Profile Contribute Done') } else { if (data.docs === undefined) {return} UI.projects.education.spaces.docsSpace.navigateTo( @@ -192,7 +212,11 @@ function newGovernanceFunctionLibraryProfileConstructor() { We also Install the User Profile as a Plugin, which in turns saves it. */ userProfile.payload.uiObject.menu.internalClick('Install as Plugin') - userProfile.payload.uiObject.menu.internalClick('Install as Plugin') + userProfile.payload.uiObject.menu.internalClick('Install as Plugin') + /* + TODO: Let's create a nice basic profile to start with liquidity and community + */ + /* Show nice message. */ From 898e582bcbdd2965446806a86e3f97c3ef25103b Mon Sep 17 00:00:00 2001 From: NAmorim Date: Wed, 24 Nov 2021 22:04:28 +0000 Subject: [PATCH 4/4] Deepscan fixes --- Platform/Client/githubServer.js | 4 +--- Platform/Client/httpInterface.js | 10 +++++----- .../UI/Function-Libraries/ProfileConstructor.js | 4 ++-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Platform/Client/githubServer.js b/Platform/Client/githubServer.js index f245239f1..b72259bb2 100644 --- a/Platform/Client/githubServer.js +++ b/Platform/Client/githubServer.js @@ -168,8 +168,6 @@ exports.newGithubServer = function newGithubServer() { username = unescape(username) token = unescape(token) - let error - await doGithub() async function doGithub() { @@ -184,7 +182,7 @@ exports.newGithubServer = function newGithubServer() { await octokit.repos.createFork({ owner: 'Superalgos', - repo: "Superalgos" + repo: 'Superalgos' }) } catch (err) { if (err === undefined) { return } diff --git a/Platform/Client/httpInterface.js b/Platform/Client/httpInterface.js index e54dddf6f..62a398f49 100644 --- a/Platform/Client/httpInterface.js +++ b/Platform/Client/httpInterface.js @@ -1135,7 +1135,7 @@ exports.newHttpInterface = function newHttpInterface() { try { console.log('fixSchemas...' + allAppSchemas.length) let projects = SA.projects.foundations.utilities.filesAndDirectories.getDirectories(global.env.PATH_TO_PROJECTS) - const fs = SA.nodeModules.fs + //const fs = SA.nodeModules.fs let needFixing = 0 for (let i = 0; i < allAppSchemas.length; i++) { let schemaDocument = allAppSchemas[i] @@ -1183,13 +1183,13 @@ exports.newHttpInterface = function newHttpInterface() { } } - if (wasUpdated === true) { - let fileContent = JSON.stringify(schemaDocument, undefined, 4) - let filePath = allAppSchemasFilePaths[i] + //if (wasUpdated === true) { + //let fileContent = JSON.stringify(schemaDocument, undefined, 4) + //let filePath = allAppSchemasFilePaths[i] //console.log('Saving File at ' + filePath) //console.log(fileContent) //fs.writeFileSync(filePath, fileContent) - } + //} } } catch (err) { console.log(err.stack) diff --git a/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js b/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js index 54766d23b..f0bf9569b 100644 --- a/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js +++ b/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js @@ -140,8 +140,8 @@ function newGovernanceFunctionLibraryProfileConstructor() { liquidProgs.payload.uiObject.menu.internalClick('Add Liquidity Program') let liquidProg = UI.projects.visualScripting.functionLibraries.uiObjectsFromNodes.addUIObject(liquidProgs, "Liquidity Program", userProfile) - liquidProgs.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 - liquidProgs.payload.uiObject.menu.internalClick('Add Tokens Awarded') + liquidProg.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 + liquidProg.payload.uiObject.menu.internalClick('Add Tokens Awarded') /* Check if the user already has the SA fork. If not, do it for them.