Hello, Among all the chaos of the rc system, it's time to update your apps ! The new mana system means that the old way of calculating voting power is no longer correct. I've updated [SteemSnippets](https://steemit.com/programming/@howo/introducting-steemsnippets) with a new code snippet for mana calculation. Huge thanks to @asgarth who provided most of the code, I only improved it slightly following @roadscape remarks and bundled it into a function. So anyways, here's the function : ``` var steem = require('steem'); steem.api.setOptions({url: 'https://api.steemit.com'}); /** * Gets the voting power of an account. code mostly by @asgarth * @param {String} account - account of whom we want to check the steem power * @param {String} callback - callback which will have the voting power as parameter */ function getvotingpower(account_name, callback) { return new Promise(resolve => { steem.api.getAccounts([account_name], function (err, account) { account = account[0]; const totalShares = parseFloat(account.vesting_shares) + parseFloat(account.received_vesting_shares) - parseFloat(account.delegated_vesting_shares) - parseFloat(account.vesting_withdraw_rate); const elapsed = Math.floor(Date.now() / 1000) - account.voting_manabar.last_update_time; const maxMana = totalShares * 1000000; // 432000 sec = 5 days let currentMana = parseFloat(account.voting_manabar.current_mana) + elapsed * maxMana / 432000; if (currentMana > maxMana) { currentMana = maxMana; } const currentManaPerc = currentMana * 100 / maxMana; return resolve(currentManaPerc); }); }); } async function example() { const vp = await getvotingpower("howo"); console.log(vp); } example(); ``` Code is also on [github](https://github.com/drov0/steemsnippets/blob/master/steemjs/voting_power/voting_power.js) Happy hf20 ! :) Of and if you have a spot left please consider voting for [SteemPress as witness](https://steemit.com/steempress/@steempress/steempress-vision-2018-roadmap-going-full-time-and-launching-witness-steempress)
author | howo |
---|---|
permlink | how-to-calculate-voting-power-with-hf20-in-js |
category | steem |
json_metadata | {"tags":["steem","development","steemsnippets","hf20","vp"],"users":["asgarth","roadscape"],"links":["https://steemit.com/programming/@howo/introducting-steemsnippets","https://github.com/drov0/steemsnippets/blob/master/steemjs/voting_power/voting_power.js","https://steemit.com/steempress/@steempress/steempress-vision-2018-roadmap-going-full-time-and-launching-witness-steempress"],"app":"steemit/0.1","format":"markdown"} |
created | 2018-09-27 20:04:24 |
last_update | 2018-09-27 20:04:24 |
depth | 0 |
children | 4 |
last_payout | 2018-10-04 20:04:24 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.871 HBD |
curator_payout_value | 0.284 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 2,199 |
author_reputation | 515,737,853,740,869 |
root_title | "How to calculate voting power with hf20 in js." |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 72,269,969 |
net_rshares | 662,770,515,459 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
lemouth | 0 | 119,251,472,481 | 50% | ||
fukako | 0 | 40,763,011,937 | 100% | ||
tarazkp | 0 | 153,443,260,804 | 11% | ||
jakipatryk | 0 | 15,098,061,050 | 50% | ||
jorgedr0id | 0 | 9,401,083,281 | 100% | ||
m31 | 0 | 174,434,154,476 | 33% | ||
howo | 0 | 122,859,756,758 | 100% | ||
makerhacks | 0 | 9,740,737,351 | 20% | ||
robotics101 | 0 | 4,940,047,193 | 100% | ||
cpufronz | 0 | 3,363,923,218 | 100% | ||
saqibnazir | 0 | 182,966,058 | 100% | ||
asgarth | 0 | 5,974,671,843 | 100% | ||
irelandscape | 0 | 1,611,691,120 | 100% | ||
programmingvalue | 0 | 1,415,851,443 | 100% | ||
papamidnite | 0 | 289,826,446 | 100% |
Thank you, this is so helpful!
author | kjnk |
---|---|
permlink | re-howo-how-to-calculate-voting-power-with-hf20-in-js-20180930t100212255z |
category | steem |
json_metadata | {"tags":["steem"],"app":"steemit/0.1"} |
created | 2018-09-30 10:02:12 |
last_update | 2018-09-30 10:02:12 |
depth | 1 |
children | 0 |
last_payout | 2018-10-07 10:02:12 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.122 HBD |
curator_payout_value | 0.039 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 30 |
author_reputation | 670,294,526,884 |
root_title | "How to calculate voting power with hf20 in js." |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 72,348,311 |
net_rshares | 80,319,732,429 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
kjnk | 0 | 78,932,760,295 | 100% | ||
programmingvalue | 0 | 1,386,972,134 | 100% |
the variable in the description, account, does not exist. callback doesn't do anything thx for the contribution.
author | lanmower |
---|---|
permlink | re-howo-how-to-calculate-voting-power-with-hf20-in-js-20180929t134100805z |
category | steem |
json_metadata | {"tags":["steem"],"app":"steemit/0.1"} |
created | 2018-09-29 13:41:03 |
last_update | 2018-09-29 13:41:03 |
depth | 1 |
children | 1 |
last_payout | 2018-10-06 13:41:03 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.075 HBD |
curator_payout_value | 0.024 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 114 |
author_reputation | -4,369,177,824,692 |
root_title | "How to calculate voting power with hf20 in js." |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 0 |
post_id | 72,315,614 |
net_rshares | 50,772,478,835 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
howo | 0 | 50,772,478,835 | 24% |
Good catch ! Copy pasted from my template a bit too fast. thanks :)
author | howo |
---|---|
permlink | re-lanmower-re-howo-how-to-calculate-voting-power-with-hf20-in-js-20180929t144612198z |
category | steem |
json_metadata | {"tags":["steem"],"app":"steemit/0.1"} |
created | 2018-09-29 14:46:12 |
last_update | 2018-09-29 14:46:12 |
depth | 2 |
children | 0 |
last_payout | 2018-10-06 14:46:12 |
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 | 67 |
author_reputation | 515,737,853,740,869 |
root_title | "How to calculate voting power with hf20 in js." |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 72,317,924 |
net_rshares | 0 |
author | programmingvalue |
---|---|
permlink | re-howo-how-to-calculate-voting-power-with-hf20-in-js-20180930t100248293z |
category | steem |
json_metadata | {"tags":["steem"],"app":"steemit/0.1"} |
created | 2018-09-30 10:02:48 |
last_update | 2018-09-30 10:02:48 |
depth | 1 |
children | 0 |
last_payout | 2018-10-07 10:02:48 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.110 HBD |
curator_payout_value | 0.035 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 35 |
author_reputation | 2,087,259,996,059 |
root_title | "How to calculate voting power with hf20 in js." |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 72,348,327 |
net_rshares | 72,886,498,779 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
kjnk | 0 | 72,584,067,097 | 100% | ||
cheneats | 0 | 302,431,682 | 3% |