fetch rewards on page load #1754

Merged
daovist merged 3 commits from fetch-rewards into master 2018-07-15 02:10:22 +02:00
3 changed files with 38 additions and 27 deletions

View file

@ -1,15 +1,20 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { selectFetchingRewards, selectUnclaimedRewards } from 'redux/selectors/rewards'; import {
selectFetchingRewards,
selectUnclaimedRewards,
selectClaimedRewards,
} from 'redux/selectors/rewards';
import { selectUser } from 'redux/selectors/user'; import { selectUser } from 'redux/selectors/user';
import { doAuthNavigate, doNavigate } from 'redux/actions/navigation'; import { doAuthNavigate, doNavigate } from 'redux/actions/navigation';
import { doRewardList } from 'redux/actions/rewards'; import { doRewardList } from 'redux/actions/rewards';
import { selectDaemonSettings } from 'redux/selectors/settings'; import { selectDaemonSettings } from 'redux/selectors/settings';
import RewardsPage from './view'; import RewardsPage from './view';
const select = (state, props) => ({ const select = state => ({
daemonSettings: selectDaemonSettings(state), daemonSettings: selectDaemonSettings(state),
fetching: selectFetchingRewards(state), fetching: selectFetchingRewards(state),
rewards: selectUnclaimedRewards(state), rewards: selectUnclaimedRewards(state),
claimed: selectClaimedRewards(state),
user: selectUser(state), user: selectUser(state),
}); });
@ -21,4 +26,7 @@ const perform = dispatch => ({
}, },
}); });
export default connect(select, perform)(RewardsPage); export default connect(
select,
perform
)(RewardsPage);

View file

@ -6,12 +6,15 @@ import RewardTile from 'component/rewardTile';
import Button from 'component/button'; import Button from 'component/button';
import Page from 'component/page'; import Page from 'component/page';
import classnames from 'classnames'; import classnames from 'classnames';
neb-b commented 2018-07-11 19:33:55 +02:00 (Migrated from github.com)
Review

Could you add a new type in types/reward? Then we can improve the above two lines with actual types.

Could you add a new type in `types/reward`? Then we can improve the above two lines with actual types.
import type { Reward } from 'types/reward';
type Props = { type Props = {
doAuth: () => void, doAuth: () => void,
fetchRewards: () => void,
navigate: string => void, navigate: string => void,
fetching: boolean, fetching: boolean,
rewards: Array<{ reward_type: boolean }>, rewards: Array<Reward>,
claimed: Array<Reward>,
user: ?{ user: ?{
is_identity_verified: boolean, is_identity_verified: boolean,
is_reward_approved: boolean, is_reward_approved: boolean,
@ -24,27 +27,9 @@ type Props = {
}; };
class RewardsPage extends React.PureComponent<Props> { class RewardsPage extends React.PureComponent<Props> {
/* componentDidMount() {
Below is broken for users who have claimed all rewards. this.props.fetchRewards();
neb-b commented 2018-07-11 19:33:06 +02:00 (Migrated from github.com)
Review

This comment can be removed

This comment can be removed
}
It can safely be disabled since we fetch all rewards after authentication, but should be re-enabled once fixed.
*/
// componentDidMount() {
// this.fetchRewards(this.props);
// }
//
// componentWillReceiveProps(nextProps) {
// this.fetchRewards(nextProps);
// }
//
// fetchRewards(props) {
// const { fetching, rewards, fetchRewards } = props;
//
// if (!fetching && (!rewards || !rewards.length)) {
// fetchRewards();
// }
// }
renderPageHeader() { renderPageHeader() {
const { doAuth, navigate, user, daemonSettings } = this.props; const { doAuth, navigate, user, daemonSettings } = this.props;
@ -96,7 +81,7 @@ class RewardsPage extends React.PureComponent<Props> {
} }
renderUnclaimedRewards() { renderUnclaimedRewards() {
const { fetching, rewards, user, daemonSettings, navigate } = this.props; const { fetching, rewards, user, daemonSettings, navigate, claimed } = this.props;
if (daemonSettings && !daemonSettings.share_usage_data) { if (daemonSettings && !daemonSettings.share_usage_data) {
return ( return (
@ -128,7 +113,11 @@ class RewardsPage extends React.PureComponent<Props> {
} else if (!rewards || rewards.length <= 0) { } else if (!rewards || rewards.length <= 0) {
return ( return (
<div className="card__content"> <div className="card__content">
{__('There are no rewards available at this time, please check back later.')} {claimed && claimed.length
? __(
"You have claimed all available rewards! We're regularly adding more so be sure to check back later."
)
: __('There are no rewards available at this time, please check back later.')}
</div> </div>
); );
} }

View file

@ -0,0 +1,14 @@
// @flow
export type Reward = {
created_at: string,
id: number,
reward_amount: number,
reward_description: string,
reward_notification: string,
reward_title: string,
reward_type: string,
reward_version: ?string,
transaction_id: ?string,
updated_at: ?string,
};