Skip to content

Commit

Permalink
Fix voting sliders
Browse files Browse the repository at this point in the history
  • Loading branch information
stoodkev committed Sep 28, 2018
1 parent e7ea55a commit 2890e01
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Expand Up @@ -3,7 +3,7 @@

"name": "SteemPlus",
"description": "Lightweight toolbox for Steemit",
"version": "3.0.1.1",
"version": "3.0.1.2",
"content_security_policy": "script-src 'self' 'unsafe-eval' https://widget.blocktrades.us/ ; object-src 'self'; child-src 'unsafe-eval' 'self' https://widget.blocktrades.us/",
"browser_action": {
"default_icon": "src/img/logo.png",
Expand Down
7 changes: 3 additions & 4 deletions src/js/vote_weight_slider.js
Expand Up @@ -68,7 +68,7 @@ function startVoteWeightSlider() {
}
}

function updateVotingSlider(weightDisplay) {
async function updateVotingSlider(weightDisplay) {
weightDisplay.css('margin-top', '-10px');
var weightDollars = weightDisplay.parent().find('.voting_weight_dollars');
if (weightDollars.length === 0) {
Expand All @@ -80,9 +80,8 @@ function updateVotingSlider(weightDisplay) {
weightDisplay.after(weightDollars);
}

var dollars = window.SteemPlus.Utils.getVotingDollarsPerAccount(parseInt(weightDisplay.eq(0).text().replace(/ /, ''), 10), account, rewardBalance, recentClaims, steemPrice, votePowerReserveRate, false);
var dollars = await window.SteemPlus.Utils.getVotingDollarsPerAccount(parseInt(weightDisplay.eq(0).text().replace(/ /, ''), 10), account, rewardBalance, recentClaims, steemPrice, votePowerReserveRate, false);

console.log(dollars);
if ((typeof dollars === 'undefined' || dollars === undefined) && retryCountVoteWeightSlider < 20) {
retryCountVoteWeightSlider++;
setTimeout(function() {
Expand Down Expand Up @@ -142,4 +141,4 @@ function tryUpdateVotingSlider(weightDisplay) {
if (weightDisplay.length) {
updateVotingSlider(weightDisplay);
}
}
}
10 changes: 5 additions & 5 deletions src/js/vote_weight_slider_busy.js
Expand Up @@ -124,7 +124,7 @@ function setupUnlikeButton(btnBusy) {
$(btnBusy).remove();
}

function createPopupVoteSlider(element) {
async function createPopupVoteSlider(element) {
var currentWeight = 100;
dollars = 0;
var popoverPosition = (isPostPage && isFloatingFooterEnabled ? 'top' : 'bottom');
Expand All @@ -134,15 +134,15 @@ function createPopupVoteSlider(element) {
$(element).attr('data-html', 'true');
$(element).attr('data-trigger', 'click');
$(element).popover('show');
dollars = window.SteemPlus.Utils.getVotingDollarsPerAccount(100, account, rewardBalance, recentClaims, steemPrice, votePowerReserveRate, false);
dollars = await window.SteemPlus.Utils.getVotingDollarsPerAccount(100, account, rewardBalance, recentClaims, steemPrice, votePowerReserveRate, false);
$(element).parent().find('.value-vote-slider-busy').html(dollars.toFixed(3));

$(element).parent().find('#vote-weight-slider-busy').slider({
tooltip: 'hide'
});
$(element).parent().find('#vote-weight-slider-busy').on('change', function(slideEvt) {
$(element).parent().find('#vote-weight-slider-busy').on('change', async function(slideEvt) {
currentWeight = slideEvt.value.newValue;
dollars = window.SteemPlus.Utils.getVotingDollarsPerAccount(currentWeight, account, rewardBalance, recentClaims, steemPrice, votePowerReserveRate, false);
dollars = await window.SteemPlus.Utils.getVotingDollarsPerAccount(currentWeight, account, rewardBalance, recentClaims, steemPrice, votePowerReserveRate, false);
$(element).parent().find('.percentage-vote-slider-busy').html(currentWeight);
$(element).parent().find('.value-vote-slider-busy').html(dollars.toFixed(3));
});
Expand Down Expand Up @@ -191,4 +191,4 @@ function unlikePost(btnBusy) {
$(btnBusy).parent().parent().find('.Payout > span > span > span').html((oldPayout - dollars).toFixed(2));
}
});
}
}
27 changes: 13 additions & 14 deletions vendor/smi/utils.js
Expand Up @@ -128,24 +128,23 @@


var getVotingPowerPerAccount = function(account) {
const mana= getMana(account);
return mana.estimated_pct.toFixed(2);
return new Promise(function(fulfill,reject){
const mana= getMana(account);
fulfill(mana.estimated_pct.toFixed(2));
});
};

var getMana = function(account) {
const STEEM_VOTING_MANA_REGENERATION_SECONDS =432000;
const estimated_max = getEffectiveVestingSharesPerAccount(account)*1000000;
console.log(estimated_max);
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;
console.log({"current_mana": current_mana, "last_update_time": last_update_time,
"estimated_mana": estimated_mana, "estimated_max": estimated_max, "estimated_pct": estimated_pct});
return {"current_mana": current_mana, "last_update_time": last_update_time,
return {"current_mana": current_mana, "last_update_time": last_update_time,
"estimated_mana": estimated_mana, "estimated_max": estimated_max, "estimated_pct": estimated_pct};
}

Expand All @@ -165,10 +164,11 @@
};


var getVotingDollarsPerAccount = function(voteWeight, account, rewardBalance, recentClaims, steemPrice, votePowerReserveRate, full) {
if (rewardBalance && recentClaims && steemPrice && votePowerReserveRate) {
var getVotingDollarsPerAccount = function(voteWeight, account, rewardBalance, recentClaims, steemPrice, votePowerReserveRate, full) {
return new Promise(async function(fulfill,reject){
if (rewardBalance && recentClaims && steemPrice && votePowerReserveRate) {
var effective_vesting_shares = Math.round(getEffectiveVestingSharesPerAccount(account) * 1000000);
var current_power = full ? 10000 : getVotingPowerPerAccount(account)*100;
var current_power = full ? 10000 : await getVotingPowerPerAccount(account)*100;
var weight = voteWeight * 100;
var max_vote_denom = votePowerReserveRate * STEEMIT_VOTE_REGENERATION_SECONDS / (60 * 60 * 24);
var used_power = Math.round((current_power * weight) / STEEMIT_100_PERCENT);
Expand All @@ -177,9 +177,10 @@
var voteValue = rshares *
rewardBalance / recentClaims *
steemPrice;
return voteValue;

}
fulfill(voteValue);
}
else reject();
});
};


Expand Down Expand Up @@ -250,7 +251,6 @@
}

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

return new Promise(function(fulfill,reject){
Expand All @@ -271,7 +271,6 @@
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)};
console.log(res);
fulfill(res);
},
error:function(e){
Expand Down

0 comments on commit 2890e01

Please sign in to comment.