Hive coding #16
HiceJS: How to get Voting Power?
by hive_coding
HTML
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@hiveio/hive-js/dist/hive.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
</head>
<body>
<div class="row">
<div class="col-xs-8 offset-sm-1">
<div class="row">
<div class="col-sm-6">
Username : <input type="text" id="username"><br/>
<button id="show">Vote Power</button><br/><br/>
Hive Voting Power: <span id="hivevotingpower"></span><br/>
</div>
</div>
</div>
</div>
<script>
$("#show").click(function() {
hive.api.getAccounts([$("#username").val()], function(err, response){
// console.log(err, response);
let account = response[0];
let hive_voting_power= getVotingPower(account);
$("#hivevotingpower").html(hive_voting_power);
});
});
function getVotingPower(t) {
var e = t.voting_power,
s = new Date(t.last_vote_time + "Z"),
a = (new Date() - s) / 1e3,
r = Math.round((1e4 * a) / 432e3)
return Math.min(Math.min(e + r, 1e4)/100,100);
}
</script>
</body>
</html>