move reward fetching from rewards page to reward summary component on wallet overview page

This commit is contained in:
Travis Eden 2018-07-17 19:26:03 -04:00
parent cbcdfb187a
commit 0d642b2be1
3 changed files with 60 additions and 44 deletions

View file

@ -1,10 +1,18 @@
import React from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { selectUnclaimedRewardValue } from 'redux/selectors/rewards'; import { selectUnclaimedRewardValue, selectFetchingRewards } from 'redux/selectors/rewards';
import { doRewardList } from 'redux/actions/rewards';
import RewardSummary from './view'; import RewardSummary from './view';
const select = state => ({ const select = state => ({
unclaimedRewardAmount: selectUnclaimedRewardValue(state), unclaimedRewardAmount: selectUnclaimedRewardValue(state),
fetching: selectFetchingRewards(state),
}); });
export default connect(select, null)(RewardSummary); const perform = dispatch => ({
fetchRewards: () => dispatch(doRewardList()),
});
export default connect(
select,
perform
)(RewardSummary);

View file

@ -2,20 +2,32 @@
import * as React from 'react'; import * as React from 'react';
import Button from 'component/button'; import Button from 'component/button';
import CreditAmount from 'component/common/credit-amount'; import CreditAmount from 'component/common/credit-amount';
import BusyIndicator from 'component/common/busy-indicator';
type Props = { type Props = {
unclaimedRewardAmount: number, unclaimedRewardAmount: number,
fetching: boolean,
fetchRewards: () => void,
}; };
const RewardSummary = (props: Props) => { class RewardSummary extends React.Component<Props> {
const { unclaimedRewardAmount } = props; componentDidMount() {
this.props.fetchRewards();
}
render() {
const { unclaimedRewardAmount, fetching } = this.props;
const hasRewards = unclaimedRewardAmount > 0; const hasRewards = unclaimedRewardAmount > 0;
return ( return (
<section className="card card--section"> <section className="card card--section">
<div className="card__title">{__('Rewards')}</div> <div className="card__title">
{__('Rewards')}
{fetching && <BusyIndicator />}
</div>
<p className="card__subtitle"> <p className="card__subtitle">
{hasRewards ? ( {!fetching &&
(hasRewards ? (
<React.Fragment> <React.Fragment>
{__('You have')} {__('You have')}
&nbsp; &nbsp;
@ -27,7 +39,7 @@ const RewardSummary = (props: Props) => {
<React.Fragment> <React.Fragment>
{__('There are no rewards available at this time, please check back later')}. {__('There are no rewards available at this time, please check back later')}.
</React.Fragment> </React.Fragment>
)} ))}
</p> </p>
<div className="card__actions"> <div className="card__actions">
<Button <Button
@ -43,6 +55,7 @@ const RewardSummary = (props: Props) => {
</p> </p>
</section> </section>
); );
}; }
}
export default RewardSummary; export default RewardSummary;

View file

@ -10,7 +10,6 @@ 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>, rewards: Array<Reward>,
@ -27,10 +26,6 @@ type Props = {
}; };
class RewardsPage extends React.PureComponent<Props> { class RewardsPage extends React.PureComponent<Props> {
componentDidMount() {
this.props.fetchRewards();
}
renderPageHeader() { renderPageHeader() {
const { doAuth, navigate, user, daemonSettings } = this.props; const { doAuth, navigate, user, daemonSettings } = this.props;