diff --git a/Projects/Governance/Schemas/App-Schema/asset-claim-vote.json b/Projects/Governance/Schemas/App-Schema/asset-claim-vote.json index 97fd65724..29de095bc 100644 --- a/Projects/Governance/Schemas/App-Schema/asset-claim-vote.json +++ b/Projects/Governance/Schemas/App-Schema/asset-claim-vote.json @@ -26,7 +26,7 @@ "config": true }, "initialValues": { - "config": "{\n \"description\": \"\"\n}" + "config": "{}" }, "addLeftIcons": true, "level": 2, diff --git a/Projects/Governance/Schemas/App-Schema/asset-weight-vote.json b/Projects/Governance/Schemas/App-Schema/asset-weight-vote.json index bc254bfb3..9c9e5bf82 100644 --- a/Projects/Governance/Schemas/App-Schema/asset-weight-vote.json +++ b/Projects/Governance/Schemas/App-Schema/asset-weight-vote.json @@ -28,7 +28,7 @@ "config": true }, "initialValues": { - "config": "{\n \"description\": \"\"\n}" + "config": "{}" }, "addLeftIcons": true, "level": 2, diff --git a/Projects/Governance/Schemas/App-Schema/contributed-youtube-video.json b/Projects/Governance/Schemas/App-Schema/contributed-youtube-video.json deleted file mode 100644 index fe07c5c9c..000000000 --- a/Projects/Governance/Schemas/App-Schema/contributed-youtube-video.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "type": "Contributed Youtube Video", - "menuItems": [ - { - "action": "Configure", - "actionFunction": "uiObject.configEditor.activate", - "label": "Configure", - "iconPathOn": "configuration", - "iconPathOff": "configuration" - }, - { - "action": "Add UI Object", - "actionFunction": "payload.executeAction", - "label": "Add Asset", - "relatedUiObject": "Asset" - }, - { - "action": "Delete UI Object", - "askConfirmation": true, - "confirmationLabel": "Confirm to Delete", - "label": "Delete", - "iconPathOn": "delete-entity", - "iconPathOff": "delete-entity", - "actionFunction": "payload.executeAction" - } - ], - "editors": { - "config": true - }, - "initialValues": { - "config": "{\n \"description\": \"\"\n}" - }, - "addLeftIcons": true, - "level": 2, - "attachingRules": { - "compatibleTypes": "->Assets->Asset->" - }, - "propertyNameAtParent": "assetContributionsFolder", - "childrenNodesProperties": [ - { - "name": "assetClass", - "type": "array", - "childType": "Asset", - "autoAdd": false - } - ], - "icon": "bitcoin" -} \ No newline at end of file diff --git a/Projects/Governance/Schemas/App-Schema/feature-claim-vote.json b/Projects/Governance/Schemas/App-Schema/feature-claim-vote.json index a5123d218..cea6990c0 100644 --- a/Projects/Governance/Schemas/App-Schema/feature-claim-vote.json +++ b/Projects/Governance/Schemas/App-Schema/feature-claim-vote.json @@ -26,7 +26,7 @@ "config": true }, "initialValues": { - "config": "{\n \"description\": \"\"\n}" + "config": "{}" }, "addLeftIcons": true, "level": 2, diff --git a/Projects/Governance/Schemas/App-Schema/feature-weight-vote.json b/Projects/Governance/Schemas/App-Schema/feature-weight-vote.json index a919051b5..229af8e55 100644 --- a/Projects/Governance/Schemas/App-Schema/feature-weight-vote.json +++ b/Projects/Governance/Schemas/App-Schema/feature-weight-vote.json @@ -27,7 +27,7 @@ "config": true }, "initialValues": { - "config": "{\n \"description\": \"\"\n}" + "config": "{}" }, "addLeftIcons": true, "level": 2, diff --git a/Projects/Governance/Schemas/App-Schema/pool-weight-vote.json b/Projects/Governance/Schemas/App-Schema/pool-weight-vote.json index 59b68b56f..47e9de487 100644 --- a/Projects/Governance/Schemas/App-Schema/pool-weight-vote.json +++ b/Projects/Governance/Schemas/App-Schema/pool-weight-vote.json @@ -26,7 +26,7 @@ "config": true }, "initialValues": { - "config": "{\n \"description\": \"\"\n}" + "config": "{}" }, "addLeftIcons": true, "level": 2, diff --git a/Projects/Governance/Schemas/App-Schema/position-weight-vote.json b/Projects/Governance/Schemas/App-Schema/position-weight-vote.json index c1cb72fc8..ff107cff4 100644 --- a/Projects/Governance/Schemas/App-Schema/position-weight-vote.json +++ b/Projects/Governance/Schemas/App-Schema/position-weight-vote.json @@ -26,7 +26,7 @@ "config": true }, "initialValues": { - "config": "{\n \"description\": \"\"\n}" + "config": "{}" }, "addLeftIcons": true, "level": 2, diff --git a/Projects/Governance/Schemas/App-Schema/user-vote-transfer.json b/Projects/Governance/Schemas/App-Schema/user-vote-transfer.json index 90bc622b7..a19bb9c3a 100644 --- a/Projects/Governance/Schemas/App-Schema/user-vote-transfer.json +++ b/Projects/Governance/Schemas/App-Schema/user-vote-transfer.json @@ -25,7 +25,7 @@ "config": true }, "initialValues": { - "config": "{\n \"description\": \"\"\n}" + "config": "{}" }, "addLeftIcons": true, "level": 2, diff --git a/Projects/Governance/Schemas/App-Schema/votes-switch.json b/Projects/Governance/Schemas/App-Schema/votes-switch.json index 4f4c0fd66..0c1866bba 100644 --- a/Projects/Governance/Schemas/App-Schema/votes-switch.json +++ b/Projects/Governance/Schemas/App-Schema/votes-switch.json @@ -76,7 +76,7 @@ "config": true }, "initialValues": { - "config": "{\n \"description\": \"\"\n}" + "config": "{}" }, "addLeftIcons": true, "level": 2, diff --git a/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js b/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js index 507d76a67..bc7ee7ebf 100644 --- a/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js +++ b/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js @@ -117,11 +117,11 @@ function newGovernanceUserProfileSpace() { } } - function distributeVotingPower(node, votingPower) { + function distributeVotingPower(node, votingPower, switchPercentage) { if (node === undefined) { return } if (node.payload === undefined) { return } node.payload.votingPower = node.payload.votingPower + votingPower - drawVotingPower(node, node.payload.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. @@ -146,6 +146,14 @@ function newGovernanceUserProfileSpace() { if (schemaDocument === undefined) { return } if (schemaDocument.childrenNodesProperties !== undefined) { + /* + Before distributing the voting power, we will calculate how the power + is going to be switched between all nodes. The first pass is about + scanning all sibling nodes to see which ones have a percentage defined + at their config, and check that all percentages don't add more than 100. + */ + let totalPercentage = 0 + let totalNodesWithoutPercentage = 0 for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) { let property = schemaDocument.childrenNodesProperties[i] @@ -155,7 +163,58 @@ function newGovernanceUserProfileSpace() { case 'node': { if (node.type === 'User Profile' && property.name === "votesDistribution") { let childNode = node[property.name] - distributeVotingPower(childNode, votingPower) + let percentage = UI.projects.superalgos.utilities.nodeConfig.loadPropertyFromNodeConfig(childNode.payload, 'percentage') + if (percentage !== undefined && isNaN(percentage) !== true) { + totalPercentage = totalPercentage + percentage + } else { + totalNodesWithoutPercentage++ + } + } + } + break + case 'array': { + let propertyArray = node[property.name] + if (propertyArray !== undefined) { + + for (let m = 0; m < propertyArray.length; m++) { + let childNode = propertyArray[m] + let percentage = UI.projects.superalgos.utilities.nodeConfig.loadPropertyFromNodeConfig(childNode.payload, 'percentage') + if (percentage !== undefined && isNaN(percentage) !== true) { + totalPercentage = totalPercentage + percentage + } else { + totalNodesWithoutPercentage++ + } + } + } + break + } + } + } + if (totalPercentage > 100) { + node.payload.uiObject.setErrorMessage('Voting Power Switching Error. Total Percentage of children nodes is grater that 100.') + return + } + let defaultPercentage = 0 + if (totalNodesWithoutPercentage > 0) { + defaultPercentage = (100 - totalPercentage) / totalNodesWithoutPercentage + } + /* + Here we do the actual distribution. + */ + for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) { + let property = schemaDocument.childrenNodesProperties[i] + + if (node.type === 'User Profile' && property.name !== "votesDistribution") { continue } + + switch (property.type) { + case 'node': { + if (node.type === 'User Profile' && property.name === "votesDistribution") { + let childNode = node[property.name] + let percentage = UI.projects.superalgos.utilities.nodeConfig.loadPropertyFromNodeConfig(childNode.payload, 'percentage') + if (percentage === undefined || isNaN(percentage) === true) { + percentage = defaultPercentage + } + distributeVotingPower(childNode, votingPower * percentage / 100, percentage) } } break @@ -164,7 +223,11 @@ function newGovernanceUserProfileSpace() { if (propertyArray !== undefined) { for (let m = 0; m < propertyArray.length; m++) { let childNode = propertyArray[m] - distributeVotingPower(childNode, votingPower / propertyArray.length) + let percentage = UI.projects.superalgos.utilities.nodeConfig.loadPropertyFromNodeConfig(childNode.payload, 'percentage') + if (percentage === undefined || isNaN(percentage) === true) { + percentage = defaultPercentage + } + distributeVotingPower(childNode, votingPower * percentage / 100, percentage) } } break @@ -174,7 +237,7 @@ function newGovernanceUserProfileSpace() { } } - function drawVotingPower(node, votingPower) { + function drawVotingPower(node, votingPower, percentage) { votingPower = new Intl.NumberFormat().format(votingPower) + ' ' + 'Votes' if (node.payload !== undefined) { if (node.type === 'User Profile') { @@ -192,15 +255,19 @@ function newGovernanceUserProfileSpace() { node.type === 'Position Contribution Claim' || node.type === 'Asset Contribution Claim' || node.type === 'Feature Contribution Claim' - ) { + ) { node.payload.uiObject.valueAngleOffset = 0 node.payload.uiObject.valueAtAngle = false - } else{ + } else { node.payload.uiObject.valueAngleOffset = 180 node.payload.uiObject.valueAtAngle = true } node.payload.uiObject.setValue(votingPower) + + if (percentage !== undefined) { + node.payload.uiObject.setPercentage(percentage.toFixed(2)) + } } } diff --git a/Projects/Superalgos/UI/Spaces/Floating-Space/UiObject.js b/Projects/Superalgos/UI/Spaces/Floating-Space/UiObject.js index b239412ae..9319f70b8 100644 --- a/Projects/Superalgos/UI/Spaces/Floating-Space/UiObject.js +++ b/Projects/Superalgos/UI/Spaces/Floating-Space/UiObject.js @@ -249,7 +249,7 @@ function newUiObject() { thisObject.uiObjectTitle = newUiObjectTitle() thisObject.uiObjectTitle.isVisibleFunction = thisObject.isVisibleFunction - thisObject.uiObjectTitle.container.connectToParent(thisObject.container, false, false, true, true, false, false, true, true) + thisObject.uiObjectTitle.container.connectToParent(thisObject.container, false, false, true, true, false, false, true, true) thisObject.uiObjectTitle.fitFunction = thisObject.fitFunction thisObject.uiObjectTitle.initialize(thisObject.payload) @@ -561,7 +561,7 @@ function newUiObject() { function chainDetachingPhysics() { if (isDragging !== true) { return } if (rightDragging === false) { return } - if (UI.projects.superalgos.spaces.floatingSpace.settings.detachUsingMouse !== true) {return} + if (UI.projects.superalgos.spaces.floatingSpace.settings.detachUsingMouse !== true) { return } let distanceToChainParent = Math.sqrt(Math.pow(thisObject.payload.position.x - thisObject.payload.targetPosition.x, 2) + Math.pow(thisObject.payload.position.y - thisObject.payload.targetPosition.y, 2)) let ratio = distanceToChainParent / previousDistanceToChainParent @@ -667,7 +667,7 @@ function newUiObject() { if (thisObject.payload === undefined) { return } if (thisObject.payload.floatingObject.isFrozen === true) { return } if (rightDragging === false) { return } - if (UI.projects.superalgos.spaces.floatingSpace.settings.detachUsingMouse !== true) {return} + if (UI.projects.superalgos.spaces.floatingSpace.settings.detachUsingMouse !== true) { return } if (thisObject.payload.referenceParent === undefined) { return } @@ -1885,15 +1885,24 @@ function newUiObject() { label = label.substring(0, MAX_LABEL_LENGTH) + '...' } - if (thisObject.isOnFocus === true) { + if (thisObject.valueAtAngle === true && thisObject.payload.angle !== undefined) { labelPoint = { x: position.x - getTextWidth(label) / 2, - y: position.y + radius * 2 / 3 + lineSeparator * 6 + 30 + y: position.y } + labelPoint.x = labelPoint.x + radius * 7 / 3 * Math.cos(toRadians(thisObject.payload.angle + thisObject.valueAngleOffset)) + labelPoint.y = labelPoint.y + radius * 7 / 3 * Math.sin(toRadians(thisObject.payload.angle + thisObject.valueAngleOffset)) + lineSeparator * 1 } else { - labelPoint = { - x: position.x - getTextWidth(label) / 2, - y: position.y + thisObject.payload.floatingObject.currentImageSize / 2 + lineSeparator * 6 + if (thisObject.isOnFocus === true) { + labelPoint = { + x: position.x - getTextWidth(label) / 2, + y: position.y + radius * 2 / 3 + lineSeparator * 6 + 30 + } + } else { + labelPoint = { + x: position.x - getTextWidth(label) / 2, + y: position.y + thisObject.payload.floatingObject.currentImageSize / 2 + lineSeparator * 6 + } } }