Merge pull request #1091 from Luis-Fernando-Molina/next-version

Contribution: Vote Switching implemented
This commit is contained in:
Luis Fernando Molina authored and GitHub committed 2021-06-05 17:10:57 -04:00
commit d304bf3673
11 files changed
+99 -71

No files matched your search

@@ -26,7 +26,7 @@
"config": true
},
"initialValues": {
"config": "{\n \"description\": \"\"\n}"
"config": "{}"
},
"addLeftIcons": true,
"level": 2,
@@ -28,7 +28,7 @@
"config": true
},
"initialValues": {
"config": "{\n \"description\": \"\"\n}"
"config": "{}"
},
"addLeftIcons": true,
"level": 2,
@@ -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"
}
@@ -26,7 +26,7 @@
"config": true
},
"initialValues": {
"config": "{\n \"description\": \"\"\n}"
"config": "{}"
},
"addLeftIcons": true,
"level": 2,
@@ -27,7 +27,7 @@
"config": true
},
"initialValues": {
"config": "{\n \"description\": \"\"\n}"
"config": "{}"
},
"addLeftIcons": true,
"level": 2,
@@ -26,7 +26,7 @@
"config": true
},
"initialValues": {
"config": "{\n \"description\": \"\"\n}"
"config": "{}"
},
"addLeftIcons": true,
"level": 2,
@@ -26,7 +26,7 @@
"config": true
},
"initialValues": {
"config": "{\n \"description\": \"\"\n}"
"config": "{}"
},
"addLeftIcons": true,
"level": 2,
@@ -25,7 +25,7 @@
"config": true
},
"initialValues": {
"config": "{\n \"description\": \"\"\n}"
"config": "{}"
},
"addLeftIcons": true,
"level": 2,
@@ -76,7 +76,7 @@
"config": true
},
"initialValues": {
"config": "{\n \"description\": \"\"\n}"
"config": "{}"
},
"addLeftIcons": true,
"level": 2,
@@ -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))
}
}
}
@@ -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
}
}
}