Added Steem Wallet Information(STEEM Balance and STEEM Power) on Hapramp.

in #utopian-io6 years ago

Repository

https://github.com/hapramp/Hapramp-Android

Added STEEM Power and STEEM Balance section

  • The user can now see his/her SBD balance
  • The user can see his/her STEEM power.

Screenshot:


Implementation

STEEM power is not directly provided by STEEM API.
It needs to be calculated at the client end.

Formulae for calculating STEEM Power is:

steem_power = (total_vesting_fund_steem * user_vesting_share ) / total_vesting_share

In order to get STEEM Power, we needed

  • total_vesting_fund_steem
  • total_vesting_share
  • user_vesting_share

First two of these( total_vesting_fund_steem , total_vesting_share) can be retrieve from SteemJ library method call.

This library is equipped with a helper method named getDynamicGlobalProperties().

Sample call:

 // SteemJ init
 SteemJ steemJ = SteemHelper.getSteemInstance(); // SteemHelper is a class which returns configured SteemJ Instance
 
 try {
     DynamicGlobalProperty dynamicGlobalProperty = steemJ.getDynamicGlobalProperties();
      float totalVestingShares = dynamicGlobalProperty.getTotalVestingShares().getAmount();
      float totalVestingFundSteem = dynamicGlobalProperty.getTotalVestingFundSteem().getAmount();
 } catch (SteemCommunicationException e) {
 
 } catch (SteemResponseException e) {
 
 }

Now the remaining is user_vesting_share.
This variable is part of Account model class of SteemJ library.
We need Account of the user for which balance is fetched.

In SteemJ library provides us a method to access user accounts.

The method has the following signature.

public List<ExtendedAccount> getAccounts(List<AccountName> accountNames)

Its documentation says

  • accountNames A list of accounts you want to request the details for.
  • returns A List of accounts found for the given account names.

The following method returns the user account given the STEEM username

 public ExtendedAccount getUserAccount(String username) throws SteemCommunicationException, SteemResponseException {
        JsonRPCRequest requestObject = new JsonRPCRequest();
        requestObject.setSteemApi(SteemApiType.DATABASE_API);
        requestObject.setApiMethod(RequestMethods.GET_ACCOUNTS);
        // The API expects an array of arrays here.
        String[] innerParameters = new String[1];
        innerParameters[0] = username;
        String[][] parameters = {innerParameters};
        requestObject.setAdditionalParameters(parameters);
        List<ExtendedAccount> accounts = communicationHandler.performRequest(requestObject, ExtendedAccount.class);
        if(accounts.size()>0){
            return accounts.get(0);
        }
        return null;
 }

and finally we can get user_vesting_share as:

ExtendedAccount extendedAccount = steemJ.getUserAccount("bxute"); //hard-coded user name. `steemJ` is an `SteemJ` instance
float userVestingShare = extendedAccount.getVestingShares().getAmount();

In the end, we can apply the formulae for calculating STEEM Power.

A helper method that returns STEEM Power:

 private static float calculateSteemPower(DynamicGlobalProperty dynamicGlobalProperty, ExtendedAccount extendedAccount) {
        float totalVestingShares = dynamicGlobalProperty.getTotalVestingShares().getAmount();
        float totalVestingFundSteem = dynamicGlobalProperty.getTotalVestingFundSteem().getAmount();
        float userVestingShare = extendedAccount.getVestingShares().getAmount();
        return ((totalVestingFundSteem * userVestingShare) / totalVestingShares);
 }

Parameters to this function is from api call made earlier in the above section.

GitHub Account

https://github.com/bxute

Sort:  

Thanks for the contribution!

It seems like a really interesting project with a great team, very cool to have you guys contributing via Utopian.io!

Since you are new I thought I would give you some feedback if you don't mind:

  • It would be great if you could add some usage and install instructions to the README. I also think adding something about how others can contribute to the project would also be a great idea.
  • Linking to a PR or commits is not mandatory, but it is always appreciated if you at least let us know which commits are relevant to the contribution, as that really helps when reviewing!
  • The more (high quality) features per contribution the better! If you want to receive a higher score I would definitely recommend combining a couple of features into one contribution.

I look forward to seeing your future contributions, so keep up the great work!

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thanks for the quick response, @amosbastian.
All very good points. I will fix the README and keep your suggestions in mind for the next contribution.

Best Regards,
Ankit

Hey @bxute
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Contributing on Utopian
Learn how to contribute on our website or by watching this tutorial on Youtube.

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.29
TRX 0.12
JST 0.033
BTC 63855.79
ETH 3113.00
USDT 1.00
SBD 4.04