_(Previous Post: [Part 2](/@jfollas/write-a-steemit-web-app-part-2-followers-and-following))_ # What is Voting Power? Voting Power is a rate-limiting feature of Steem to help prevent abuse. Each vote cast reduces the user's voting power by 2% of their remaining pool. So, if someone (or a bot) goes wild and upvotes hundreds of posts, then each upvote is worth less than the previous one (eventually being worth nothing). Voting power regenerates linearly over 5 days, or 20% per day. So, with HF19, most people have set a goal of only depleting 20% of their voting power per day so that it will regenerate to 100% within 24 hours. This means that they can vote 11 times (at 100% per vote - only worth noting for those with enough steem power to unlock the ability to choose how much each vote is worth): #|Voting Power ----|---- (Start)|100.00% Vote 1|98.0% Vote 2|96.04% Vote 3|94.12% Vote 4|92.24% Vote 5|90.40% Vote 6|88.58% Vote 7|86.81% Vote 8|85.08% Vote 9|83.37% Vote 10|81.71% **Vote 11**|**80.07%** ## Representing Voting Power in a Web App When you fetch account information with Steem.js, such as with the `getAccounts()` function, you get a `voting_power` number in the account data object: `{ ..., voting_power: 9668, ... }`. However, if you keep refreshing, you will not see this number ever change on its own - even if it's been five days since the last vote. This value is only updated when a user casts a vote. _Note: A LOT of the Steem applications out there are guilty of just showing this value... so even if you are really at 100% voting power, the apps won't reflect that._ But, there is another value in the account data object that is also updated when a vote is cast: `{..., last_vote_time: "2017-07-03T01:12:15", ...}`. So, your web app must do the task of calculating the current voting power value given these two inputs. The basic formula is to take the reported `voting_power` and add in how much should have been regenerated since the `last_vote_time`. The maximum result would be 100%. ## JavaScript Code In the [first post](/@jfollas/write-a-steemit-web-app-part-1-hello-user) of this series, we used the following code in the naive way to represent the user's voting power: ```javascript vm.$set(vm.userData, 'power', result[0].voting_power / 100) ``` <br/>To correct this, we must first figure out how many seconds have passed: ```javascript let secondsago = (new Date - new Date(result[0].last_vote_time + "Z")) / 1000 ``` <br/>Next, divide the `secondsago` by the number of seconds in 5 days (`432000`) in order to get a percentage of how much of the 5 days has elapsed. Multiply this by `10000` (100%) to calculate how much voting power has regenerated so far, and add to the `voting_power` value from the account object: ```javascript let vpow = result[0].voting_power + (10000 * secondsago / 432000) ``` <br/>Now we can set the value in our viewmodel (taking care of formatting and ensuring that the max is 100%): ```javascript vm.$set(vm.userData, 'power', Math.min(vpow / 100, 100).toFixed(2)) ``` <br/>The whole thing together would look like: ```javascript steem.api.getAccountsAsync([accountName]) .then(function (result) { ... let secondsago = (new Date - new Date(result[0].last_vote_time + "Z")) / 1000 let vpow = result[0].voting_power + (10000 * secondsago / 432000) vm.$set(vm.userData, 'power', Math.min(vpow / 100, 100).toFixed(2)) ... }) ``` <br/>Improvements to this would be to periodically recalculate the value using a timer so that the user always sees their latest voting power (especially if they are waiting for it to tick over to 100%).  _(Next Post: [Part 4](/@jfollas/write-a-steemit-web-app-part-4-calculating-steem-power))_
author | jfollas |
---|---|
permlink | write-a-steemit-web-app-part-3-current-voting-power |
category | steem-dev |
json_metadata | {"tags":["steem-dev","steem","developer","javascript","steemjs"],"image":["https://steemitimages.com/DQmZBbDGvKqM8V46NHaXoT7nZvrXhHLtTysrhixRu8eS87g/javascriptlogo.png"],"links":["/@jfollas/write-a-steemit-web-app-part-2-followers-and-following","/@jfollas/write-a-steemit-web-app-part-1-hello-user","/@jfollas/write-a-steemit-web-app-part-4-calculating-steem-power"],"app":"steemit/0.1","format":"markdown"} |
created | 2017-07-03 03:37:09 |
last_update | 2017-07-08 21:21:18 |
depth | 0 |
children | 5 |
last_payout | 2017-07-10 03:37:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.035 HBD |
curator_payout_value | 0.001 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 3,852 |
author_reputation | 4,351,701,088,490 |
root_title | "Write a Steemit Web App: Part 3 - Current Voting Power" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 0 |
post_id | 7,094,279 |
net_rshares | 5,247,600,076 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
curator | 0 | 2,865,511,857 | 100% | ||
steemitboard | 0 | 195,884,856 | 2% | ||
jfollas | 0 | 1,245,836,538 | 100% | ||
musicfever | 0 | 377,227,952 | 100% | ||
konstantint | 0 | 0 | 100% | ||
matthewdavid | 0 | 563,138,873 | 100% | ||
therealwolf | 0 | 0 | 2% | ||
purec | 0 | 0 | 100% |
Thanks so much for posting these. I look forward to trying out the code.
author | matthewdavid |
---|---|
permlink | re-jfollas-write-a-steemit-web-app-part-3-current-voting-power-20170703t042141736z |
category | steem-dev |
json_metadata | {"tags":["steem-dev"],"app":"steemit/0.1"} |
created | 2017-07-03 04:21:42 |
last_update | 2017-07-03 04:21:42 |
depth | 1 |
children | 0 |
last_payout | 2017-07-10 04:21:42 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 72 |
author_reputation | 2,155,255,892,877 |
root_title | "Write a Steemit Web App: Part 3 - Current Voting Power" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 7,097,718 |
net_rshares | 0 |
To make the refresh add this function to the end where refreshAccountData function was called: ``` refreshAccountData(vm.user) function timeout() { refreshAccountData(vm.user,true) setTimeout(function () { timeout(); }, 1000); } timeout() ``` No need to refresh follow(ers/ing) each time: ``` function refreshAccountData(accountName,refresh=false) { ... if( ! refresh ) { getFollowersList() getFollowingList() getIgnoredList() ... } ```
author | money-dreamer |
---|---|
permlink | re-jfollas-write-a-steemit-web-app-part-3-current-voting-power-20171220t035221799z |
category | steem-dev |
json_metadata | {"tags":["steem-dev"],"app":"steemit/0.1"} |
created | 2017-12-20 03:52:21 |
last_update | 2017-12-20 03:52:21 |
depth | 1 |
children | 0 |
last_payout | 2017-12-27 03:52:21 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 619 |
author_reputation | 4,495,208,779,741 |
root_title | "Write a Steemit Web App: Part 3 - Current Voting Power" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 24,288,913 |
net_rshares | 0 |
Sir you are a great inspiration for people out there.
author | musicfever |
---|---|
permlink | re-jfollas-write-a-steemit-web-app-part-3-current-voting-power-20170703t035456007z |
category | steem-dev |
json_metadata | {"tags":["steem-dev"],"app":"steemit/0.1"} |
created | 2017-07-03 03:54:57 |
last_update | 2017-07-03 03:54:57 |
depth | 1 |
children | 0 |
last_payout | 2017-07-10 03:54:57 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 53 |
author_reputation | 1,937,741,063 |
root_title | "Write a Steemit Web App: Part 3 - Current Voting Power" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 7,095,664 |
net_rshares | 371,424,445 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
musicfever | 0 | 371,424,445 | 100% |
3 months later, I find your post. Helped me tremendously, wish I had found it sooner so I could have voted on it. Thanks for putting this up here for people like me to find.
author | shaunmza |
---|---|
permlink | re-jfollas-write-a-steemit-web-app-part-3-current-voting-power-20171017t161033146z |
category | steem-dev |
json_metadata | {"tags":["steem-dev"],"app":"steemit/0.1"} |
created | 2017-10-17 16:10:33 |
last_update | 2017-10-17 16:10:33 |
depth | 1 |
children | 0 |
last_payout | 2017-10-24 16:10:33 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 174 |
author_reputation | 17,139,522,306,343 |
root_title | "Write a Steemit Web App: Part 3 - Current Voting Power" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 17,906,595 |
net_rshares | 0 |
Congratulations @jfollas! You have completed some achievement on Steemit and have been rewarded with new badge(s) : [](http://steemitboard.com/@jfollas) Award for the number of posts published Click on any badge to view your own Board of Honnor on SteemitBoard. For more information about SteemitBoard, click [here](https://steemit.com/@steemitboard) If you no longer want to receive notifications, reply to this comment with the word `STOP` By upvoting this notification, you can help all Steemit users. Learn how [here](https://steemit.com/steemitboard/@steemitboard/http-i-cubeupload-com-7ciqeo-png)!
author | steemitboard |
---|---|
permlink | steemitboard-notify-jfollas-20170703t055141000z |
category | steem-dev |
json_metadata | {"image":["https://steemitboard.com/img/notifications.png"]} |
created | 2017-07-03 05:51:39 |
last_update | 2017-07-03 05:51:39 |
depth | 1 |
children | 0 |
last_payout | 2017-07-10 05:51:39 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 691 |
author_reputation | 38,975,615,169,260 |
root_title | "Write a Steemit Web App: Part 3 - Current Voting Power" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 7,104,647 |
net_rshares | 0 |