From 7f2ad622e324a1eddeaa6e2e4c3783985beb9940 Mon Sep 17 00:00:00 2001 From: Travis Eden Date: Tue, 10 Jul 2018 22:54:50 -0400 Subject: [PATCH] fetch rewards on page load --- src/renderer/page/rewards/index.js | 14 ++++++++--- src/renderer/page/rewards/view.jsx | 39 ++++++++++++------------------ src/renderer/types/reward.js | 14 +++++++++++ 3 files changed, 41 insertions(+), 26 deletions(-) create mode 100644 src/renderer/types/reward.js diff --git a/src/renderer/page/rewards/index.js b/src/renderer/page/rewards/index.js index 8efdfe1d3..3a8bfb3c4 100644 --- a/src/renderer/page/rewards/index.js +++ b/src/renderer/page/rewards/index.js @@ -1,15 +1,20 @@ 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 { doAuthNavigate, doNavigate } from 'redux/actions/navigation'; import { doRewardList } from 'redux/actions/rewards'; import { selectDaemonSettings } from 'redux/selectors/settings'; import RewardsPage from './view'; -const select = (state, props) => ({ +const select = state => ({ daemonSettings: selectDaemonSettings(state), fetching: selectFetchingRewards(state), rewards: selectUnclaimedRewards(state), + claimed: selectClaimedRewards(state), user: selectUser(state), }); @@ -21,4 +26,7 @@ const perform = dispatch => ({ }, }); -export default connect(select, perform)(RewardsPage); +export default connect( + select, + perform +)(RewardsPage); diff --git a/src/renderer/page/rewards/view.jsx b/src/renderer/page/rewards/view.jsx index c1ad7d57f..e6c6e810f 100644 --- a/src/renderer/page/rewards/view.jsx +++ b/src/renderer/page/rewards/view.jsx @@ -6,12 +6,15 @@ import RewardTile from 'component/rewardTile'; import Button from 'component/button'; import Page from 'component/page'; import classnames from 'classnames'; +import type { Reward } from 'types/reward'; type Props = { doAuth: () => void, + fetchRewards: () => void, navigate: string => void, fetching: boolean, - rewards: Array<{ reward_type: boolean }>, + rewards: Array, + claimed: Array, user: ?{ is_identity_verified: boolean, is_reward_approved: boolean, @@ -24,27 +27,13 @@ type Props = { }; class RewardsPage extends React.PureComponent { - /* - Below is broken for users who have claimed all rewards. + componentDidMount() { + const { fetching, rewards, fetchRewards } = this.props; - 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(); - // } - // } + if (!fetching && (!rewards || !rewards.length)) { + fetchRewards(); + } + } renderPageHeader() { const { doAuth, navigate, user, daemonSettings } = this.props; @@ -96,7 +85,7 @@ class RewardsPage extends React.PureComponent { } renderUnclaimedRewards() { - const { fetching, rewards, user, daemonSettings, navigate } = this.props; + const { fetching, rewards, user, daemonSettings, navigate, claimed } = this.props; if (daemonSettings && !daemonSettings.share_usage_data) { return ( @@ -128,7 +117,11 @@ class RewardsPage extends React.PureComponent { } else if (!rewards || rewards.length <= 0) { return (
- {__('There are no rewards available at this time, please check back later.')} + {claimed && Object.keys(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.')}
); } diff --git a/src/renderer/types/reward.js b/src/renderer/types/reward.js new file mode 100644 index 000000000..bc2dccf70 --- /dev/null +++ b/src/renderer/types/reward.js @@ -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, +};