Skip to content

Commit

Permalink
Fix #177, calculate effective steem vests
Browse files Browse the repository at this point in the history
  • Loading branch information
bxute committed Sep 13, 2018
1 parent d179c6b commit 2928e69
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 120 deletions.
10 changes: 9 additions & 1 deletion app/src/main/java/com/hapramp/datastore/DataDispatcher.java
Expand Up @@ -268,13 +268,21 @@ void dispatchWalletInfo(String globalPropsJson,
String userProfileJson,
final UserWalletCallback userWalletCallback) {
if (userWalletCallback != null) {

GlobalProperties globalProperties = new Gson().fromJson(globalPropsJson, GlobalProperties.class);
final User user = jsonParser.parseUser(userProfileJson);

double totalVestingShare =
Double.valueOf(user.getVesting_share().split(" ")[0]) +
Double.valueOf(user.getReceived_vesting_shares().split(" ")[0]) -
Double.valueOf(user.getDelegated_vesting_shares().split(" ")[0]);

final double steemPower = SteemPowerCalc.calculateSteemPower(
user.getVesting_share(),
totalVestingShare,
globalProperties.getResult().getTotal_vesting_fund_steem(),
globalProperties.getResult().getTotal_vesting_shares()
);

handler.post(
new Runnable() {
@Override
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/hapramp/datastore/JSONParser.java
Expand Up @@ -310,6 +310,8 @@ public User parseUser(String userJson) {
user.setVestsRewardBalance(userObj.getString("reward_vesting_balance"));
user.setBalance(userObj.getString("balance"));
user.setVesting_share(userObj.getString("vesting_shares"));
user.setReceived_vesting_shares(userObj.getString("received_vesting_shares"));
user.setDelegated_vesting_shares(userObj.getString("delegated_vesting_shares"));
}
catch (JSONException e) {
e.printStackTrace();
Expand Down
212 changes: 101 additions & 111 deletions app/src/main/java/com/hapramp/steem/models/User.java
Expand Up @@ -50,6 +50,12 @@ public class User {
@SerializedName("vesting_shares")
private String vesting_share;
@Expose
@SerializedName("delegated_vesting_shares")
private String delegated_vesting_shares;
@Expose
@SerializedName("received_vesting_shares")
private String received_vesting_shares;
@Expose
@SerializedName("reward_sbd_balance")
private String sbdRewardBalance;

Expand All @@ -64,27 +70,7 @@ public class User {
public User() {
}

public User(String username,
String fullname,
String location,
String profile_image,
String cover_image,
String about,
String website,
int postCount,
long reputation,
String created,
int commentCount,
boolean canVote,
int votingPower,
String savings_sbd_balance,
String sbd_balance,
String savings_balance,
String balance,
String vesting_share,
String sbdRewardBalance,
String steemRewardBalance,
String vestsRewardBalance) {
public User(String username, String fullname, String location, String profile_image, String cover_image, String about, String website, int postCount, long reputation, String created, int commentCount, boolean canVote, int votingPower, String savings_sbd_balance, String sbd_balance, String savings_balance, String balance, String vesting_share, String delegated_vesting_shares, String received_vesting_shares, String sbdRewardBalance, String steemRewardBalance, String vestsRewardBalance) {
this.username = username;
this.fullname = fullname;
this.location = location;
Expand All @@ -103,81 +89,99 @@ public User(String username,
this.savings_balance = savings_balance;
this.balance = balance;
this.vesting_share = vesting_share;
this.delegated_vesting_shares = delegated_vesting_shares;
this.received_vesting_shares = received_vesting_shares;
this.sbdRewardBalance = sbdRewardBalance;
this.steemRewardBalance = steemRewardBalance;
this.vestsRewardBalance = vestsRewardBalance;
}

public String getSbdRewardBalance() {
return sbdRewardBalance;
public String getUsername() {
return username;
}

public void setSbdRewardBalance(String sbdRewardBalance) {
this.sbdRewardBalance = sbdRewardBalance;
public void setUsername(String username) {
this.username = username;
}

public String getSteemRewardBalance() {
return steemRewardBalance;
public String getFullname() {
return fullname;
}

public void setSteemRewardBalance(String steemRewardBalance) {
this.steemRewardBalance = steemRewardBalance;
public void setFullname(String fullname) {
this.fullname = fullname;
}

public String getVestsRewardBalance() {
return vestsRewardBalance;
public String getLocation() {
return location;
}

public void setVestsRewardBalance(String vestsRewardBalance) {
this.vestsRewardBalance = vestsRewardBalance;
public void setLocation(String location) {
this.location = location;
}

public int getCommentCount() {
return commentCount;
public String getProfile_image() {
return profile_image;
}

public void setCommentCount(int commentCount) {
this.commentCount = commentCount;
public void setProfile_image(String profile_image) {
this.profile_image = profile_image;
}

public String getSavings_sbd_balance() {
return savings_sbd_balance;
public String getCover_image() {
return cover_image;
}

public void setSavings_sbd_balance(String savings_sbd_balance) {
this.savings_sbd_balance = savings_sbd_balance;
public void setCover_image(String cover_image) {
this.cover_image = cover_image;
}

public String getSbd_balance() {
return sbd_balance;
public String getAbout() {
return about;
}

public void setSbd_balance(String sbd_balance) {
this.sbd_balance = sbd_balance;
public void setAbout(String about) {
this.about = about;
}

public String getSavings_balance() {
return savings_balance;
public String getWebsite() {
return website;
}

public void setSavings_balance(String savings_balance) {
this.savings_balance = savings_balance;
public void setWebsite(String website) {
this.website = website;
}

public String getBalance() {
return balance;
public int getPostCount() {
return postCount;
}

public void setBalance(String balance) {
this.balance = balance;
public void setPostCount(int postCount) {
this.postCount = postCount;
}

public String getVesting_share() {
return vesting_share;
public long getReputation() {
return reputation;
}

public void setVesting_share(String vesting_share) {
this.vesting_share = vesting_share;
public void setReputation(long reputation) {
this.reputation = reputation;
}

public String getCreated() {
return created;
}

public void setCreated(String created) {
this.created = created;
}

public int getCommentCount() {
return commentCount;
}

public void setCommentCount(int commentCount) {
this.commentCount = commentCount;
}

public boolean isCanVote() {
Expand All @@ -196,97 +200,83 @@ public void setVotingPower(int votingPower) {
this.votingPower = votingPower;
}

public String getCreated() {
return created;
}

public void setCreated(String created) {
this.created = created;
public String getSavings_sbd_balance() {
return savings_sbd_balance;
}

public String getUsername() {
return username;
public void setSavings_sbd_balance(String savings_sbd_balance) {
this.savings_sbd_balance = savings_sbd_balance;
}

public String getWebsite() {
return website;
public String getSbd_balance() {
return sbd_balance;
}

public void setWebsite(String website) {
this.website = website;
public void setSbd_balance(String sbd_balance) {
this.sbd_balance = sbd_balance;
}

public void setUsername(String username) {
this.username = username;
public String getSavings_balance() {
return savings_balance;
}

public String getFullname() {
return fullname;
public void setSavings_balance(String savings_balance) {
this.savings_balance = savings_balance;
}

public void setFullname(String fullname) {
this.fullname = fullname;
public String getBalance() {
return balance;
}

public String getLocation() {
return location;
public void setBalance(String balance) {
this.balance = balance;
}

public void setLocation(String location) {
this.location = location;
public String getVesting_share() {
return vesting_share;
}

public String getProfile_image() {
return profile_image;
public void setVesting_share(String vesting_share) {
this.vesting_share = vesting_share;
}

public void setProfile_image(String profile_image) {
this.profile_image = profile_image;
public String getDelegated_vesting_shares() {
return delegated_vesting_shares;
}

public String getCover_image() {
return cover_image;
public void setDelegated_vesting_shares(String delegated_vesting_shares) {
this.delegated_vesting_shares = delegated_vesting_shares;
}

public void setCover_image(String cover_image) {
this.cover_image = cover_image;
public String getReceived_vesting_shares() {
return received_vesting_shares;
}

public String getAbout() {
return about;
public void setReceived_vesting_shares(String received_vesting_shares) {
this.received_vesting_shares = received_vesting_shares;
}

public void setAbout(String about) {
this.about = about;
public String getSbdRewardBalance() {
return sbdRewardBalance;
}

public int getPostCount() {
return postCount;
public void setSbdRewardBalance(String sbdRewardBalance) {
this.sbdRewardBalance = sbdRewardBalance;
}

public void setPostCount(int postCount) {
this.postCount = postCount;
public String getSteemRewardBalance() {
return steemRewardBalance;
}

public long getReputation() {
return reputation;
public void setSteemRewardBalance(String steemRewardBalance) {
this.steemRewardBalance = steemRewardBalance;
}

public void setReputation(long reputation) {
this.reputation = reputation;
public String getVestsRewardBalance() {
return vestsRewardBalance;
}

@Override
public String toString() {
return "User{" +
"username='" + username + '\'' +
", fullname='" + fullname + '\'' +
", location='" + location + '\'' +
", profile_image='" + profile_image + '\'' +
", cover_image='" + cover_image + '\'' +
", about='" + about + '\'' +
", postCount=" + postCount +
", reputation='" + reputation + '\'' +
'}';
public void setVestsRewardBalance(String vestsRewardBalance) {
this.vestsRewardBalance = vestsRewardBalance;
}
}
Expand Up @@ -206,8 +206,9 @@ public void bind(TransferHistoryModel transferHistoryModel) {
timestamp.setText(MomentsUtils.getFormattedTime(transferHistoryModel.getTimeStamp()));
double sbd = Double.parseDouble(authorReward.getSbd_payout().split(" ")[0]);
double steem = Double.parseDouble(authorReward.getSteem_payout().split(" ")[0]);
double vests = Double.parseDouble(authorReward.getVesting_payout().split(" ")[0]);
double sp = SteemPowerCalc.calculateSteemPower(
authorReward.getVesting_payout(),
vests,
transferHistoryModel.getTotal_vesting_fund_steem(),
transferHistoryModel.getTotal_vesting_shares());

Expand All @@ -232,8 +233,6 @@ public void onClick(View view) {
}
});
}


}

class CommentBenefactorViewHolder extends RecyclerView.ViewHolder {
Expand Down Expand Up @@ -280,8 +279,9 @@ public void bind(TransferHistoryModel transferHistoryModel) {
timestamp.setText(MomentsUtils.getFormattedTime(transferHistoryModel.getTimeStamp()));
double sbd = Double.parseDouble(claimRewardBalance.getReward_sbd().split(" ")[0]);
double steem = Double.parseDouble(claimRewardBalance.getReward_steem().split(" ")[0]);
double vests = Double.parseDouble(claimRewardBalance.getReward_vests().split(" ")[0]);
double sp = SteemPowerCalc.calculateSteemPower(
claimRewardBalance.getReward_vests(),
vests,
transferHistoryModel.getTotal_vesting_fund_steem(),
transferHistoryModel.getTotal_vesting_shares());

Expand Down Expand Up @@ -320,8 +320,9 @@ public CurationViewHolder(View itemView) {
public void bind(TransferHistoryModel transferHistoryModel) {
TransferHistoryModel.CurationReward curationReward = transferHistoryModel.getCurationReward();
timestamp.setText(MomentsUtils.getFormattedTime(transferHistoryModel.getTimeStamp()));
double vests = Double.valueOf(curationReward.getReward().split(" ")[0]);
double sp = SteemPowerCalc.calculateSteemPower(
curationReward.getReward(),
vests,
transferHistoryModel.getTotal_vesting_fund_steem(),
transferHistoryModel.getTotal_vesting_shares());
steemPowerTv.setText(String.format(Locale.US, "%.3f SP", sp));
Expand Down

0 comments on commit 2928e69

Please sign in to comment.