Commit 7072741b authored by Jonathan Porta's avatar Jonathan Porta
Browse files

Fix all the bugs

parent fd470686
......@@ -112,7 +112,20 @@ class Powerdown extends React.Component {
);
}
if (notes.length === 0) {
let AMOUNT = vestsToSpf(this.props.state, new_withdraw) / 13;
const total_vesting_shares = this.props.state.getIn([
'props',
'total_vesting_shares',
]);
const total_vesting_fund_steem = this.props.state.getIn([
'props',
'total_vesting_fund_steem',
]);
let AMOUNT =
vestsToSpf(
total_vesting_shares,
total_vesting_fund_steem,
new_withdraw
) / 13;
AMOUNT = AMOUNT.toFixed(AMOUNT >= 10 ? 0 : 1);
notes.push(
<li key="per_week">
......
......@@ -2,7 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import Moment from 'moment';
import NumAbbr from 'number-abbreviate';
import { numberWithCommas } from 'app/utils/StateFunctions';
import { numberWithCommas, vestsToSpf } from 'app/utils/StateFunctions';
import Icon from 'app/components/elements/Icon';
......@@ -20,6 +20,8 @@ Proposal.propTypes = {
onVote: PropTypes.func.isRequired,
isVoting: PropTypes.bool.isRequired,
isUpVoted: PropTypes.bool.isRequired,
total_vesting_shares: PropTypes.number.isRequired,
total_vesting_fund_steem: PropTypes.number.isRequired,
};
export default function Proposal(props) {
......@@ -37,13 +39,19 @@ export default function Proposal(props) {
voteFailed,
voteSucceeded,
isUpVoted,
total_vesting_shares,
total_vesting_fund_steem,
} = props;
const start = new Date(props.start_date);
const end = new Date(props.end_date);
const duration = end - start;
const durationInDays = Moment(end).diff(Moment(start), 'days');
const totalPayout = durationInDays * daily_pay.split(' SBD')[0]; // ¯\_(ツ)_/¯
const total_votes_in_sp = vestsToSpf(
total_vesting_shares,
total_vesting_fund_steem,
parseFloat(total_votes)
).toFixed(3);
console.log(
'PROPOSAL-RENDER(isUpVoted, voteSucceeded, voteFailed, isVoting)',
......@@ -51,7 +59,11 @@ export default function Proposal(props) {
isUpVoted,
voteSucceeded,
voteFailed,
isVoting
isVoting,
total_votes_in_sp,
total_vesting_shares,
total_vesting_fund_steem,
total_votes
);
const classUp =
'Voting__button Voting__button-up' +
......@@ -70,7 +82,7 @@ export default function Proposal(props) {
</span>
</a>
<span>{abbreviateNumber(total_votes)}</span>
<span>{abbreviateNumber(total_votes_in_sp)}</span>
</div>
<div className="proposals__description">
<span>
......@@ -112,7 +124,7 @@ export default function Proposal(props) {
</a>
</span>
<small>
${abbreviateNumber(daily_pay.amount)} per day for{' '}
${abbreviateNumber(daily_pay.split(' SBD')[0])} per day for{' '}
{durationInDays} days
</small>
</div>
......
......@@ -58,10 +58,22 @@ class ProposalContainer extends React.Component {
};
render() {
const { proposal } = this.props;
const {
proposal,
total_vesting_shares,
total_vesting_fund_steem,
} = this.props;
// console.log('ProposalContainer.jsx::render()', this.props);
return <Proposal {...proposal} onVote={this.onVote} {...this.state} />;
return (
<Proposal
{...proposal}
onVote={this.onVote}
{...this.state}
total_vesting_shares={total_vesting_shares}
total_vesting_fund_steem={total_vesting_fund_steem}
/>
);
}
}
......@@ -69,6 +81,8 @@ ProposalContainer.propTypes = {
proposal: PropTypes.shape({ creator: PropTypes.string.isRequired })
.isRequired,
voteOnProposal: PropTypes.func.isRequired,
total_vesting_shares: PropTypes.number.isRequired,
total_vesting_fund_steem: PropTypes.number.isRequired,
};
export default ProposalContainer;
......@@ -7,6 +7,8 @@ ProposalList.propTypes = {
proposals: PropTypes.array.isRequired,
voteOnProposal: PropTypes.func.isRequired,
loading: PropTypes.bool.isRequired,
total_vesting_shares: PropTypes.number.isRequired,
total_vesting_fund_steem: PropTypes.number.isRequired,
// proposals: PropTypes.arrayOf(
// PropTypes.shape({
// color: PropTypes.string.isRequired,
......@@ -22,7 +24,13 @@ ProposalList.propTypes = {
export default function ProposalList(props) {
// console.log('ProposalList.jsx->()', props);
const { proposals, voteOnProposal, loading } = props;
const {
proposals,
voteOnProposal,
loading,
total_vesting_shares,
total_vesting_fund_steem,
} = props;
const proposalCount = proposals.length;
if (!loading && proposalCount == 0) {
......@@ -60,6 +68,8 @@ export default function ProposalList(props) {
key={proposal.id}
voteOnProposal={voteOnProposal}
proposal={proposal}
total_vesting_shares={total_vesting_shares}
total_vesting_fund_steem={total_vesting_fund_steem}
/>
))}
</div>
......
......@@ -7,6 +7,8 @@ ProposalList.propTypes = {
proposals: PropTypes.array.isRequired, // TODO: Specify shape.
voteOnProposal: PropTypes.func.isRequired,
loading: PropTypes.bool.isRequired,
total_vesting_shares: PropTypes.number.isRequired,
total_vesting_fund_steem: PropTypes.number.isRequired,
};
class ProposalListContainer extends React.Component {
......@@ -20,7 +22,7 @@ class ProposalListContainer extends React.Component {
}
render() {
const { proposals, voteOnProposal, loading } = this.props;
// const { proposals, voteOnProposal, loading } = this.props;
// console.log('ProposalListContainer.jsx::render()', arguments);
return <ProposalList {...this.props} />;
......
......@@ -159,6 +159,7 @@ class Proposals extends React.Component {
render() {
console.log('Proposals->render()', this.state);
const { proposals, loading } = this.state;
const { total_vesting_shares, total_vesting_fund_steem } = this.props;
let showBottomLoading = false;
if (loading && proposals && proposals.length > 0) {
showBottomLoading = true;
......@@ -169,6 +170,8 @@ class Proposals extends React.Component {
voteOnProposal={this.voteOnProposal}
proposals={proposals}
loading={loading}
total_vesting_shares={total_vesting_shares}
total_vesting_fund_steem={total_vesting_fund_steem}
/>
<center style={{ paddingTop: '1em', paddingBottom: '1em' }}>
{!loading ? (
......@@ -191,6 +194,8 @@ Proposals.propTypes = {
// updateProposalVotes: PropTypes.func.isRequired,
createProposal: PropTypes.func.isRequired,
voteOnProposal: PropTypes.func.isRequired,
total_vesting_shares: PropTypes.number.isRequired,
total_vesting_fund_steem: PropTypes.number.isRequired,
};
module.exports = {
......@@ -216,13 +221,21 @@ module.exports = {
// `transaction_proposal_vote_active_${currentUser}`,
// List()
// );
const total_vesting_shares = state.global.getIn([
'props',
'total_vesting_shares',
]);
const total_vesting_fund_steem = state.global.getIn([
'props',
'total_vesting_fund_steem',
]);
return {
currentUser,
proposals: newProposals,
// voterProposals,
total_vesting_shares,
total_vesting_fund_steem,
last_id,
// votesInProgress,
};
},
dispatch => {
......
......@@ -8,25 +8,47 @@ import { formatter } from '@steemit/steem-js';
export const numberWithCommas = x => x.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
export function vestsToSpf(state, vesting_shares) {
const { global } = state;
let vests = vesting_shares;
export function vestsToSpf(
total_vesting_shares,
total_vesting_fund_steem,
vesting_shares
) {
console.log('vesting_shares', vesting_shares);
let vests = `${vesting_shares}`;
if (typeof vesting_shares === 'string') {
vests = assetFloat(vesting_shares, VEST_TICKER);
}
const total_vests = assetFloat(
global.getIn(['props', 'total_vesting_shares']),
VEST_TICKER
);
// console.log('vests', vests);
const total_vests = assetFloat(total_vesting_shares, VEST_TICKER);
// console.log('total_vests', total_vests);
const total_vest_steem = assetFloat(
global.getIn(['props', 'total_vesting_fund_steem']),
total_vesting_fund_steem,
LIQUID_TICKER
);
console.log(
'return total_vest_steem * (vests / total_vests);',
total_vest_steem,
vests,
total_vests
);
return total_vest_steem * (vests / total_vests);
}
export function vestsToSp(state, vesting_shares) {
return vestsToSpf(state, vesting_shares).toFixed(3);
console.log('export function vestsToSp(state, vesting_shares) {', state);
const total_vesting_shares = state.global.getIn([
'props',
'total_vesting_shares',
]);
const total_vesting_fund_steem = state.global.getIn([
'props',
'total_vesting_fund_steem',
]);
return vestsToSpf(
total_vesting_shares,
total_vesting_fund_steem,
vesting_shares
).toFixed(3);
}
export function spToVestsf(state, steem_power) {
......@@ -43,7 +65,7 @@ export function spToVestsf(state, steem_power) {
global.getIn(['props', 'total_vesting_fund_steem']),
LIQUID_TICKER
);
return steem_power / total_vest_steem * total_vests;
return (steem_power / total_vest_steem) * total_vests;
}
export function spToVests(state, vesting_shares) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment