lbry-desktop/ui/js/actions/rewards.js

62 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-06-06 23:19:12 +02:00
import * as types from "constants/action_types";
import lbry from "lbry";
import lbryio from "lbryio";
import rewards from "rewards";
export function doFetchRewards() {
return function(dispatch, getState) {
2017-06-06 23:19:12 +02:00
const state = getState();
dispatch({
type: types.FETCH_REWARDS_STARTED,
2017-06-06 23:19:12 +02:00
});
2017-06-06 23:19:12 +02:00
lbryio.call("reward", "list", {}).then(function(userRewards) {
dispatch({
type: types.FETCH_REWARDS_COMPLETED,
2017-06-06 23:19:12 +02:00
data: { userRewards },
});
});
2017-06-06 23:19:12 +02:00
};
}
2017-05-26 10:53:32 +02:00
export function doClaimReward(reward) {
return function(dispatch, getState) {
2017-05-26 10:53:32 +02:00
dispatch({
type: types.CLAIM_REWARD_STARTED,
data: { reward }
})
const success = (a) => {
console.log(a)
dispatch({
type: types.CLAIM_REWARD_SUCCESS,
data: {
a
}
})
2017-05-26 10:53:32 +02:00
}
const failure = (error) => {
dispatch({
type: types.CLAIM_REWARD_FAILURE,
data: {
reward,
error
}
})
}
rewards.claimReward(reward.reward_type).then(success, failure)
}
}
export function doClaimRewardClearError(reward) {
return function(dispatch, getState) {
dispatch({
type: types.CLAIM_REWARD_CLEAR_ERROR,
data: { reward }
})
2017-05-26 10:53:32 +02:00
}
}