nhj12311 avatar

[개발] HF20 관련 steem.apps 사이트 - RC 퍼센트와 회복 시간 추가

nhj12311

Published: 27 Sept 2018 › Updated: 27 Sept 2018[개발] HF20 관련 steem.apps 사이트 - RC 퍼센트와 회복 시간 추가

[개발] HF20 관련 steem.apps 사이트 - RC 퍼센트와 회복 시간 추가

오늘 RC를 까고 바로 RC 확인하는 개발 글을 올립니다... RC(리소스 크레디트) 채우기 위한 시간을 확인하려고 디스코드까지 접속하는게 불편하다고 생각했습니다. 그래서 바로 제 사이트에 추가했습니다. 사이트에서 편리하게 확인해보세요. ㅎㅎㅎ ( 궁금하다 보니 어느 순간 바로 코딩을 하고 있더군요. )

https://nhj7.github.io/steem.apps/

스크린샷 2018-09-27 오후 8.31.00.png


참고하셔서 본인 사이트나 서드파티에 추가하실 분들은 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:

Written by

개발, 금융에 관심 많음. 취미로 스팀관련 기능도 개발 steem.apps 사이트와 스팀잇 봇 @steem.apps 운영 중

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