diff --git a/Projects/Governance/Schemas/App-Schema/position-claim-vote.json b/Projects/Governance/Schemas/App-Schema/position-claim-vote.json index b77163f27..9be9e18a2 100644 --- a/Projects/Governance/Schemas/App-Schema/position-claim-vote.json +++ b/Projects/Governance/Schemas/App-Schema/position-claim-vote.json @@ -26,7 +26,7 @@ "config": true }, "initialValues": { - "config": "{\n \"description\": \"\"\n}" + "config": "{}" }, "addLeftIcons": true, "level": 2, diff --git a/Projects/Governance/UI/Function-Libraries/Accounts.js b/Projects/Governance/UI/Function-Libraries/Accounts.js deleted file mode 100644 index d84df1548..000000000 --- a/Projects/Governance/UI/Function-Libraries/Accounts.js +++ /dev/null @@ -1,53 +0,0 @@ -function newEthereumFunctionLibraryAccounts() { - let thisObject = { - createWalletAccount: createWalletAccount - } - - return thisObject - - function createWalletAccount(node) { - - let walletAccountNode = UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Wallet Account') - - let params = { - method: 'createWalletAccount', - entropy: walletAccountNode.id - } - - let url = 'WEB3' // we don't need to ask this to any specific superalgos node. - - 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.') - walletAccountNode.payload.uiObject.menu.internalClick('Delete UI Object') - walletAccountNode.payload.uiObject.menu.internalClick('Delete UI Object') - return - } - - let response = JSON.parse(data) - - /* Lets check the result of the method call */ - if (response.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { - node.payload.uiObject.setErrorMessage('Call to WEB3 Server failed. ' + response.error) - walletAccountNode.payload.uiObject.menu.internalClick('Delete UI Object') - walletAccountNode.payload.uiObject.menu.internalClick('Delete UI Object') - return - } - - let config = { - address: response.address, - privateKey: response.privateKey - } - - walletAccountNode.config = JSON.stringify(config, null, 4) - walletAccountNode.name = - response.address[response.address.length - 4] + - response.address[response.address.length - 3] + - response.address[response.address.length - 2] + - response.address[response.address.length - 1] - } - } -} diff --git a/Projects/Governance/UI/Function-Libraries/Weights.js b/Projects/Governance/UI/Function-Libraries/Weights.js new file mode 100644 index 000000000..7841eb22d --- /dev/null +++ b/Projects/Governance/UI/Function-Libraries/Weights.js @@ -0,0 +1,88 @@ +function newGovernanceFunctionLibraryWeights() { + let thisObject = { + calculateWeights: calculateWeights + } + + return thisObject + + function calculateWeights(node) { + let totalVotes = 0 + countVotesAndResetWeights(node) + applyWeightCalculation(node) + + function countVotesAndResetWeights(node) { + if (node === undefined) { return } + if (node.payload === undefined) { return } + + if (node.payload.votes !== undefined) { + totalVotes = totalVotes + node.payload.votes + } + node.payload.weight = 0 + /* + Now we will count the voting power of this node's children. + */ + let schemaDocument = getSchemaDocument(node) + if (schemaDocument === undefined) { return } + + if (schemaDocument.childrenNodesProperties !== undefined) { + for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) { + let property = schemaDocument.childrenNodesProperties[i] + switch (property.type) { + case 'node': { + let childNode = node[property.name] + countVotesAndResetWeights(childNode) + } + break + case 'array': { + let propertyArray = node[property.name] + if (propertyArray !== undefined) { + for (let m = 0; m < propertyArray.length; m++) { + let childNode = propertyArray[m] + countVotesAndResetWeights(childNode) + } + } + break + } + } + } + } + } + + function applyWeightCalculation(node) { + if (node === undefined) { return } + if (node.payload === undefined) { return } + + if (node.payload.votes !== undefined) { + node.payload.weight = node.payload.votes / totalVotes + } + /* + Now we will count the voting power of this node's children. + */ + let schemaDocument = getSchemaDocument(node) + if (schemaDocument === undefined) { return } + + if (schemaDocument.childrenNodesProperties !== undefined) { + for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) { + let property = schemaDocument.childrenNodesProperties[i] + switch (property.type) { + case 'node': { + let childNode = node[property.name] + applyWeightCalculation(childNode) + } + break + case 'array': { + let propertyArray = node[property.name] + if (propertyArray !== undefined) { + for (let m = 0; m < propertyArray.length; m++) { + let childNode = propertyArray[m] + applyWeightCalculation(childNode) + } + } + break + } + } + } + } + } + } +} diff --git a/Projects/Governance/UI/Spaces/Features-Space/Features.js b/Projects/Governance/UI/Spaces/Features-Space/Features.js index 3573a4dca..31221b350 100644 --- a/Projects/Governance/UI/Spaces/Features-Space/Features.js +++ b/Projects/Governance/UI/Spaces/Features-Space/Features.js @@ -25,7 +25,15 @@ function newGovernanceFeaturesSpace() { } function physics() { + if (UI.projects.superalgos.spaces.designSpace.workspace === undefined) { return } + let features = UI.projects.superalgos.spaces.designSpace.workspace.getHierarchyHeadsByNodeType('Features') + + /* Weight Calculation Follows */ + for (let i = 0; i < features.length; i++) { + let feature = features[i] + UI.projects.governance.functionLibraries.weights.calculateWeights(feature) + } } function getContainer(point) { diff --git a/Projects/Governance/UI/Spaces/Pools-Space/Pools.js b/Projects/Governance/UI/Spaces/Pools-Space/Pools.js index 62ddd3fcc..c7941e35c 100644 --- a/Projects/Governance/UI/Spaces/Pools-Space/Pools.js +++ b/Projects/Governance/UI/Spaces/Pools-Space/Pools.js @@ -39,8 +39,13 @@ function newGovernancePoolsSpace() { let pools = UI.projects.superalgos.spaces.designSpace.workspace.getHierarchyHeadsByNodeType('Pools') + /* Weight Calculation Follows */ + for (let i = 0; i < pools.length; i++) { + let poolsNode = pools[i] + UI.projects.governance.functionLibraries.weights.calculateWeights(poolsNode) + } /* - We will first reset all the token flows, and then distribute it. + We will reset all the token flows, and then distribute it. */ for (let i = 0; i < pools.length; i++) { let poolsNode = pools[i] @@ -117,8 +122,30 @@ function newGovernancePoolsSpace() { function distributeTokenFlow(node, tokenFlow) { if (node === undefined) { return } if (node.payload === undefined) { return } - node.payload.tokenFlow = node.payload.tokenFlow + tokenFlow - drawTokenFlow(node, node.payload.tokenFlow) + /* + Let's get the schemaDocument first + */ + let schemaDocument = getSchemaDocument(node) + if (schemaDocument === undefined) { return } + /* + At hierarchy heads we will shouw how many tokens are comming in. + */ + if ( + schemaDocument.isHierarchyHead === true + ) { + drawTokenFlow(node, tokenFlow) + } + /* + We will also have tokens at nodes with weight. + */ + if ( + isNaN(node.payload.weight ) !== true && + node.payload.weight !== undefined && + node.payload.weight !== 0 + ) { + node.payload.tokenFlow = tokenFlow * node.payload.weight + drawTokenFlow(node, node.payload.tokenFlow, node.payload.weight) + } /* If there is a reference parent defined, this means that the token flow is transfered to it and not distributed among children. @@ -128,18 +155,14 @@ function newGovernancePoolsSpace() { return } /* - When we reach certain node types, we will halt the distribution, because thse are targets for + When we reach certain node types, we will halt the distribution, because these are targets for token flow. */ if ( node.type === 'Asset' || node.type === 'Feature' ) { return } - /* - If there is no reference parent we will redistribute token flow among children. - */ - let schemaDocument = getSchemaDocument(node) - if (schemaDocument === undefined) { return } + if (schemaDocument.childrenNodesProperties !== undefined) { for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) { @@ -158,7 +181,7 @@ function newGovernancePoolsSpace() { if (propertyArray !== undefined) { for (let m = 0; m < propertyArray.length; m++) { let childNode = propertyArray[m] - distributeTokenFlow(childNode, tokenFlow / propertyArray.length) + distributeTokenFlow(childNode, tokenFlow) } } break @@ -168,12 +191,14 @@ function newGovernancePoolsSpace() { } } - function drawTokenFlow(node, tokenFlow) { - tokenFlow = new Intl.NumberFormat().format(tokenFlow) + ' ' + 'SA Tokens' + function drawTokenFlow(node, tokenFlow, weight) { + if (weight !== undefined && weight !== 0) { + tokenFlow = new Intl.NumberFormat().format(tokenFlow) + ' ' + 'SA Tokens' + ' - ' + 'Weight: ' + weight.toFixed(2) + } else { + tokenFlow = new Intl.NumberFormat().format(tokenFlow) + ' ' + 'SA Tokens' + } + if (node.payload !== undefined) { - if (node.type === 'Pools') { - return - } node.payload.uiObject.setStatus(tokenFlow) } } diff --git a/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js b/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js index bc7ee7ebf..fb2b13715 100644 --- a/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js +++ b/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js @@ -37,34 +37,61 @@ function newGovernanceUserProfileSpace() { function physics() { if (UI.projects.superalgos.spaces.designSpace.workspace === undefined) { return } - let userProfiles = UI.projects.superalgos.spaces.designSpace.workspace.getHierarchyHeadsByNodeType('User Profile') + let pools = UI.projects.superalgos.spaces.designSpace.workspace.getHierarchyHeadsByNodeType('Pools') + /* Reset Votes at Pools */ + for (let i = 0; i < pools.length; i++) { + let poolsNode = pools[i] + resetVotes(poolsNode) + } + let features = UI.projects.superalgos.spaces.designSpace.workspace.getHierarchyHeadsByNodeType('Features') + /* Reset Votes at Features */ + for (let i = 0; i < features.length; i++) { + let feature = features[i] + resetVotes(feature) + } + + let assets = UI.projects.superalgos.spaces.designSpace.workspace.getHierarchyHeadsByNodeType('Assets') + /* Reset Votes at Features */ + for (let i = 0; i < assets.length; i++) { + let asset = assets[i] + resetVotes(asset) + } + + let positions = UI.projects.superalgos.spaces.designSpace.workspace.getHierarchyHeadsByNodeType('Positions') + /* Reset Votes at Features */ + for (let i = 0; i < positions.length; i++) { + let position = positions[i] + resetVotes(position) + } + + let userProfiles = UI.projects.superalgos.spaces.designSpace.workspace.getHierarchyHeadsByNodeType('User Profile') /* We will first reset all the voting power, and then distribute it. */ for (let i = 0; i < userProfiles.length; i++) { let userProfile = userProfiles[i] - userProfileReset(userProfile) + resetVotes(userProfile) } for (let i = 0; i < userProfiles.length; i++) { let userProfile = userProfiles[i] - userProfileDistribute(userProfile) + distributeVotes(userProfile) } } - function userProfileReset(userProfile) { + function resetVotes(userProfile) { resetVotingPower(userProfile) } - function userProfileDistribute(userProfile) { - let votingPower = UI.projects.superalgos.utilities.nodeConfig.loadPropertyFromNodeConfig(userProfile.payload, 'tokens') - distributeVotingPower(userProfile, votingPower) + function distributeVotes(userProfile) { + let votes = UI.projects.superalgos.utilities.nodeConfig.loadPropertyFromNodeConfig(userProfile.payload, 'tokens') + distributeVotingPower(userProfile, votes) } function resetVotingPower(node) { if (node === undefined) { return } if (node.payload === undefined) { return } - node.payload.votingPower = 0 + node.payload.votes = 0 /* If there is a reference parent defined, this means that the voting power is transfered to it and not distributed among children. @@ -117,19 +144,11 @@ function newGovernanceUserProfileSpace() { } } - function distributeVotingPower(node, votingPower, switchPercentage) { + function distributeVotingPower(node, votes, switchPercentage) { if (node === undefined) { return } if (node.payload === undefined) { return } - node.payload.votingPower = node.payload.votingPower + votingPower - drawVotingPower(node, node.payload.votingPower, switchPercentage) - /* - If there is a reference parent defined, this means that the voting power is - transfered to it and not distributed among children. - */ - if (node.payload.referenceParent !== undefined) { - distributeVotingPower(node.payload.referenceParent, votingPower) - return - } + node.payload.votes = node.payload.votes + votes + drawVotingPower(node, node.payload.votes, switchPercentage) /* When we reach certain node types, we will halt the distribution, because thse are targets for voting power. @@ -137,9 +156,18 @@ function newGovernanceUserProfileSpace() { if ( node.type === 'Position' || node.type === 'Asset' || - node.type === 'Feature' + node.type === 'Feature' || + node.type === 'Pool' ) { return } /* + If there is a reference parent defined, this means that the voting power is + transfered to it and not distributed among children. + */ + if (node.payload.referenceParent !== undefined) { + distributeVotingPower(node.payload.referenceParent, votes) + return + } + /* If there is no reference parent we will redistribute voting power among children. */ let schemaDocument = getSchemaDocument(node) @@ -214,7 +242,7 @@ function newGovernanceUserProfileSpace() { if (percentage === undefined || isNaN(percentage) === true) { percentage = defaultPercentage } - distributeVotingPower(childNode, votingPower * percentage / 100, percentage) + distributeVotingPower(childNode, votes * percentage / 100, percentage) } } break @@ -227,7 +255,7 @@ function newGovernanceUserProfileSpace() { if (percentage === undefined || isNaN(percentage) === true) { percentage = defaultPercentage } - distributeVotingPower(childNode, votingPower * percentage / 100, percentage) + distributeVotingPower(childNode, votes * percentage / 100, percentage) } } break @@ -237,8 +265,8 @@ function newGovernanceUserProfileSpace() { } } - function drawVotingPower(node, votingPower, percentage) { - votingPower = new Intl.NumberFormat().format(votingPower) + ' ' + 'Votes' + function drawVotingPower(node, votes, percentage) { + votes = new Intl.NumberFormat().format(votes) + ' ' + 'Votes' if (node.payload !== undefined) { if (node.type === 'User Profile') { return @@ -263,10 +291,10 @@ function newGovernanceUserProfileSpace() { node.payload.uiObject.valueAtAngle = true } - node.payload.uiObject.setValue(votingPower) + node.payload.uiObject.setValue(votes) if (percentage !== undefined) { - node.payload.uiObject.setPercentage(percentage.toFixed(2)) + node.payload.uiObject.setPercentage(percentage.toFixed(2)) } } } diff --git a/Projects/ProjectsSchema.json b/Projects/ProjectsSchema.json index 36299a81c..8e2eb41dc 100644 --- a/Projects/ProjectsSchema.json +++ b/Projects/ProjectsSchema.json @@ -996,9 +996,9 @@ ], "functionLibraries": [ { - "name": "Accounts", - "propertyName": "accounts", - "functionName": "newEthereumFunctionLibraryAccounts" + "name": "Weights", + "propertyName": "weights", + "functionName": "newGovernanceFunctionLibraryWeights" } ], "utilities": [