diff --git a/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json b/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json index 61df8041c..323766f68 100644 --- a/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json +++ b/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json @@ -1,7 +1,7 @@ { "type": "User Profile", "name": "Luis-Fernando-Molina", - "config": "{\n \"tokens\": 10000000\n}", + "config": "{\n \"tokens\": 10000000,\n\"blockchainAccount\": \"0x9546eAA9380A224a56d7067D712296E9D40d40e1\"\n}", "project": "Governance", "contributionClaims": { "type": "Contribution Claims", diff --git a/Projects/Governance/UI/Function-Libraries/UserReferrals.js b/Projects/Governance/UI/Function-Libraries/UserReferrals.js index bcb6d724d..a3c1927eb 100644 --- a/Projects/Governance/UI/Function-Libraries/UserReferrals.js +++ b/Projects/Governance/UI/Function-Libraries/UserReferrals.js @@ -117,7 +117,13 @@ function newGovernanceFunctionLibraryUserReferrals() { function distributeForProfile(userProfile) { if (userProfile === undefined || userProfile.payload === undefined) { return } - let referringPower = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(userProfile.payload, 'tokens') + let referringPower + if (userProfile.payload.blockchainTokens === undefined) { + referringPower = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(userProfile.payload, 'tokens') + } else { + referringPower = userProfile.payload.blockchainTokens + } + let referringCount = 0 userProfile.payload.referring.ownPower = referringPower distributeUserReferrals(userProfile, referringPower, referringCount) @@ -157,6 +163,8 @@ function newGovernanceFunctionLibraryUserReferrals() { } function calculateAwardedForProfile(userProfile) { + if (userProfile.payload === undefined) { return } + let totalPowerRewardRation = tokensReward / totalReferralsPower if (totalPowerRewardRation < 1) { totalPowerRewardRation = 1 } diff --git a/Projects/Governance/UI/Function-Libraries/Votes.js b/Projects/Governance/UI/Function-Libraries/Votes.js index 790517151..cd5d296f5 100644 --- a/Projects/Governance/UI/Function-Libraries/Votes.js +++ b/Projects/Governance/UI/Function-Libraries/Votes.js @@ -115,7 +115,14 @@ function newGovernanceFunctionLibraryVotes() { } function distributeForProfile(userProfile) { - let votes = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(userProfile.payload, 'tokens') + if (userProfile.payload === undefined) { return } + let votes + if (userProfile.payload.blockchainTokens === undefined) { + votes = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(userProfile.payload, 'tokens') + } else { + votes = userProfile.payload.blockchainTokens + } + distributeVotes(userProfile, votes) } diff --git a/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js b/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js index 827d8fcd0..1b2144f17 100644 --- a/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js +++ b/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js @@ -39,6 +39,40 @@ function newGovernanceUserProfileSpace() { function physics() { if (UI.projects.foundations.spaces.designSpace.workspace === undefined) { return } + let userProfiles = UI.projects.foundations.spaces.designSpace.workspace.getHierarchyHeadsByNodeType('User Profile') + + /* + 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. + */ + let timer = 0 + for (let i = 0; i < userProfiles.length; i++) { + let userProfile = userProfiles[i] + if (userProfile.payload === undefined) { continue } + + if (userProfile.payload.blockchainTokens === undefined) { + let blockchainAccount = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(userProfile.payload, 'blockchainAccount') + if (blockchainAccount !== undefined && blockchainAccount !== "") { + setTimeout(getBlockchainTokens, timer, userProfile) + timer = timer + 5000 + } + } + } + + function getBlockchainTokens(userProfile) { + let blockchainAccount = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(userProfile.payload, 'blockchainAccount') + const url = "https://api.bscscan.com/api?module=account&action=tokenbalance&contractaddress=0xfb981ed9a92377ca4d75d924b9ca06df163924fd&address=" + blockchainAccount + "&tag=latest&apikey=YourApiKeyToken" + + fetch(url).then(function (response) { + return response.json(); + }).then(function (data) { + console.log(data) + userProfile.payload.uiObject.setInfoMessage(data) + userProfile.payload.blockchainTokens = Number(data.result) / 1000000000000000000 + }).catch(function (err) { + userProfile.payload.uiObject.setErrorMessage(err.message) + }); + } } function draw() {