Skip to content

Commit

Permalink
Add Voting and RC Manas
Browse files Browse the repository at this point in the history
  • Loading branch information
stoodkev committed Sep 26, 2018
1 parent 1a1233c commit bfc5647
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 37 deletions.
2 changes: 0 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,6 @@ chrome.storage.local.get(['steemplus_points', 'dtube_post' ,'utopian_post' ,'tip
if (steemConnect.connect === true && steemConnect.tokenExpire > Date.now()) {
initializeSteemConnect(steemConnect.sessionToken);
api.me().then((me) => {
console.log(me);


const votePowerReserveRateLS = (items.votePowerReserveRateLS == undefined ? 1 : items.votePowerReserveRateLS);
const totalSteemLS = (items.totalSteemLS == undefined ? 1 : items.totalSteemLS);
Expand Down
16 changes: 9 additions & 7 deletions src/js/user_info_popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ function checkDisplayPopoverUserInfo(userName) {


function displayPopoverUserInfo(userName){
window.SteemPlus.Utils.getAccounts([userName], function(err, result){
if(!$('.UserProfile__banner').hasClass('smi-profile-banner-1'))
steem.api.getAccounts([userName], function(err, result){
if(!$('.UserProfile__banner').hasClass('smi-profile-banner-1'))
$('.UserProfile__banner').addClass('smi-profile-banner-1');
Promise.all([window.SteemPlus.Utils.getVotingPowerPerAccount(result[0]), window.SteemPlus.Utils.getVotingDollarsPerAccount(100, result[0], rewardBalanceUIP, recentClaimsUIP, steemPriceUIP, votePowerReserveRateUIP)])
Promise.all([window.SteemPlus.Utils.getVotingPowerPerAccount(result[0]), window.SteemPlus.Utils.getVotingDollarsPerAccount(100, result[0], rewardBalanceUIP, recentClaimsUIP, steemPriceUIP, votePowerReserveRateUIP), window.SteemPlus.Utils.getRC(account.name)])
.then(function(values) {
$("#popover").remove();
var pop=document.createElement('a');
Expand All @@ -79,16 +79,18 @@ function displayPopoverUserInfo(userName){
$('.UserProfile__rep').parent().after(pop);
$('.rep').remove();
$('.UserProfile__rep').parent().after('<span class="rep">(' + reputation + ')</span>');

var title='<h5>User Information</h5>';
var votingPower = values[0]/100;
var votingPower = values[0];
var votingDollars = parseFloat(values[1]);
var fullInString = window.SteemPlus.Utils.getTimeBeforeFull(votingPower*100);

var rc=values[2];
console.log(rc);
$('#popover').attr('data-toggle','popover');
$('#popover').attr('data-content','<h5>Voting Power: <span class="value_of">' + votingPower + '%</span>'
$('#popover').attr('data-content','<h5>Voting Mana: <span class="value_of">' + votingPower + '%</span>'
+'</h5><hr/><h5>Voting Value: <span class="value_of">' + votingDollars.toFixed(2) + '$</span>'
+'</h5><hr/><h5>Full in: <span class="value_of">' + fullInString + '</span>'
+'</h5><hr/><h5>RC Mana: <span class="value_of">' + rc.estimated_pct + '%</span>'
+'</h5><hr/><h5>Full in: <span class="value_of">' + rc.fullin + '</span>'
+'</h5>');
$('#popover').attr('data-placement','right');
$('#popover').attr('title',title);
Expand Down
77 changes: 49 additions & 28 deletions vendor/smi/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,24 @@


var getVotingPowerPerAccount = function(account) {
var voting_power = account.voting_power;
var last_vote_time = new Date((account.last_vote_time) + 'Z');
var elapsed_seconds = (new Date() - last_vote_time) / 1000;
var regenerated_power = Math.round((STEEMIT_100_PERCENT * elapsed_seconds) / STEEMIT_VOTE_REGENERATION_SECONDS);
var current_power = Math.min(voting_power + regenerated_power, STEEMIT_100_PERCENT);
return current_power;
const mana= getMana(account);
return mana.estimated_pct.toFixed(2);
};

var getMana = function(account) {
const STEEM_VOTING_MANA_REGENERATION_SECONDS =432000;
const estimated_max = parseFloat(account.vesting_shares.replace(" VESTS", ""))*1000000;
const current_mana = parseFloat(account.voting_manabar.current_mana);
const last_update_time = account.voting_manabar.last_update_time;
const diff_in_seconds = Math.round(Date.now()/1000-last_update_time);
let estimated_mana = (current_mana + diff_in_seconds * estimated_max / STEEM_VOTING_MANA_REGENERATION_SECONDS);
if (estimated_mana > estimated_max)
estimated_mana = estimated_max;
const estimated_pct = estimated_mana / estimated_max * 100;
return {"current_mana": current_mana, "last_update_time": last_update_time,
"estimated_mana": estimated_mana, "estimated_max": estimated_max, "estimated_pct": estimated_pct};
}

var getEffectiveVestingSharesPerAccount = function(account) {
var effective_vesting_shares = parseFloat(account.vesting_shares.replace(" VESTS", "")) +
parseFloat(account.received_vesting_shares.replace(" VESTS", "")) -
Expand All @@ -153,37 +163,17 @@


var getVotingDollarsPerAccount = function(voteWeight, account, rewardBalance, recentClaims, steemPrice, votePowerReserveRate, full) {

if (!account) {
account = currentUserAccount;
}
if (!account) {
return;
}

if (rewardBalance && recentClaims && steemPrice && votePowerReserveRate) {
var effective_vesting_shares = Math.round(getEffectiveVestingSharesPerAccount(account) * 1000000);
var voting_power = account.voting_power;
var current_power = full ? 10000 : getVotingPowerPerAccount(account)*100;
var weight = voteWeight * 100;
var last_vote_time = new Date((account.last_vote_time) + 'Z');


var elapsed_seconds = (new Date() - last_vote_time) / 1000;
var regenerated_power = Math.round((STEEMIT_100_PERCENT * elapsed_seconds) / STEEMIT_VOTE_REGENERATION_SECONDS);

var current_power = full ? 10000 : Math.min(voting_power + regenerated_power, STEEMIT_100_PERCENT);
var max_vote_denom = votePowerReserveRate * STEEMIT_VOTE_REGENERATION_SECONDS / (60 * 60 * 24);
var used_power = Math.round((current_power * weight) / STEEMIT_100_PERCENT);
used_power = Math.round((used_power + max_vote_denom - 1) / max_vote_denom);

var rshares = Math.round((effective_vesting_shares * used_power) / (STEEMIT_100_PERCENT))


var voteValue = rshares *
rewardBalance / recentClaims *
steemPrice;


return voteValue;

}
Expand Down Expand Up @@ -256,6 +246,35 @@
steem.api.getAccountVotes(name, cb);
}

var getRC=function(name,cb){
let data={"jsonrpc":"2.0","id":1,"method":"rc_api.find_rc_accounts","params":{"accounts":[name]}};

return new Promise(function(fulfill,reject){
$.ajax({
url: "https://api.steemit.com",
type: "POST",
data: JSON.stringify(data),
success: function(response){
const STEEM_RC_MANA_REGENERATION_SECONDS =432000;
const estimated_max = parseFloat(response.result.rc_accounts["0"].max_rc);
const current_mana = parseFloat(response.result.rc_accounts["0"].rc_manabar.current_mana);
const last_update_time = parseFloat(response.result.rc_accounts["0"].rc_manabar.last_update_time);
const diff_in_seconds = Math.round(Date.now()/1000-last_update_time);
let estimated_mana = (current_mana + diff_in_seconds * estimated_max / STEEM_RC_MANA_REGENERATION_SECONDS);
if (estimated_mana > estimated_max)
estimated_mana = estimated_max;

const estimated_pct = estimated_mana / estimated_max * 100;
const res= {"current_mana": current_mana, "last_update_time": last_update_time,
"estimated_mana": estimated_mana, "estimated_max": estimated_max, "estimated_pct": estimated_pct.toFixed(2),"fullin":getTimeBeforeFull(estimated_pct*100)};
fulfill(res);
},
error:function(e){
console.log(e);
}
});
});
}

var getLoadingHtml = function(options) {
var divClass = 'smi-spinner';
Expand Down Expand Up @@ -676,6 +695,7 @@
getSteemPrice: function() {
return steemPrice;
},
getMana:getMana,
getVotingPowerPerAccount: getVotingPowerPerAccount,
getVotingDollarsPerAccount: getVotingDollarsPerAccount,
getVotingDollarsPerShares: getVotingDollarsPerShares,
Expand All @@ -697,6 +717,7 @@
getReputation: getReputation,
getUserTopMenusBusy,
getUserTopMenusBusy,
getRC:getRC,
getTimeBeforeFull: getTimeBeforeFull
};

Expand All @@ -705,4 +726,4 @@
window.SteemPlus.Settings = Settings;
window.SteemPlus.Utils = Utils;

})();
})();

0 comments on commit bfc5647

Please sign in to comment.