Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add current voting power to UserInfo #927

Merged
merged 9 commits into from Oct 29, 2017
Merged

Add current voting power to UserInfo #927

merged 9 commits into from Oct 29, 2017

Conversation

mktcode
Copy link
Contributor

@mktcode mktcode commented Oct 28, 2017

In the left sidebar, when viewing a user's profile, the current voting power is now shown.

screenshot-2017-10-29 mkt - busy

In a future PR this should be implemented:

function calculateVotingPower(votingPower, lastVoteTime, precision) {
    let secondsPassedSinceLastVote = (new Date - new Date(lastVoteTime + "Z")) / 1000;
    votingPower += (10000 * secondsPassedSinceLastVote / 432000);

    return Math.min(votingPower / 100, 100).toFixed(precision);
}

I took this code from another project. It takes into account the replenishment of the voting power since the last vote.

@bonustrack bonustrack temporarily deployed to busy-dev-pr-927 October 29, 2017 08:05 Inactive
@Sekhmet Sekhmet self-requested a review October 29, 2017 08:05
@Sekhmet Sekhmet self-assigned this Oct 29, 2017
@@ -57,6 +59,13 @@ const UserInfo = ({ intl, authenticated, authenticatedUser, user, ...props }) =>
}}
/>
</div>
<div>
<i className="iconfont icon-flashlight text-icon" />
{intl.formatMessage({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use FormattedMessage from react-intl instead of this?

{intl.formatMessage({
id: 'voting_power',
defaultMessage: 'Voting Power',
})}: {currentVotingPower} %
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use FormattedNumber from react-intl instead of this as well?
Like here:

<FormattedNumber
style="percent" // eslint-disable-line react/style-prop-object
value={vote.percent / 10000}
/>

@mktcode
Copy link
Contributor Author

mktcode commented Oct 29, 2017

I don't know if I use it correctly and I also don't know why I have to divide by 10000 but... it works.

@Sekhmet Sekhmet changed the title added current voting power to UserInfo Add current voting power to UserInfo Oct 29, 2017
@bonustrack bonustrack temporarily deployed to busy-dev-pr-927 October 29, 2017 13:09 Inactive
<i className="iconfont icon-flashlight text-icon" />
<FormattedMessage id="voting_power" defaultMessage="Voting Power" />: <FormattedNumber
style="percent" // eslint-disable-line react/style-prop-object
value={user.voting_power / 10000}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So to get the percent of something you divide it by the total... so is 10,000 the total voting power that a user can have? @Sekhmet @bonustrack might know the answer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jm90m
Steem uses 0-10000 range (10000 being 100%). react-intl uses 0-1 range, thus we need to divide it by 10000.

Copy link
Contributor Author

@mktcode mktcode Oct 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok.... so style="percent" transforms 0-1 to 0-100? Can't find this transformation in the code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just tells react-intl to render this as per cent.
https://github.com/yahoo/react-intl/wiki/Components#formattednumber

@bonustrack bonustrack temporarily deployed to busy-dev-pr-927 October 29, 2017 15:25 Inactive
Copy link
Contributor

@bonustrack bonustrack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea and well done thank you!

@bonustrack bonustrack merged commit 740f022 into busyorg:new-design Oct 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants