[개발] HF20 관련 steem.apps 사이트 - RC 퍼센트와 회복 시간 추가
오늘 RC를 까고 바로 RC 확인하는 개발 글을 올립니다... RC(리소스 크레디트) 채우기 위한 시간을 확인하려고 디스코드까지 접속하는게 불편하다고 생각했습니다. 그래서 바로 제 사이트에 추가했습니다. 사이트에서 편리하게 확인해보세요. ㅎㅎㅎ ( 궁금하다 보니 어느 순간 바로 코딩을 하고 있더군요. )
https://nhj7.github.io/steem.apps/
참고하셔서 본인 사이트나 서드파티에 추가하실 분들은 https://github.com/nhj7/nhj7.github.io 소스 참고하시면 됩니다. 그리고 핵심이 되는 코드 올립니다. 본인 사이트에 맞게 수정하셔서 쓰시면 됩니다. 제 사이트는 deferred를 사용하고 있어 저런 패턴입니다.
function getResourceCredits(arr_acct_nm) {
var deferred = $.Deferred();
let param={"jsonrpc":"2.0","id":1,"method":"rc_api.find_rc_accounts","params":{"accounts":arr_acct_nm}};
$.ajax({
url: "https://api.steemitstage.com/",
type: "POST",
data: JSON.stringify(param),
success: function(res){
deferred.resolve(res);
console.log(res);
},
error:function(e){
console.log(e);
deferred.reject(err);
}
});
return deferred.promise();
}
function getTimeBeforeFull(votingPower) {
var fullInString;
var remainingPowerToGet = 100.0 - votingPower / 100;
// 1% every 72minutes
var minutesNeeded = remainingPowerToGet * 72;
if (minutesNeeded === 0) {
fullInString = "Already full!";
} else {
var fullInDays = parseInt(minutesNeeded / 1440);
var fullInHours = parseInt((minutesNeeded - fullInDays * 1440) / 60);
var fullInMinutes = parseInt((minutesNeeded - fullInDays * 1440 - fullInHours * 60));
fullInString = (fullInDays === 0 ? '' : fullInDays + (fullInDays > 1 ? ' days ' : 'day ')) +
(fullInHours === 0 ? '' : fullInHours + (fullInHours > 1 ? ' hours ' : 'hour ')) +
(fullInMinutes === 0 ? '' : fullInMinutes + (fullInMinutes > 1 ? ' minutes ' : 'minute'));
}
return fullInString;
}
'rc_api.find_rc_accounts' jsonrpc로 RC 데이터를 얻고 시간계산하는 함수 추가하고 아래 계산 부를 넣으면 끝이 납니다.
......
// start rc calc.
console.log(rcInfo);
const STEEM_RC_MANA_REGENERATION_SECONDS =432000;
const estimated_max = parseFloat(rcInfo.result.rc_accounts["0"].max_rc);
const current_mana = parseFloat(rcInfo.result.rc_accounts["0"].rc_manabar.current_mana);
const last_update_time = parseFloat(rcInfo.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 calcRC = {"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(calcRC);
data.resource_credits = calcRC.estimated_pct;
data.rc_fullin = calcRC.fullin
// end resource_credits
......
참고
https://github.com/steemplus (스팀플러스 github )
Leave [개발] HF20 관련 steem.apps 사이트 - RC 퍼센트와 회복 시간 추가 to:
Read more #kr-dev posts
Best Posts From nhj12311
We have not curated any of nhj12311's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From nhj12311
- 스팀잇 신조어 '보클'은 어뷰징 행위에 해당하는 것이 아닐까요?
- 유머, 귀염, 감동 각종 짤 방출(데이터 주의)
- 신규 가입자를 위한 계정 생성 중개 서비스가 있다면 어떨까?
- 대역폭 문제는 과거에도 있었다.
- [개발] HF20 관련 steem.apps 사이트 - RC 퍼센트와 회복 시간 추가
- 정말 대단한 하드포크다. - 500 스파 계정은 댓글 20개 달고 끝?
- [개발] 업비트 api로 직장인을 위한 코인질 같지 않은 업비트 시세조회 개발
- [개발] Node & Steem #11 - 글 아카이브 기능으로서의 첫 걸음. 포스팅 분류하기.
- [개발] Node & Steem #10 - 형태소 분석을 해보자. - mecab, mecab-ya 활용
- 새벽에 컴터를 하는데 시끄러워 살펴보니 소방차들이 몰려와있다.