From 80920eabb36a90520e1b2763d9e07aeb700f97d4 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 23 Oct 2021 14:49:22 +0200 Subject: [PATCH] liquidity Balances Laoding Well --- .../User-Profiles/Luis-Fernando-Molina.json | 32 +++++++++---------- .../Schemas/App-Schema/liquidity-program.json | 2 +- .../UI/Function-Libraries/AirdropProgram.js | 2 +- .../UI/Function-Libraries/GithubProgram.js | 2 +- .../UI/Function-Libraries/LiquidityProgram.js | 2 +- .../UI/Function-Libraries/StakingProgram.js | 2 +- .../Spaces/User-Profile-Space/UserProfile.js | 26 ++++++++++----- .../Governance/UI/Utilities/BonusProgram.js | 2 +- .../UI/Utilities/DecendentProgram.js | 2 +- 9 files changed, 41 insertions(+), 31 deletions(-) diff --git a/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json b/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json index e82f447cf..d27019a07 100644 --- a/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json +++ b/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json @@ -11653,7 +11653,7 @@ "liquidityPrograms": { "type": "Liquidity Programs", "name": "New Liquidity Programs", - "config": "{}", + "config": "{\n \"percentage\": 0\n}", "project": "Governance", "liquidityProgram": [ { @@ -11668,12 +11668,12 @@ "id": "5fd55dc1-69c8-473e-9d3d-b39b58818b07", "savedPayload": { "position": { - "x": 38426.01200417474, - "y": 19425.064478540568 + "x": 38529.55549577344, + "y": 19215.099048196847 }, "targetPosition": { - "x": 38188.00600208737, - "y": 19242.43604983795 + "x": 38239.77774788672, + "y": 19137.45333466609 }, "floatingObject": { "isPinned": false, @@ -11691,8 +11691,8 @@ "id": "a081e0a9-ee60-4a56-b5a6-aadb7bd8b052", "savedPayload": { "position": { - "x": 38188.00600208737, - "y": 19242.43604983795 + "x": 38239.77774788672, + "y": 19137.45333466609 }, "targetPosition": { "x": 37950, @@ -11702,7 +11702,7 @@ "isPinned": false, "isFrozen": false, "isCollapsed": false, - "angleToParent": 3, + "angleToParent": 2, "distanceToParent": 3, "arrangementStyle": 0 }, @@ -11757,7 +11757,7 @@ "isPinned": false, "isFrozen": false, "isCollapsed": false, - "angleToParent": 3, + "angleToParent": 2, "distanceToParent": 3, "arrangementStyle": 0 }, @@ -11778,12 +11778,12 @@ "id": "b66c668c-8411-4401-8aa7-10d8b2c4c233", "savedPayload": { "position": { - "x": 38028.315715332035, - "y": 19654.674537959618 + "x": 37794.708572938485, + "y": 19639.363116908775 }, "targetPosition": { - "x": 37989.15785766602, - "y": 19357.241079547475 + "x": 37872.35428646924, + "y": 19349.585369022054 }, "floatingObject": { "isPinned": false, @@ -11801,8 +11801,8 @@ "id": "8c213687-2520-41ff-8b89-f5abaf6f2f2e", "savedPayload": { "position": { - "x": 37989.15785766602, - "y": 19357.241079547475 + "x": 37872.35428646924, + "y": 19349.585369022054 }, "targetPosition": { "x": 37950, @@ -11812,7 +11812,7 @@ "isPinned": false, "isFrozen": false, "isCollapsed": false, - "angleToParent": 3, + "angleToParent": 2, "distanceToParent": 3, "arrangementStyle": 0 }, diff --git a/Projects/Governance/Schemas/App-Schema/liquidity-program.json b/Projects/Governance/Schemas/App-Schema/liquidity-program.json index 164c8cb38..5ac8606a3 100644 --- a/Projects/Governance/Schemas/App-Schema/liquidity-program.json +++ b/Projects/Governance/Schemas/App-Schema/liquidity-program.json @@ -35,7 +35,7 @@ "initialValues": { "config": "{\n\"asset\": \"BTCB\"\n}" }, "attachingRules": { - "compatibleTypes": "->Financial Programs->" + "compatibleTypes": "->Liquidity Programs->" }, "addLeftIcons": true, "level": 1, diff --git a/Projects/Governance/UI/Function-Libraries/AirdropProgram.js b/Projects/Governance/UI/Function-Libraries/AirdropProgram.js index adbd0d15c..ecf4b835b 100644 --- a/Projects/Governance/UI/Function-Libraries/AirdropProgram.js +++ b/Projects/Governance/UI/Function-Libraries/AirdropProgram.js @@ -107,7 +107,7 @@ function newGovernanceFunctionLibraryAirdropProgram() { ) { node.payload.airdropProgram.isActive = false userProfile.payload.uiObject.setErrorMessage( - "Waiting for blockchain balance. It takes 6 seconds to load the balance of each profile, bacause you are using a free API provided by BSC Scan.", + "Waiting for blockchain balance. It takes 1 minute to load the balance of each profile, bacause you are using a free API provided by BSC Scan.", UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR ) return diff --git a/Projects/Governance/UI/Function-Libraries/GithubProgram.js b/Projects/Governance/UI/Function-Libraries/GithubProgram.js index 8c2aa2896..62c139c99 100644 --- a/Projects/Governance/UI/Function-Libraries/GithubProgram.js +++ b/Projects/Governance/UI/Function-Libraries/GithubProgram.js @@ -107,7 +107,7 @@ function newGovernanceFunctionLibraryGithubProgram() { ) { node.payload.githubProgram.isActive = false userProfile.payload.uiObject.setErrorMessage( - "Waiting for blockchain balance. It takes 6 seconds to load the balance of each profile, bacause you are using a free API provided by BSC Scan.", + "Waiting for blockchain balance. It takes 1 minute to load the balance of each profile, bacause you are using a free API provided by BSC Scan.", UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR ) return diff --git a/Projects/Governance/UI/Function-Libraries/LiquidityProgram.js b/Projects/Governance/UI/Function-Libraries/LiquidityProgram.js index 172b1b9b1..6818275e3 100644 --- a/Projects/Governance/UI/Function-Libraries/LiquidityProgram.js +++ b/Projects/Governance/UI/Function-Libraries/LiquidityProgram.js @@ -108,7 +108,7 @@ function newGovernanceFunctionLibraryLiquidityProgram() { ) { node.payload.liquidityProgram.isActive = false userProfile.payload.uiObject.setErrorMessage( - "Waiting for liquidity balance. It takes 6 seconds to load the liquidity provided by each profile, bacause you are using a free API provided by BSC Scan.", + "Waiting for liquidity balance. It takes 1 minute to load the liquidity provided by each profile, bacause you are using a free API provided by BSC Scan.", UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR ) return diff --git a/Projects/Governance/UI/Function-Libraries/StakingProgram.js b/Projects/Governance/UI/Function-Libraries/StakingProgram.js index d3b8a0263..48f3cccc9 100644 --- a/Projects/Governance/UI/Function-Libraries/StakingProgram.js +++ b/Projects/Governance/UI/Function-Libraries/StakingProgram.js @@ -107,7 +107,7 @@ function newGovernanceFunctionLibraryStakingProgram() { ) { node.payload.stakingProgram.isActive = false userProfile.payload.uiObject.setErrorMessage( - "Waiting for blockchain balance. It takes 6 seconds to load the balance of each profile, bacause you are using a free API provided by BSC Scan.", + "Waiting for blockchain balance. It takes 1 minute to load the balance of each profile, bacause you are using a free API provided by BSC Scan.", UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR ) return diff --git a/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js b/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js index 98f938403..2489310a1 100644 --- a/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js +++ b/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js @@ -15,7 +15,7 @@ function newGovernanceUserProfileSpace() { } let waitingForResponses = 0 - const BSC_SCAN_RATE_LIMIT_DELAY = 6000 * 4 + const BSC_SCAN_RATE_LIMIT_DELAY = 6000 * 5 let reputationByAddress = new Map() return thisObject @@ -373,7 +373,12 @@ function newGovernanceUserProfileSpace() { let userProfile = userProfiles[i] if (userProfile.payload === undefined) { continue } + if (userProfile.payload.bloackchainBalancesLoading === true) { + return + } + if (userProfile.payload.blockchainTokens === undefined) { + userProfile.payload.bloackchainBalancesLoading = true getBlockchainAccount(userProfile) return } @@ -394,6 +399,7 @@ function newGovernanceUserProfileSpace() { httpRequest(JSON.stringify(request.params), request.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) { userProfile.payload.uiObject.setErrorMessage( @@ -422,13 +428,16 @@ function newGovernanceUserProfileSpace() { blockchainAccount !== "" && userProfile.payload.blockchainTokens === undefined ) { - waitingForResponses++ + userProfile.payload.liquidityTokens = { BTCB: 0, BNB: 0, BUSD: 0 } + waitingForResponses++ + waitingForResponses++ + waitingForResponses++ setTimeout(getBPancakeTokens, BSC_SCAN_RATE_LIMIT_DELAY / 4 * 1, userProfile, blockchainAccount, 'BTCB', UI.projects.governance.globals.saToken.SA_TOKEN_BSC_PANCAKE_LIQUIDITY_POOL_BTCB_CONTRACT_ADDRESS) setTimeout(getBPancakeTokens, BSC_SCAN_RATE_LIMIT_DELAY / 4 * 2, userProfile, blockchainAccount, 'BNB', UI.projects.governance.globals.saToken.SA_TOKEN_BSC_PANCAKE_LIQUIDITY_POOL_BNB_CONTRACT_ADDRESS) setTimeout(getBPancakeTokens, BSC_SCAN_RATE_LIMIT_DELAY / 4 * 3, userProfile, blockchainAccount, 'BUSD', UI.projects.governance.globals.saToken.SA_TOKEN_BSC_PANCAKE_LIQUIDITY_POOL_BUSD_CONTRACT_ADDRESS) @@ -437,7 +446,6 @@ function newGovernanceUserProfileSpace() { Now we get the SA Tokens Balance. */ waitingForResponses++ - userProfile.payload.blockchainTokens = 0 // We need to set this value here so that the next call to BSCSCAN is not done more than once. setTimeout(getBlockchainTokens, BSC_SCAN_RATE_LIMIT_DELAY / 4 * 4, userProfile, blockchainAccount) } } @@ -450,14 +458,15 @@ function newGovernanceUserProfileSpace() { fetch(url).then(function (response) { return response.json(); }).then(function (data) { - //console.log(data) + userProfile.payload.bloackchainBalancesLoading = false if (data.result === "Max rate limit reached, please use API Key for higher rate limit") { - userProfile.payload.blockchainTokens = undefined // This enables this profile to query the blockchain again. + userProfile.payload.blockchainTokens = undefined } else { userProfile.payload.uiObject.setInfoMessage('Blockchan Balance Succesfully Loaded.', UI.projects.governance.globals.designer.SET_INFO_COUNTER_FACTOR ) userProfile.payload.blockchainTokens = Number(data.result) / 1000000000000000000 + console.log('[INFO] SA Balance of ' + userProfile.name + ' is ', userProfile.payload.blockchainTokens) userProfile.payload.reputation = Math.min(reputationByAddress.get(blockchainAccount.toLowerCase()) | 0, userProfile.payload.blockchainTokens) console.log('[INFO] Reputation of ' + userProfile.name + ' is ', userProfile.payload.reputation) } @@ -475,7 +484,7 @@ function newGovernanceUserProfileSpace() { } function getBPancakeTokens(userProfile, blockchainAccount, asset, marketContract) { - console.log('[INFO] Loading Pancake Balance for User Profile: ', userProfile.name, 'blockchainAccount: ', blockchainAccount) + console.log('[INFO] Loading Pancake Balance for User Profile: ', userProfile.name, 'blockchainAccount: ', blockchainAccount, 'asset: ', asset) const url = "https://api.bscscan.com/api?module=account&action=tokenbalance&contractaddress=" + marketContract + "&address=" + blockchainAccount + "&tag=latest&apikey=YourApiKeyToken" fetch(url).then(function (response) { @@ -483,9 +492,10 @@ function newGovernanceUserProfileSpace() { }).then(function (data) { //console.log(data) if (data.result === "Max rate limit reached, please use API Key for higher rate limit") { - userProfile.payload.liquidityTokens = undefined // This enables this profile to query the blockchain again. + console.log('[WARN] Rate Limit Reached fetching liquidity tokens for asset ' + asset + ' of user profile ' + userProfile.name) + userProfile.payload.blockchainTokens = undefined } else { - userProfile.payload.uiObject.setInfoMessage('Pancake Balance Succesfully Loaded.', + userProfile.payload.uiObject.setInfoMessage('Pancake Balance Succesfully Loaded for asset ' + asset, UI.projects.governance.globals.designer.SET_INFO_COUNTER_FACTOR ) userProfile.payload.liquidityTokens[asset] = Number(data.result) / 1000000000000000000 diff --git a/Projects/Governance/UI/Utilities/BonusProgram.js b/Projects/Governance/UI/Utilities/BonusProgram.js index 5ef959426..df89a8cd2 100644 --- a/Projects/Governance/UI/Utilities/BonusProgram.js +++ b/Projects/Governance/UI/Utilities/BonusProgram.js @@ -102,7 +102,7 @@ function newGovernanceUtilitiesBonusProgram() { ) { node.payload[programPropertyName].isActive = false userProfile.payload.uiObject.setErrorMessage( - "Waiting for blockchain balance. It takes 6 seconds to load the balance of each profile, bacause you are using a free API provided by BSC Scan.", + "Waiting for blockchain balance. It takes 1 minute to load the balance of each profile, bacause you are using a free API provided by BSC Scan.", UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR ) return diff --git a/Projects/Governance/UI/Utilities/DecendentProgram.js b/Projects/Governance/UI/Utilities/DecendentProgram.js index 70a3d9b0b..fe94ee3f8 100644 --- a/Projects/Governance/UI/Utilities/DecendentProgram.js +++ b/Projects/Governance/UI/Utilities/DecendentProgram.js @@ -169,7 +169,7 @@ function newGovernanceUtilitiesDecendentProgram() { ) { node.payload[programPropertyName].isActive = false userProfile.payload.uiObject.setErrorMessage( - "Waiting for blockchain balance. It takes 6 seconds to load the balance of each profile, bacause you are using a free API provided by BSC Scan.", + "Waiting for blockchain balance. It takes 1 minute to load the balance of each profile, bacause you are using a free API provided by BSC Scan.", UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR ) return