lbry-desktop/ui/js/component/rewardLink/index.js

36 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-06-08 02:56:52 +02:00
import React from "react";
import { connect } from "react-redux";
2017-05-26 10:53:32 +02:00
import {
makeSelectHasClaimedReward,
makeSelectClaimRewardError,
2017-06-08 02:56:52 +02:00
makeSelectRewardByType,
2017-06-02 17:45:37 +02:00
makeSelectIsRewardClaimPending,
2017-06-08 02:56:52 +02:00
} from "selectors/rewards";
import { doNavigate } from "actions/app";
import { doClaimReward, doClaimRewardClearError } from "actions/rewards";
import RewardLink from "./view";
2017-05-26 10:53:32 +02:00
const makeSelect = () => {
2017-06-08 02:56:52 +02:00
const selectHasClaimedReward = makeSelectHasClaimedReward();
const selectIsPending = makeSelectIsRewardClaimPending();
const selectReward = makeSelectRewardByType();
const selectError = makeSelectClaimRewardError();
2017-05-26 10:53:32 +02:00
const select = (state, props) => ({
isClaimed: selectHasClaimedReward(state, props),
errorMessage: selectError(state, props),
2017-06-08 02:56:52 +02:00
isPending: selectIsPending(state, props),
2017-06-08 23:15:34 +02:00
reward: selectReward(state, props),
2017-06-08 02:56:52 +02:00
});
2017-05-26 10:53:32 +02:00
2017-06-08 02:56:52 +02:00
return select;
};
2017-05-26 10:53:32 +02:00
2017-06-08 02:56:52 +02:00
const perform = dispatch => ({
2017-06-08 23:15:34 +02:00
claimReward: reward => dispatch(doClaimReward(reward, true)),
2017-06-08 02:56:52 +02:00
clearError: reward => dispatch(doClaimRewardClearError(reward)),
navigate: path => dispatch(doNavigate(path)),
});
2017-05-26 10:53:32 +02:00
2017-06-08 02:56:52 +02:00
export default connect(makeSelect, perform)(RewardLink);