diff --git a/Projects/Governance/UI/Function-Libraries/Claims.js b/Projects/Governance/UI/Function-Libraries/Claims.js index 75f3a232f..099b79c57 100644 --- a/Projects/Governance/UI/Function-Libraries/Claims.js +++ b/Projects/Governance/UI/Function-Libraries/Claims.js @@ -6,126 +6,213 @@ function newGovernanceFunctionLibraryClaims() { return thisObject function calculate( - pools, features, assets, - positions + positions, + userProfiles ) { - /* Claim Calculation Follows */ + + /* Claim Reset Follows */ for (let i = 0; i < assets.length; i++) { let assetsNode = assets[i] - calculateForNode(assetsNode) + resetClaims(assetsNode) } - /* Claim Calculation Follows */ + /* Claim Reset Follows */ for (let i = 0; i < features.length; i++) { let featuresNode = features[i] - calculateForNode(featuresNode) + resetClaims(featuresNode) + } + + /* Claim Reset Follows */ + for (let i = 0; i < positions.length; i++) { + let positionsNode = positions[i] + resetClaims(positionsNode) + } + + /* Claim Count Follows */ + for (let i = 0; i < userProfiles.length; i++) { + let userProfilesNode = userProfiles[i] + countForNode(userProfilesNode.contributionClaims) } /* Claim Calculation Follows */ - for (let i = 0; i < positions.length; i++) { - let positionsNode = positions[i] - calculateForNode(positionsNode) + for (let i = 0; i < userProfiles.length; i++) { + let userProfilesNode = userProfiles[i] + calculateForNode(userProfilesNode.contributionClaims) + } + } + + function resetClaims(node) { + if (node === undefined) { return } + if (node.payload === undefined) { return } + + if ( + node.type !== 'Asset Class' && + node.type !== 'Feature Class' && + node.type !== 'Position Class' + ) { + if (node.payload.votes !== undefined) { + node.payload.claimsCount = 0 + node.payload.claimsVotes = 0 + } + } + + 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] + resetClaims(childNode) + } + break + case 'array': { + let propertyArray = node[property.name] + if (propertyArray !== undefined) { + for (let m = 0; m < propertyArray.length; m++) { + let childNode = propertyArray[m] + resetClaims(childNode) + } + } + break + } + } + } + } + } + + function countForNode(node) { + if (node === undefined) { return } + if (node.payload === undefined) { return } + + if ( + node.type !== 'Asset Contributions Folder' && + node.type !== 'Feature Contributions Folder' && + node.type !== 'Position Contributions Folder' && + node.type !== 'Contribution Claims' + ) { + if ( + node.payload.votes !== undefined && + node.payload.votes > 0 && + node.payload.referenceParent !== undefined && + node.payload.referenceParent.payload.votes !== undefined && + node.payload.referenceParent.payload.votes > 0 && + node.payload.referenceParent.payload.weight !== undefined && + node.payload.referenceParent.payload.weight > 0 && + node.payload.referenceParent.payload.claimsCount !== undefined && + node.payload.referenceParent.payload.claimsVotes !== undefined + ) { + node.payload.referenceParent.payload.claimsCount++ + node.payload.referenceParent.payload.claimsVotes = node.payload.referenceParent.payload.claimsVotes + node.payload.votes + } + } + + 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] + countForNode(childNode) + } + break + case 'array': { + let propertyArray = node[property.name] + if (propertyArray !== undefined) { + for (let m = 0; m < propertyArray.length; m++) { + let childNode = propertyArray[m] + countForNode(childNode) + } + } + break + } + } + } } } function calculateForNode(node) { + if (node === undefined) { return } + if (node.payload === undefined) { return } - let totalVotes = 0 - countVotesAndResetClaims(node) - applyClaimCalculation(node) - - function countVotesAndResetClaims(node) { - if (node === undefined) { return } - if (node.payload === undefined) { return } - + if ( + node.type !== 'Asset Contributions Folder' && + node.type !== 'Feature Contributions Folder' && + node.type !== 'Position Contributions Folder' && + node.type !== 'Contribution Claims' + ) { if ( - node.type !== 'Asset Class' && - node.type !== 'Feature Class' && - node.type !== 'Position Class' + node.payload.votes !== undefined && + node.payload.votes > 0 && + node.payload.referenceParent !== undefined && + node.payload.referenceParent.payload.votes !== undefined && + node.payload.referenceParent.payload.votes > 0 && + node.payload.referenceParent.payload.weight !== undefined && + node.payload.referenceParent.payload.weight > 0 && + node.payload.referenceParent.payload.claimsCount !== undefined && + node.payload.referenceParent.payload.claimsVotes !== undefined ) { - if (node.payload.votes !== undefined) { - totalVotes = totalVotes + node.payload.votes - } - } + /* + We will use the concept of Vote Ratio for the situation in which the total votes in claims exeeds the + amount of votes for wigthing. When this happen the Votes Ratio will be used to redude the amount of + tokens awarded proportionally to how much was exeeded. + */ + let votesRatio = node.payload.referenceParent.payload.votes / node.payload.referenceParent.payload.claimsVotes + if (votesRatio > 1) { votesRatio = 1 } + /* + Share Count means the amount to claims pointing to the same potential tokens reward. + */ + let shareCount = node.payload.referenceParent.payload.claimsCount + let sharePercentage = node.payload.votes * 100 / node.payload.referenceParent.payload.claimsVotes + let awarded = node.payload.votes / node.payload.referenceParent.payload.votes * node.payload.referenceParent.payload.tokens * votesRatio + let awardedPercentage = node.payload.votes / node.payload.referenceParent.payload.votes * 100 * votesRatio - 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] - countVotesAndResetClaims(childNode) - } - break - case 'array': { - let propertyArray = node[property.name] - if (propertyArray !== undefined) { - for (let m = 0; m < propertyArray.length; m++) { - let childNode = propertyArray[m] - countVotesAndResetClaims(childNode) - } - } - break - } - } - } + drawClaims(node, shareCount, sharePercentage, awarded, awardedPercentage) } } - function applyClaimCalculation(node) { - if (node === undefined) { return } - if (node.payload === undefined) { return } + let schemaDocument = getSchemaDocument(node) + if (schemaDocument === undefined) { return } - if ( - node.type !== 'Pool Class' && - node.type !== 'Asset Class' && - node.type !== 'Feature Class' && - node.type !== 'Position Class' - ) { - if (node.payload.votes !== undefined) { - if (node.payload.votes !== undefined) { - node.payload.weight = node.payload.votes / totalVotes + 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] + calculateForNode(childNode) } - } - } - - /* - 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] - applyClaimCalculation(childNode) - } - break - case 'array': { - let propertyArray = node[property.name] - if (propertyArray !== undefined) { - for (let m = 0; m < propertyArray.length; m++) { - let childNode = propertyArray[m] - applyClaimCalculation(childNode) - } + break + case 'array': { + let propertyArray = node[property.name] + if (propertyArray !== undefined) { + for (let m = 0; m < propertyArray.length; m++) { + let childNode = propertyArray[m] + calculateForNode(childNode) } - break } + break } } } } } + + function drawClaims(node, shareCount, sharePercentage, awarded, awardedPercentage) { + let satatus = + 'Awarded: ' + + new Intl.NumberFormat().format(awarded) + + ' ' + 'SA Tokens' + ' - ' + + 'From Reward: ' + awardedPercentage.toFixed(2) + '%' + ' - ' + + 'Shared Between: ' + shareCount + ' claims' + ' - ' + + 'Share of Claims: ' + sharePercentage.toFixed(2) + '%' + node.payload.uiObject.setStatus(satatus) + } } \ No newline at end of file diff --git a/Projects/Governance/UI/Function-Libraries/DistributionProcess.js b/Projects/Governance/UI/Function-Libraries/DistributionProcess.js index 0d311bd31..5dc6308a8 100644 --- a/Projects/Governance/UI/Function-Libraries/DistributionProcess.js +++ b/Projects/Governance/UI/Function-Libraries/DistributionProcess.js @@ -27,15 +27,16 @@ function newGovernanceFunctionLibraryDistributionProcess() { assets, positions ) -/* - UI.projects.governance.functionLibraries.claims.calculate( - features, - assets, - positions - ) -*/ + UI.projects.governance.functionLibraries.tokens.calculate( pools ) + + UI.projects.governance.functionLibraries.claims.calculate( + features, + assets, + positions, + userProfiles + ) } } \ No newline at end of file diff --git a/Projects/Governance/UI/Function-Libraries/Tokens.js b/Projects/Governance/UI/Function-Libraries/Tokens.js index da49c1307..d2be53607 100644 --- a/Projects/Governance/UI/Function-Libraries/Tokens.js +++ b/Projects/Governance/UI/Function-Libraries/Tokens.js @@ -26,14 +26,14 @@ function newGovernanceFunctionLibraryTokens() { } function poolsDistribute(pools) { - let tokenFlow = UI.projects.superalgos.utilities.nodeConfig.loadPropertyFromNodeConfig(pools.payload, 'tokens') - distributeTokens(pools, tokenFlow) + let tokens = UI.projects.superalgos.utilities.nodeConfig.loadPropertyFromNodeConfig(pools.payload, 'tokens') + distributeTokens(pools, tokens) } function resetTokenFlow(node) { if (node === undefined) { return } if (node.payload === undefined) { return } - node.payload.tokenFlow = 0 + node.payload.tokens = 0 /* If there is a reference parent defined, this means that the token flow is transfered to it and not distributed among children. @@ -83,7 +83,7 @@ function newGovernanceFunctionLibraryTokens() { } } - function distributeTokens(node, tokenFlow) { + function distributeTokens(node, tokens) { if (node === undefined) { return } if (node.payload === undefined) { return } /* @@ -97,7 +97,7 @@ function newGovernanceFunctionLibraryTokens() { if ( schemaDocument.isHierarchyHead === true ) { - drawTokenFlow(node, tokenFlow) + drawTokenFlow(node, tokens) } /* We will also have tokens at nodes with weight. @@ -107,15 +107,15 @@ function newGovernanceFunctionLibraryTokens() { node.payload.weight !== undefined && node.payload.weight !== 0 ) { - node.payload.tokenFlow = tokenFlow * node.payload.weight - drawTokenFlow(node, node.payload.tokenFlow, node.payload.weight) + node.payload.tokens = tokens * node.payload.weight + drawTokenFlow(node, node.payload.tokens, 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. */ if (node.payload.referenceParent !== undefined) { - distributeTokens(node.payload.referenceParent, node.payload.tokenFlow) + distributeTokens(node.payload.referenceParent, node.payload.tokens) return } /* @@ -135,7 +135,7 @@ function newGovernanceFunctionLibraryTokens() { case 'node': { if (node.type === 'Pools' && property.name === "votesDistribution") { let childNode = node[property.name] - distributeTokens(childNode, tokenFlow) + distributeTokens(childNode, tokens) } } break @@ -144,7 +144,7 @@ function newGovernanceFunctionLibraryTokens() { if (propertyArray !== undefined) { for (let m = 0; m < propertyArray.length; m++) { let childNode = propertyArray[m] - distributeTokens(childNode, tokenFlow) + distributeTokens(childNode, tokens) } } break @@ -154,15 +154,16 @@ function newGovernanceFunctionLibraryTokens() { } } - function drawTokenFlow(node, tokenFlow, weight) { + function drawTokenFlow(node, tokens, weight) { + let status if (weight !== undefined && weight !== 0) { - tokenFlow = new Intl.NumberFormat().format(tokenFlow) + ' ' + 'SA Tokens' + ' - ' + 'Weight: ' + weight.toFixed(2) + status = new Intl.NumberFormat().format(tokens) + ' ' + 'SA Tokens Reward' + ' - ' + 'Weight: ' + weight.toFixed(2) } else { - tokenFlow = new Intl.NumberFormat().format(tokenFlow) + ' ' + 'SA Tokens' + status = new Intl.NumberFormat().format(tokens) + ' ' + 'SA Tokens Reward' } if (node.payload !== undefined) { - node.payload.uiObject.setStatus(tokenFlow) + node.payload.uiObject.setStatus(status) } } } \ No newline at end of file diff --git a/Projects/Superalgos/UI/Spaces/Floating-Space/UiObject.js b/Projects/Superalgos/UI/Spaces/Floating-Space/UiObject.js index 9319f70b8..3b500eec7 100644 --- a/Projects/Superalgos/UI/Spaces/Floating-Space/UiObject.js +++ b/Projects/Superalgos/UI/Spaces/Floating-Space/UiObject.js @@ -1937,7 +1937,7 @@ function newUiObject() { browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY if (radius > 6) { - const MAX_LABEL_LENGTH = 100 + const MAX_LABEL_LENGTH = 120 label = currentStatus