在记录一提到,我想练习并加入:
等功能。
https://xiangstan.github.io/steem/
原来这两条还是很简单的。
在SteemJS的API中有getFollowers和getFollowing两个method方法。
根据https://github.com/steemit/steem-js/blob/master/src/api/methods.js和https://developers.steem.io/tutorials-javascript/get_follower_and_following_list的介绍,这两个方法都拥有四个参数。分别为:STEEM ID, 初始跟随/跟进,类型,和最高的限制。听起来挺空洞的。我的理解就是,用户ID,从头一个follow的人开始为0,哪里跟随/跟进的(都是在blog里面的),和一共显示多少人的名单。以我现在在STEEMIT里面混的面子,查看的介绍中的显示100个人绰绰有余。所以我就用了default的数字。
GetFollow: function(method) {
const that = this;
window.setTimeout(function() {
steem.api[method](that.SteemId, 0, "blog", 100, (err, result) => {
if (err) {
that.$store.commit("updFollowList", [
{ "follower": 'Error: '
+ err +'' }
]);
}
else{ that.$store.commit("updFollowList", result); }
that.$store.commit("setLoading", false);
});
}, 100);
},
程序1
在我的VueJS现在Followers/Following的单文件组件里面,我设立了一个Method方法(程序1)。通过method这个参数,我可以告诉程序调取getFollowers还是getFollowing,由于四个参数完全一样,因而无需再传送任何其他的数据。
这里我想说我本来是不想用VueJS的Vuex状态管理模式的。没有什么必要。数据完全可以作为一个变量存在根下的数据中。但是以下几条原因使我还是决定把followers/following的列表commit(that.$sotre.commit())到Vuex中。
本来设想的直接掉啪啪啪的liker ID看来是有一些难度。getFollowers和getFollowing返回的数据只有跟随,跟进和类型三条信息。
在参读了两篇很老的文章之后:
我找到了如何计算Steem Power,Voting Power,Steem Price,和Recent Claims的公式。
这几个公式的共同点就是,都需要Current Median History Price,Get Reward Fund,和Steem Golbal Properties这三个API的数据。
/* generic steem.api call without query parameter */
SteemApiNoQry: function(api, callback) {
const that = this;
that.steem.api[api](function(err, result) { callback(err, result); });
},
/* generic steem.api call with query parameter */
SteemApiQry: function(api, query, callback) {
const that = this;
that.steem.api[api](query, function(err, result) { callback(err, result); });
},
/* current median history price */
SteemCurMedHisPrice: function() {
const that = this;
that.SteemApiNoQry("getCurrentMedianHistoryPrice", function(err, result) {
if (err) { console.err(err); }
that.$store.commit("updateHisPrice", result);
});
},
/* get reward fund */
SteemGetRewardFund: function() {
const that = this;
that.SteemApiQry("getRewardFund", "post", function(err, result){
if (err) { console.error(err); }
that.$store.commit("updateRewardFund", result);
});
},
SteemGlobalProperties: function(){
const that = this;
that.steem.api.getDynamicGlobalProperties(function(err,result) {
if(err === null) {
that.$store.commit("updateGlobal", result);
}
});
},
这里我要说一下。我的本专业是学电脑工程,无线电波的。编程是爱好。我能想到的如果简化同类函数的方法就是上面SteemApiNoQry和SteemApiQry这种方法。如果要三个参数加callback的话,我只能再写一个SteemApiTwoQry(api, query, blah, callback)了。我觉得应该有更好的方法,但是我不会。
公式是什么样子的,我就不细说了,反正不是我写出来的。分享这几个API返回的数据的方法还是用Vuex。只要受到新的信息,VueJs的Computed就能随时更新计算的数值。
备注: 给Steem Golbal PropertiesAPI设置了window.setInterval(function() { that.SteemGlobalProperties(); }, 120000);,每隔两分钟自动更新一次最新数据。
我顺便加了一个能够取消授权的小功能。比如说如果我想取消我给steempeak.app登录我的账号的授权,实际上就是利用Steemconnect网址获取(URL Get)来revoke来删除权限https://beta.steemconnect.com/revoke/steempeak.app。只要在网页上加一个同样的连接就可以实现这个功能。
已经完成了第一期的两个愿望。在未来的攻克中,我要继续完成剩下的功课:
除此之外,我还想: