diff --git a/src/app/components/elements/Voting.jsx b/src/app/components/elements/Voting.jsx index 556f0d322c7d0d2cdf58d717010fe66d479a160a..01e35fa77cb424754f9bebbe0cdabf626d07876b 100644 --- a/src/app/components/elements/Voting.jsx +++ b/src/app/components/elements/Voting.jsx @@ -21,6 +21,7 @@ import { import DropdownMenu from 'app/components/elements/DropdownMenu'; import TimeAgoWrapper from 'app/components/elements/TimeAgoWrapper'; import Dropdown from 'app/components/elements/Dropdown'; +import { List } from 'immutable'; const ABOUT_FLAG = ( <div> @@ -613,7 +614,7 @@ export default connect( // mapStateToProps (state, ownProps) => { const post = - ownProps.post || state.global.getIn(['content', ownProps.post_ref]); + state.global.getIn(['content', ownProps.post_ref]) || ownProps.post; if (!post) { console.error('post_not_found', ownProps); @@ -622,7 +623,8 @@ export default connect( const author = post.get('author'); const permlink = post.get('permlink'); - const active_votes = post.get('active_votes'); + let votes_key = ['content', author + '/' + permlink, 'active_votes']; + const active_votes = state.global.getIn(votes_key, List()); const is_comment = post.get('depth') == 0; const current = state.user.get('current'); @@ -640,7 +642,17 @@ export default connect( let myVote = ownProps.myVote || null; // ownProps: test only if (username && active_votes) { const vote = active_votes.find(el => el.get('voter') === username); - if (vote) myVote = parseInt(vote.get('rshares'), 10); + if (vote) { + let has_rshares = vote.get('rshares') !== undefined; + let has_percent = vote.get('percent') !== undefined; + if (has_rshares && !has_percent) { + myVote = parseInt(vote.get('rshares'), 10); + } else if (!has_rshares && has_percent) { + myVote = vote.get('percent'); + } else if (has_rshares && has_percent) { + myVote = null; + } + } } return { diff --git a/src/app/redux/GlobalReducer.js b/src/app/redux/GlobalReducer.js index f7e6baf2df4d3f3f139c6d9857afee22e01e9d55..8ca45d0e7f93437d196c9166f389ad81fe7edb79 100644 --- a/src/app/redux/GlobalReducer.js +++ b/src/app/redux/GlobalReducer.js @@ -181,6 +181,14 @@ export default function reducer(state = defaultState, action = {}) { c.mergeDeep(content) ); + // merge vote info taking pending votes into account + let votes_key = ['content', key, 'active_votes']; + let old_votes = state.getIn(votes_key, List()); + let new_votes = content.get('active_votes'); + const { merge } = require('immutable'); + let merged_votes = new_votes.merge(new_votes, old_votes); + new_state = new_state.setIn(votes_key, merged_votes); + // set creation-pending key (optimistic UI update) if (content.get('depth') == 0) { const category = content.get('category'); @@ -246,10 +254,9 @@ export default function reducer(state = defaultState, action = {}) { const idx = votes.findIndex(v => v.get('voter') === voter); votes = idx === -1 ? votes.push(vote) : votes.set(idx, vote); - console.log('Applying vote @ idx', idx, payload); // TODO: new state never returned -- masked by RECEIVE_CONTENT - state.setIn(key, votes); + state = state.setIn(key, votes); return state; } diff --git a/src/app/utils/steemApi.js b/src/app/utils/steemApi.js index 9f78667f62d1f405e1af816ea73b6f7b6ed10d0f..0c144a4b39e5aba0f1ab2a31dc7309cced51f74b 100644 --- a/src/app/utils/steemApi.js +++ b/src/app/utils/steemApi.js @@ -21,8 +21,10 @@ export async function callBridge(method, params) { params && (params.observer === null || params.observer === undefined) && params.tag === 'my' - ) + ) { delete params.tag; + delete params.observer; + } return new Promise(function(resolve, reject) { api.call('bridge.' + method, params, function(err, data) {