Skip to content

Commit

Permalink
Also update global account state on MarketSaga get_accounts, fixes #437
Browse files Browse the repository at this point in the history
  • Loading branch information
svk31 committed Dec 1, 2016
1 parent 9f0faf7 commit b0e2507
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
2 changes: 1 addition & 1 deletion app/components/pages/Market.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class Market extends React.Component {
}, {})
}

let account = this.props.account
let account = this.props.account ? this.props.account.toJS() : null;
let open_orders = this.props.open_orders;
let orderbook = aggOrders(normalizeOrders(this.props.orderbook));

Expand Down
28 changes: 14 additions & 14 deletions app/components/pages/Witnesses.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import links from 'app/utils/Links'
import Icon from 'app/components/elements/Icon';
import transaction from 'app/redux/Transaction'
import ByteBuffer from 'bytebuffer'
import {Set} from 'immutable'
import {Set, is} from 'immutable'
import { translate } from 'app/Translator';

const Long = ByteBuffer.Long
Expand All @@ -16,7 +16,7 @@ class Witnesses extends React.Component {
// HTML properties

// Redux connect properties
global: object.isRequired,
witnesses: object.isRequired,
accountWitnessVote: func.isRequired,
username: string,
witness_votes: object,
Expand All @@ -36,20 +36,20 @@ class Witnesses extends React.Component {
}
}

shouldComponentUpdate(np, ns) {
return (
!is(np.witness_votes, this.props.witness_votes) ||
np.witnesses !== this.props.witnesses ||
np.username !== this.props.username ||
ns.customUsername !== this.state.customUsername
);
}

render() {
const {props: {global, witness_votes}, state: {customUsername}, accountWitnessVote, onWitnessChange} = this
const sorted_witnesses = global.getIn(['witnesses'])
const {props: {witness_votes}, state: {customUsername}, accountWitnessVote, onWitnessChange} = this
const sorted_witnesses = this.props.witnesses
.sort((a, b) => Long.fromString(String(b.get('votes'))).subtract(Long.fromString(String(a.get('votes'))).toString()));

const header =
<div className="row">
<div className="column small-1">
<label>{translate('vote')}</label>
</div>
<div className="column small-4">
<label>{translate('witness')}</label>
</div>
</div>
const up = <Icon name="chevron-up-circle" />;
let witness_vote_count = 30
let rank = 1
Expand Down Expand Up @@ -164,7 +164,7 @@ module.exports = {
const current_account = current_user && state.global.getIn(['accounts', username])
const witness_votes = current_account && Set(current_account.get('witness_votes'))
return {
global: state.global,
witnesses: state.global.get('witnesses'),
username,
witness_votes,
};
Expand Down
18 changes: 11 additions & 7 deletions app/redux/MarketSaga.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {takeLatest, takeEvery} from 'redux-saga';
import {call, put, select} from 'redux-saga/effects';
import {takeLatest} from 'redux-saga';
import {call, put} from 'redux-saga/effects';
import Apis from 'shared/api_client/ApiInstances';
import MarketReducer from './MarketReducer';
import constants from './constants';
import {fromJS, Map} from 'immutable'
import g from 'app/redux/GlobalReducer'
// import constants from './constants';
import {fromJS} from 'immutable'

export const marketWatches = [watchLocationChange, watchUserLogin, watchMarketUpdate];

Expand Down Expand Up @@ -68,9 +69,12 @@ export function* fetchOpenOrders(set_user_action) {
const state = yield call([db_api, db_api.exec], 'get_open_orders', [username]);
yield put(MarketReducer.actions.receiveOpenOrders(state));

const [account] = yield call(Apis.db_api, 'get_accounts', [username])
yield put(MarketReducer.actions.receiveAccount({ account }))

let [account] = yield call(Apis.db_api, 'get_accounts', [username])
if(account) {
account = fromJS(account)
yield put(MarketReducer.actions.receiveAccount({ account }))
yield put(g.actions.receiveAccount({ account }))
}
} catch (error) {
console.error('~~ Saga fetchOpenOrders error ~~>', error);
yield put({type: 'global/STEEM_API_ERROR', error: error.message});
Expand Down

0 comments on commit b0e2507

Please sign in to comment.