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

36 lines
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 {
makeSelectClaimRewardError,
2017-06-08 02:56:52 +02:00
makeSelectRewardByType,
2017-06-02 17:45:37 +02:00
makeSelectIsRewardClaimPending,
2017-11-13 22:02:23 +01:00
} from "redux/selectors/rewards";
import { doNavigate } from "redux/actions/navigation";
import {
doClaimRewardType,
doClaimRewardClearError,
} from "redux/actions/rewards";
2017-06-08 02:56:52 +02:00
import RewardLink from "./view";
2017-05-26 10:53:32 +02:00
const makeSelect = () => {
2017-06-08 02:56:52 +02:00
const selectIsPending = makeSelectIsRewardClaimPending();
const selectReward = makeSelectRewardByType();
const selectError = makeSelectClaimRewardError();
2017-05-26 10:53:32 +02:00
const select = (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 => ({
claimReward: reward => dispatch(doClaimRewardType(reward.reward_type, 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);