Commit d3c3fd6c authored by Jonathan Porta's avatar Jonathan Porta
Browse files

Cleanup

parent c2139c81
......@@ -112,20 +112,7 @@ class Powerdown extends React.Component {
);
}
if (notes.length === 0) {
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;
let AMOUNT = vestsToSpf(this.props.state, new_withdraw) / 13;
AMOUNT = AMOUNT.toFixed(AMOUNT >= 10 ? 0 : 1);
notes.push(
<li key="per_week">
......
......@@ -7,26 +7,8 @@ import { numberWithCommas, vestsToSpf } from 'app/utils/StateFunctions';
import Icon from 'app/components/elements/Icon';
const numAbbr = new NumAbbr();
Proposal.propTypes = {
id: PropTypes.number.isRequired,
creator: PropTypes.string.isRequired,
receiver: PropTypes.string.isRequired,
start_date: PropTypes.string.isRequired,
end_date: PropTypes.string.isRequired,
daily_pay: PropTypes.object.isRequired, // TODO: Specify shape.
subject: PropTypes.string.isRequired,
total_votes: PropTypes.number.isRequired,
permlink: PropTypes.string.isRequired,
onVote: PropTypes.func.isRequired,
isVoting: PropTypes.bool.isRequired,
isUpVoted: PropTypes.bool.isRequired,
// passed through connect from global state object to calc vests to sp
total_vesting_shares: PropTypes.string.isRequired,
total_vesting_fund_steem: PropTypes.string.isRequired
};
export default function Proposal(props) {
// console.log('Proposal.jsx->()', props);
const {
id,
creator,
......@@ -48,24 +30,7 @@ export default function Proposal(props) {
const end = new Date(props.end_date);
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)',
props,
isUpVoted,
voteSucceeded,
voteFailed,
isVoting,
total_votes_in_sp,
total_vesting_shares,
total_vesting_fund_steem,
total_votes
);
const classUp =
'Voting__button Voting__button-up' +
(isUpVoted ? ' Voting__button--upvoted' : '') +
......@@ -82,11 +47,14 @@ export default function Proposal(props) {
/>
</span>
</a>
<span>{abbreviateNumber(
<span>
{abbreviateNumber(
simpleVotesToSp(
total_votes,
props.total_vesting_shares,
props.total_vesting_fund_steem))}
total_vesting_shares,
total_vesting_fund_steem
)
)}
</span>
</div>
<div className="proposals__description">
......@@ -136,6 +104,24 @@ export default function Proposal(props) {
</div>
);
}
//TODO: Move Proposal type to a proptypes file and use where we need it.
Proposal.propTypes = {
id: PropTypes.number.isRequired,
creator: PropTypes.string.isRequired,
receiver: PropTypes.string.isRequired,
start_date: PropTypes.string.isRequired,
end_date: PropTypes.string.isRequired,
daily_pay: PropTypes.string.isRequired,
subject: PropTypes.string.isRequired,
total_votes: PropTypes.string.isRequired,
permlink: PropTypes.string.isRequired,
onVote: PropTypes.func.isRequired,
isVoting: PropTypes.bool.isRequired,
isUpVoted: PropTypes.bool.isRequired,
// passed through connect from global state object to calc vests to sp
total_vesting_shares: PropTypes.string.isRequired,
total_vesting_fund_steem: PropTypes.string.isRequired,
};
/**
* Given a number, return a string with the number formatted as currency
......@@ -223,7 +209,6 @@ function startedOrFinishedInWordsLongVersion(start, end) {
*/
function timeUntil(timestamp) {
return timestamp;
// return timeAgo.format(new Date(timestamp));
}
/**
......@@ -236,7 +221,6 @@ function durationInWords(duration) {
const a = Moment(now);
const b = Moment(now + duration);
return b.from(a);
// return timeAgo.format(duration, 'time');
}
/**
......@@ -288,8 +272,14 @@ function urlifyPermlink(username, permlink) {
* @param {string} total_vesting_fund_steem - total steem vesting fund with liquid symbol on end
* @returns {number} - return the number converted to SP
*/
function simpleVotesToSp(total_votes, total_vesting_shares, total_vesting_fund_steem) {
function simpleVotesToSp(
total_votes,
total_vesting_shares,
total_vesting_fund_steem
) {
const total_vests = parseFloat(total_vesting_shares);
const total_vest_steem = parseFloat(total_vesting_fund_steem);
return ((total_vest_steem * (total_votes / total_vests)) * 0.000001).toFixed(2);
}
\ No newline at end of file
return (total_vest_steem * (total_votes / total_vests) * 0.000001).toFixed(
2
);
}
......@@ -82,15 +82,19 @@ class ProposalContainer extends React.Component {
ProposalContainer.propTypes = {
proposal: PropTypes.shape({ creator: PropTypes.string.isRequired })
.isRequired,
.isRequired, // TODO: Add Shape
voteOnProposal: PropTypes.func.isRequired,
total_vesting_shares: PropTypes.number.isRequired,
total_vesting_fund_steem: PropTypes.number.isRequired,
};
export default connect((state, ownProps) => {
// pulling these out of state object to calculate vests to sp
const total_vesting_shares = state.global.getIn(['props', 'total_vesting_shares']);
const total_vesting_fund_steem = state.global.getIn(['props', 'total_vesting_fund_steem']);
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 { total_vesting_shares, total_vesting_fund_steem, ...ownProps };
})(ProposalContainer);
......@@ -3,34 +3,8 @@ import PropTypes from 'prop-types';
import ProposalContainer from './ProposalContainer';
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,
// fontSize: PropTypes.number.isRequired,
// })
// ).isRequired,
// name: PropTypes.string.isRequired,
// logo: PropTypes.string.isRequired,
// total_cost: PropTypes.number.isRequired,
// total_net_profit: PropTypes.number.isRequired,
// total_gross_profit: PropTypes.number.isRequired,
};
export default function ProposalList(props) {
// console.log('ProposalList.jsx->()', props);
const {
proposals,
voteOnProposal,
loading,
total_vesting_shares,
total_vesting_fund_steem,
} = props;
const { proposals, voteOnProposal, loading } = props;
const proposalCount = proposals.length;
if (!loading && proposalCount == 0) {
......@@ -68,10 +42,14 @@ 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>
);
}
ProposalList.propTypes = {
proposals: PropTypes.array.isRequired, //TODO: Specify Shape
voteOnProposal: PropTypes.func.isRequired,
loading: PropTypes.bool.isRequired,
};
......@@ -3,30 +3,20 @@ import PropTypes from 'prop-types';
import ProposalList from './ProposalList';
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 {
constructor(props) {
// console.log('ProposalListContainer.jsx::constructor()', props);
super(props);
}
async componentWillMount() {
// await console.log('ProposalListContainer.jsx::componentWillMount()');
}
render() {
// const { proposals, voteOnProposal, loading } = this.props;
// console.log('ProposalListContainer.jsx::render()', arguments);
return <ProposalList {...this.props} />;
}
}
ProposalList.propTypes = {
proposals: PropTypes.array.isRequired, // TODO: Specify shape.
voteOnProposal: PropTypes.func.isRequired,
loading: PropTypes.bool.isRequired,
};
export default ProposalListContainer;
......@@ -2,15 +2,7 @@ import React from 'react';
import { connect } from 'react-redux';
import { actions as proposalActions } from 'app/redux/ProposalSaga';
import * as transactionActions from 'app/redux/TransactionReducer'; // TODO: Only import what we need.
import { List } from 'immutable';
// import tt from 'counterpart';
// import { FormattedDate, FormattedTime } from 'react-intl';
// import Icon from 'app/components/elements/Icon';
// import Pagination from '../elements/Pagination';
// import DropdownMenu from '../elements/DropdownMenu';
import PropTypes from 'prop-types';
import ProposalListContainer from 'app/components/modules/ProposalList/ProposalListContainer';
......@@ -28,38 +20,22 @@ class Proposals extends React.Component {
}
async componentWillMount() {
await this.load();
console.log('componentWillMount', this.state);
}
async load(quiet = false) {
console.log('load', this.state);
// if (this.state.proposals && this.state.proposals.length > 0) {
// this.setState({ loading: false });
// } else {
if (quiet) {
this.setState({ loading: true });
}
// }
const proposals =
(await this.getAllProposals(
this.state.last_proposal,
'by_total_votes',
// 'by_creator',
// 'ascending',
'descending',
this.state.limit + this.state.proposals.length,
this.state.status
)) || [];
// const userProposals = (await this.getAllProposals(100, 'all', 0)) || [];
// const upvotedProposals =
// (await this.getUpvotedProposals(100, 'all', 0)) || [];
console.log(
'Proposals->load',
proposals
// userProposals,
// upvotedProposals
);
let last_proposal = false;
if (proposals.length > 0) {
last_proposal = proposals[0];
......@@ -73,9 +49,6 @@ class Proposals extends React.Component {
}
getAllProposals(last_proposal, order_by, order_direction, limit, status) {
// if (status === 'voted') {
// start = this.props.currentUser;
// }export function* listProposals({
return this.props.listProposals({
voter_id: this.props.currentUser,
last_proposal,
......@@ -85,56 +58,6 @@ class Proposals extends React.Component {
status,
});
}
//
// getUserProposals(
// limit,
// status = 'all',
// last_id,
// order_by = 'by_creator',
// order_direction = 'ascending',
// start = ''
// ) {
// if (!this.props.currentUser) return [];
//
// // if (status === 'voted') {
// start = this.props.currentUser;
// // }
// return this.props.listProposalsByVoter({
// start,
// limit,
// order_by,
// order_direction,
// status,
// });
// }
//
// getUpvotedProposals(
// limit = 1000,
// status = 'all',
// order_by = 'by_creator',
// order_direction = 'ascending'
// ) {
// // if (this.props.currentUser) {
// return this.props.listVotedOnProposals({
// voter_id: this.props.currentUser,
// limit,
// order_by: 'by_proposal_voter',
// order_direction,
// status,
// });
// // }
// // return [];
// }
// voteOnProposal = (proposalId, voteForIt, onSuccess, onFailure) => {
// return this.props.voteOnProposal(
// this.props.currentUser,
// [proposalId],
// voteForIt,
// onSuccess,
// onFailure
// );
// };
voteOnProposal = async (proposalId, voteForIt, onSuccess, onFailure) => {
return this.props.voteOnProposal(
......@@ -152,14 +75,11 @@ class Proposals extends React.Component {
onClickLoadMoreProposals = e => {
e.preventDefault();
console.log('onClickLoadMoreProposals::clicked');
this.load();
};
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;
......@@ -170,8 +90,6 @@ 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 ? (
......@@ -189,98 +107,31 @@ class Proposals extends React.Component {
Proposals.propTypes = {
listProposals: PropTypes.func.isRequired,
// listVotedOnProposals: PropTypes.func.isRequired,
removeProposal: PropTypes.func.isRequired,
// 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 = {
path: 'proposals',
component: connect(
state => {
console.log('state.proposal', state.proposal.toJS());
const user = state.user.get('current');
console.log("const user = state.user.get('current');", user);
const currentUser = user && user.get('username');
console.log(
"const currentUser = user && user.get('username');",
currentUser
);
const proposals = state.proposal.get('proposals', List());
const last = proposals.size - 1;
const last_id =
(proposals.size && proposals.get(last).get('id')) || null;
const newProposals =
proposals.size >= 10 ? proposals.delete(last) : proposals;
// const voterProposals = state.proposal.get('voterProposals', List());
// const votesInProgress = state.proposal.get(
// `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,
total_vesting_shares,
total_vesting_fund_steem,
last_id,
};
},
dispatch => {
// const successCallback = () => {
// console.log('successCallback', arguments);
// dispatch(
// proposalActions.listProposals({
// start: '',
// limit: 1000,
// order_by: 'by_creator',
// order_direction: 'ascending',
// status: 'all',
// })
// );
// // dispatch(
// // proposalActions.listVoterProposals({
// // start: proposal_owner,
// // limit: 1000,
// // order_by: 'by_creator',
// // order_direction: 'ascending',
// // status: 'all',
// // })
// // );
// };
// const errorCallback = () => {
// console.log('errorCallback', arguments);
// // dispatch(
// // proposalActions.listProposals({
// // start: '',
// // limit: 11,
// // order_by: 'by_creator',
// // order_direction: 'ascending',
// // status: 'all',
// // })
// // );
// // dispatch(
// // proposalActions.listVoterProposals({
// // start: proposal_owner,
// // limit: 1000,
// // order_by: 'by_creator',
// // order_direction: 'ascending',
// // status: 'all',
// // })
// // );
// };
return {
voteOnProposal: (
voter,
......@@ -289,7 +140,6 @@ module.exports = {
successCallback,
errorCallback
) => {
console.log('voteOnProposal', arguments);
dispatch(
transactionActions.broadcastOperation({
type: 'update_proposal_votes',
......@@ -310,7 +160,6 @@ module.exports = {
successCallback,
errorCallback
) => {
console.log('createProposal', arguments);
dispatch(
transactionActions.broadcastOperation({
type: 'create_proposal',
......@@ -334,7 +183,6 @@ module.exports = {
successCallback,
errorCallback
) => {
console.log('removeProposal', arguments);
dispatch(
transactionActions.broadcastOperation({
type: 'remove_proposal',
......@@ -348,7 +196,6 @@ module.exports = {
);
},
listProposals: payload => {
console.log('listProposals', arguments);
return new Promise((resolve, reject) => {
dispatch(
proposalActions.listProposals({
......@@ -359,16 +206,6 @@ module.exports = {
);
});
},
// listVotedOnProposals: payload =>
// new Promise((resolve, reject) => {
// dispatch(
// proposalActions.listVotedOnProposals({
// ...payload,
// resolve,
// reject,
// })
// );
// }),
};
}
)(Proposals),
......
import { Map, Set, List, fromJS } from 'immutable';
import { Map, fromJS } from 'immutable';
// const ADD_ACTIVE_PROPOSAL_VOTE = 'global/ADD_ACTIVE_PROPOSAL_VOTE';
// const REMOVE_ACTIVE_PROPOSAL_VOTE = 'global/REMOVE_ACTIVE_PROPOSAL_VOTE';
const RECEIVE_LIST_PROPOSALS = 'global/RECEIVE_LIST_PROPOSALS';
const RECEIVE_LIST_VOTER_PROPOSALS = 'global/RECEIVE_LIST_VOTER_PROPOSALS';
const RECEIVE_LIST_PROPOSAL_VOTES = 'global/RECEIVE_LIST_PROPOSAL_VOTES';
......@@ -12,22 +10,6 @@ export default function reducer(state = defaultState, action = {}) {
const payload = action.payload;
switch (action.type) {
// case ADD_ACTIVE_PROPOSAL_VOTE: {
// return state.update(
// `transaction_proposal_vote_active_${payload.voter}`,
// List(),
// l => l.push(payload.proposal_ids[0])
// );
// }
//
// case REMOVE_ACTIVE_PROPOSAL_VOTE: {
// return state.update(
// `transaction_proposal_vote_active_${payload.voter}`,
// List(),
// l => l.delete(l.indexOf(payload.proposal_ids[0]))
// );
// }
case RECEIVE_LIST_PROPOSALS: {
const new_state = fromJS(payload);
return state.merge(new_state);
......@@ -48,26 +30,11 @@ export default function reducer(state = defaultState, action = {}) {
}
}
// export const addActiveProposalVote = payload => ({
// type: ADD_ACTIVE_PROPOSAL_VOTE,
// payload,
// });
//
// export const removeActiveProposalVote = payload => ({
// type: REMOVE_ACTIVE_PROPOSAL_VOTE,
// payload,
// });
export const receiveListProposals = payload => ({
type: RECEIVE_LIST_PROPOSALS,
payload,
});
// export const receiveListVoterProposals = payload => ({
// type: RECEIVE_LIST_VOTER_PROPOSALS,
// payload,
// });
export const receiveListProposalVotes = payload => ({
type: RECEIVE_LIST_PROPOSAL_VOTES,