diff --git a/Platform/UI/AppLoader.js b/Platform/UI/AppLoader.js index eb8f87864..2e010babf 100644 --- a/Platform/UI/AppLoader.js +++ b/Platform/UI/AppLoader.js @@ -138,7 +138,7 @@ function newAppLoader() { for (let i = 0; i < modulesArray.length; i++) { let path = modulesArray[i] - console.log(path) + REQUIREJS([path], onRequired) if (INFO_LOG === true) { logger.write('[INFO] loadModules -> Module Requested.') } diff --git a/Platform/UI/Utilities.js b/Platform/UI/Utilities.js index 0c2cbee7a..6216d3d59 100644 --- a/Platform/UI/Utilities.js +++ b/Platform/UI/Utilities.js @@ -98,6 +98,9 @@ function newUniqueId () { function splitTextIntoPhrases (text, wordsPerLine) { try { + if (text.split === undefined) { + return [] + } let splittedLabel = text.split(' ') let phrases = [] let phrase = '' diff --git a/Projects/Foundations/UI/Spaces/Design-Space/Workspace.js b/Projects/Foundations/UI/Spaces/Design-Space/Workspace.js index 5f1fcc8bc..61a2b1335 100644 --- a/Projects/Foundations/UI/Spaces/Design-Space/Workspace.js +++ b/Projects/Foundations/UI/Spaces/Design-Space/Workspace.js @@ -18,6 +18,7 @@ function newWorkspace() { share: shareWorkspace, getNodesByTypeAndHierarchyHeadsType: getNodesByTypeAndHierarchyHeadsType, getProjectsHeads: getProjectsHeads, + getProjectHeadByNodeType: getProjectHeadByNodeType, getHierarchyHeads: getHierarchyHeads, getHierarchyHeadsById: getHierarchyHeadsById, getHierarchyHeadsByCodeNameAndNodeType: getHierarchyHeadsByCodeNameAndNodeType, @@ -547,6 +548,17 @@ function newWorkspace() { return nodes } + function getProjectHeadByNodeType(nodeType) { + let projectHeads = getProjectsHeads() + if (projectHeads === undefined) { return } + for (let i = 0; i < projectHeads.length; i++) { + let hierarchyHead = projectHeads[i] + if (hierarchyHead.type === nodeType) { + return hierarchyHead + } + } + } + function getHierarchyHeadsById(nodeId) { let hierarchyHeads = getHierarchyHeads() if (hierarchyHeads === undefined) { return } diff --git a/Projects/Governance/Icons/signing-account.png b/Projects/Governance/Icons/signing-account.png new file mode 100644 index 000000000..a4ee2a209 Binary files /dev/null and b/Projects/Governance/Icons/signing-account.png differ diff --git a/Projects/Governance/Icons/signing-accounts.png b/Projects/Governance/Icons/signing-accounts.png new file mode 100644 index 000000000..a4ee2a209 Binary files /dev/null and b/Projects/Governance/Icons/signing-accounts.png differ diff --git a/Projects/Governance/Schemas/App-Schema/profile-constructor.json b/Projects/Governance/Schemas/App-Schema/profile-constructor.json index 5c4180bd3..b8cf9f043 100644 --- a/Projects/Governance/Schemas/App-Schema/profile-constructor.json +++ b/Projects/Governance/Schemas/App-Schema/profile-constructor.json @@ -18,6 +18,16 @@ "relatedUiObject": "Profile Constructor", "actionFunction": "payload.executeAction" }, + { + "action": "Add Signing Account", + "actionProject": "Governance", + "label": "Add Signing Account", + "askConfirmation": true, + "confirmationLabel": "Confirm to Proceed", + "workDoneLabel": "Done", + "relatedUiObject": "Profile Constructor", + "actionFunction": "payload.executeAction" + }, { "action": "Delete UI Object", "actionProject": "Foundations", diff --git a/Projects/Governance/Schemas/App-Schema/signing-account.json b/Projects/Governance/Schemas/App-Schema/signing-account.json new file mode 100644 index 000000000..34aef0869 --- /dev/null +++ b/Projects/Governance/Schemas/App-Schema/signing-account.json @@ -0,0 +1,35 @@ +{ + "type": "Signing Account", + "menuItems": [ + { + "action": "Configure", + "actionFunction": "uiObject.configEditor.activate", + "actionProject": "Foundations", + "label": "Configure", + "iconPathOn": "configuration", + "iconPathOff": "configuration" + }, + { + "action": "Delete UI Object", + "actionProject": "Foundations", + "askConfirmation": true, + "confirmationLabel": "Confirm to Delete", + "label": "Delete", + "iconPathOn": "delete-entity", + "iconPathOff": "delete-entity", + "actionFunction": "payload.executeAction" + } + ], + "addLeftIcons": true, + "level": 2, + "attachingRules": { + "compatibleTypes": "->User Profile->" + }, + "editors": { + "config": true + }, + "initialValues": { + "config": "{}" + }, + "propertyNameAtParent": "signingAccount" +} \ No newline at end of file diff --git a/Projects/Governance/Schemas/App-Schema/signing-accounts.json b/Projects/Governance/Schemas/App-Schema/signing-accounts.json new file mode 100644 index 000000000..8a8b2dba4 --- /dev/null +++ b/Projects/Governance/Schemas/App-Schema/signing-accounts.json @@ -0,0 +1,29 @@ +{ + "type": "Signing Accounts", + "menuItems": [ + { + "action": "Delete UI Object", + "actionProject": "Foundations", + "askConfirmation": true, + "confirmationLabel": "Confirm to Delete", + "label": "Delete", + "iconPathOn": "delete-entity", + "iconPathOff": "delete-entity", + "actionFunction": "payload.executeAction" + } + ], + "addLeftIcons": true, + "level": 2, + "attachingRules": { + "compatibleTypes": "->User Profile->" + }, + "propertyNameAtParent": "signingAccounts", + "childrenNodesProperties": [ + { + "name": "signingAccounts", + "type": "array", + "childType": "Signing Account", + "autoAdd": false + } + ] +} \ No newline at end of file diff --git a/Projects/Governance/Schemas/App-Schema/user-profile.json b/Projects/Governance/Schemas/App-Schema/user-profile.json index a3e31924e..4fe356ae4 100644 --- a/Projects/Governance/Schemas/App-Schema/user-profile.json +++ b/Projects/Governance/Schemas/App-Schema/user-profile.json @@ -69,6 +69,12 @@ "type": "node", "childType": "Tokens Mined", "autoAdd": true + }, + { + "name": "signingAccounts", + "type": "node", + "childType": "Signing Accounts", + "autoAdd": false } ] } \ No newline at end of file diff --git a/Projects/Governance/UI/Function-Libraries/ActionSwitch.js b/Projects/Governance/UI/Function-Libraries/ActionSwitch.js index b9ac27c78..da9022ebe 100644 --- a/Projects/Governance/UI/Function-Libraries/ActionSwitch.js +++ b/Projects/Governance/UI/Function-Libraries/ActionSwitch.js @@ -38,6 +38,11 @@ function newGovernanceActionSwitch() { UI.projects.governance.functionLibraries.profileConstructor.buildProfile(action.node, action.rootNodes) break } + case 'Add Signing Account': + { + UI.projects.governance.functionLibraries.profileConstructor.addSigningAccount(action.node, action.rootNodes) + break + } case 'Add Missing Plugin User Profiles': { UI.projects.governance.functionLibraries.pluginsFunctions.addMissingPluginUserProfiles(action.node, action.rootNodes) diff --git a/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js b/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js index eb09d4f6f..679d69743 100644 --- a/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js +++ b/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js @@ -1,6 +1,7 @@ function newGovernanceFunctionLibraryProfileConstructor() { let thisObject = { - buildProfile: buildProfile + buildProfile: buildProfile, + addSigningAccount: addSigningAccount } return thisObject @@ -18,7 +19,7 @@ function newGovernanceFunctionLibraryProfileConstructor() { if (githubUsername === undefined || githubUsername === "") { node.payload.uiObject.setErrorMessage( "githubUsername config property missing.", - UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR + UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR ) return } @@ -53,7 +54,7 @@ function newGovernanceFunctionLibraryProfileConstructor() { if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { node.payload.uiObject.setErrorMessage( 'Call via HTTP Interface failed.', - UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR + UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR ) return } @@ -67,14 +68,14 @@ function newGovernanceFunctionLibraryProfileConstructor() { node.payload.uiObject.setErrorMessage( 'Call to WEB3 Server failed. ' + response.error, UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR - ) + ) console.log('Call to WEB3 Server failed. ' + response.error) return } else { node.payload.uiObject.setErrorMessage( 'Call to WEB3 Server failed. Most likely the Mnemonic provided is not correct or you need to run node setup because a dependency is missing. ' + response.error, UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR - ) + ) console.log('Call to WEB3 Server failed. Most likely the Mnemonic provided is not correct or you need to run node setup because a dependency is missing. ' + response.error) return } @@ -103,7 +104,7 @@ function newGovernanceFunctionLibraryProfileConstructor() { node.payload.uiObject.setErrorMessage( 'Call via HTTP Interface failed.', UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR - ) + ) return } @@ -114,7 +115,7 @@ function newGovernanceFunctionLibraryProfileConstructor() { node.payload.uiObject.setErrorMessage( 'Call to WEB3 Server failed. ' + response.error, UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR - ) + ) console.log('Call to WEB3 Server failed. ' + response.error) return } @@ -145,14 +146,130 @@ function newGovernanceFunctionLibraryProfileConstructor() { 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 - ) + ) } else { node.payload.uiObject.setInfoMessage( "Mnemonic successfully imported. User Profile installed as a plugin and saved. Your external wallet was sucessfully linked to your profile.", UI.projects.governance.globals.designer.SET_INFO_COUNTER_FACTOR - ) + ) } } } } + + function addSigningAccount( + node, + rootNodes + ) { + let mnemonic = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(node.payload, 'mnemonic') + let signingAccounts + /* + Some validations first... + */ + if (node.payload.referenceParent === undefined) { + node.payload.uiObject.setErrorMessage( + "The Profile Contstructor needs to reference your User Profile.", + UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR + ) + return + } + + if (node.payload.referenceParent.signingAccounts === undefined) { + signingAccounts = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject( + node.payload.referenceParent, + 'Signing Accounts', + UI.projects.foundations.spaces.designSpace.workspace.workspaceNode.rootNodes + ) + } else { + signingAccounts = node.payload.referenceParent.signingAccounts + } + + createWallet() + + function createWallet() { + let params + /* + If the user provides a mnemonic then we will get the private key and address from it, + otherwise, we will create a new private key and address. + */ + if (mnemonic === undefined || mnemonic === "") { + params = { + method: 'createWalletAccount', + entropy: node.id + (new Date()).valueOf() + } + } else { + params = { + method: 'mnemonicToPrivateKey', + mnemonic: mnemonic + } + } + + let url = 'WEB3' // We will access the default Client WEB3 endpoint. + + httpRequest(JSON.stringify(params), url, onResponse) + + function onResponse(err, data) { + /* Lets check the result of the call through the http interface */ + if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { + node.payload.uiObject.setErrorMessage( + 'Call via HTTP Interface failed.', + UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR + ) + return + } + + let response = JSON.parse(data) + + /* Lets check the result of the method call */ + if (response.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { + + if (mnemonic === undefined || mnemonic === "") { + node.payload.uiObject.setErrorMessage( + 'Call to WEB3 Server failed. ' + response.error, + UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR + ) + console.log('Call to WEB3 Server failed. ' + response.error) + return + } else { + node.payload.uiObject.setErrorMessage( + 'Call to WEB3 Server failed. Most likely the Mnemonic provided is not correct or you need to run node setup because a dependency is missing. ' + response.error, + UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR + ) + console.log('Call to WEB3 Server failed. Most likely the Mnemonic provided is not correct or you need to run node setup because a dependency is missing. ' + response.error) + return + } + } + + createSigningAccount(response.address, response.privateKey) + } + } + + function createSigningAccount(address, privateKey) { + + let signingAccount = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject( + signingAccounts, + 'Signing Account', + UI.projects.foundations.spaces.designSpace.workspace.workspaceNode.rootNodes + ) + /* + We store at the User Profile the Signed githubUsername + */ + UI.projects.foundations.utilities.nodeConfig.saveConfigProperty(signingAccount.payload, 'address', address) + UI.projects.foundations.utilities.nodeConfig.saveConfigProperty(node.payload, 'privateKey', privateKey) + /* + Show nice message. + */ + if (mnemonic === undefined || mnemonic === "") { + node.payload.uiObject.setInfoMessage( + "Signing Account has been successfully created.", + UI.projects.governance.globals.designer.SET_INFO_COUNTER_FACTOR + ) + } else { + node.payload.uiObject.setInfoMessage( + "Mnemonic successfully imported. Signing Account has been successfully created.", + UI.projects.governance.globals.designer.SET_INFO_COUNTER_FACTOR + ) + } + } + } } diff --git a/Projects/Governance/UI/Function-Libraries/TokenMining.js b/Projects/Governance/UI/Function-Libraries/TokenMining.js index 68abe13c7..4ad90ec87 100644 --- a/Projects/Governance/UI/Function-Libraries/TokenMining.js +++ b/Projects/Governance/UI/Function-Libraries/TokenMining.js @@ -126,6 +126,7 @@ function newGovernanceFunctionLibraryTokenMining() { if (userProfile === undefined) { return } if (userProfile.payload === undefined) { return } if (userProfile.tokensMined === undefined) { return } + if (userProfile.tokensMined.payload === undefined) { return } if (userProfile.tokensMined.payload.tokensMined === undefined) { userProfile.tokensMined.payload.tokensMined = { awarded: 0, @@ -147,6 +148,8 @@ function newGovernanceFunctionLibraryTokenMining() { if (userProfile === undefined) { return } if (userProfile.payload === undefined) { return } if (userProfile.tokensMined === undefined) { return } + if (userProfile.tokensMined.payload === undefined) { return } + if (programNode.payload === undefined) { return } if (programNode.payload[programPropertyName] === undefined) { return } @@ -165,6 +168,7 @@ function newGovernanceFunctionLibraryTokenMining() { if (userProfile === undefined) { return } if (userProfile.payload === undefined) { return } if (userProfile.tokensMined === undefined) { return } + if (userProfile.tokensMined.payload === undefined) { return } const awarded = parseFloat(userProfile.tokensMined.payload.tokensMined.awarded.toFixed(0)).toLocaleString('en') const bonus = parseFloat(userProfile.tokensMined.payload.tokensMined.bonus.toFixed(0)).toLocaleString('en') diff --git a/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js b/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js index b851a6f82..d38898d0e 100644 --- a/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js +++ b/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js @@ -26,7 +26,7 @@ function newGovernanceUserProfileSpace() { /* If the workspace is not related to governance, then we exit the Intialize Function */ - let governanceProject = UI.projects.foundations.spaces.designSpace.workspace.getHierarchyHeadsByNodeType('Governance Project') + let governanceProject = UI.projects.foundations.spaces.designSpace.workspace.getProjectHeadByNodeType('Governance Project') if (governanceProject === undefined) { return } /* Here we will run the distribution process, that in turn will run all the programs. @@ -334,12 +334,13 @@ function newGovernanceUserProfileSpace() { /* If the workspace is not related to governance, then we exit the Intialize Function */ - let governanceProject = UI.projects.foundations.spaces.designSpace.workspace.getHierarchyHeadsByNodeType('Governance Project') + let governanceProject = UI.projects.foundations.spaces.designSpace.workspace.getProjectHeadByNodeType('Governance Project') if (governanceProject === undefined) { return } /* Load the user profiles with Token Power. */ let userProfiles = UI.projects.foundations.spaces.designSpace.workspace.getHierarchyHeadsByNodeType('User Profile') + if (waitingForResponses !== 0) { return } /* We will get all the user Profiles tokens from the blockchain, making a call every 5 seconds so as not to exceed the rate limit.