add logic for reward codes
This commit is contained in:
parent
c09aa2645e
commit
a818633ea2
4 changed files with 971 additions and 527 deletions
1420
dist/bundle.js
vendored
1420
dist/bundle.js
vendored
File diff suppressed because it is too large
Load diff
|
@ -21,6 +21,7 @@
|
|||
"main": "dist/bundle.js",
|
||||
"scripts": {
|
||||
"build": "webpack",
|
||||
"dev": "webpack --watch",
|
||||
"precommit": "lint-staged",
|
||||
"lint": "eslint 'src/**/*.js' --fix",
|
||||
"format": "prettier 'src/**/*.{js,json}' --write"
|
||||
|
|
|
@ -26,17 +26,22 @@ export function doRewardList() {
|
|||
};
|
||||
}
|
||||
|
||||
export function doClaimRewardType(rewardType, options) {
|
||||
export function doClaimRewardType(rewardType, options = {}) {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const unclaimedRewards = selectUnclaimedRewards(state);
|
||||
const reward = unclaimedRewards.find(ur => ur.reward_type === rewardType);
|
||||
const userIsRewardApproved = selectUserIsRewardApproved(state);
|
||||
const unclaimedRewards = selectUnclaimedRewards(state);
|
||||
const reward =
|
||||
rewardType === rewards.TYPE_REWARD_CODE
|
||||
? { reward_type: rewards.TYPE_REWARD_CODE }
|
||||
: unclaimedRewards.find(ur => ur.reward_type === rewardType);
|
||||
|
||||
if (!rewards.TYPE_REWARD_CODE) {
|
||||
if (!reward || reward.transaction_id) {
|
||||
// already claimed or doesn't exist, do nothing
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!userIsRewardApproved && rewardType !== rewards.TYPE_CONFIRM_EMAIL) {
|
||||
const action = doNotify({
|
||||
|
@ -80,7 +85,7 @@ export function doClaimRewardType(rewardType, options) {
|
|||
});
|
||||
};
|
||||
|
||||
rewards.claimReward(rewardType).then(success, failure);
|
||||
rewards.claimReward(rewardType, options.params).then(success, failure);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Lbry, doNotify } from 'lbry-redux';
|
||||
import { Lbry, doNotify, doHideNotification } from 'lbry-redux';
|
||||
import Lbryio from 'lbryio';
|
||||
|
||||
const rewards = {};
|
||||
|
@ -12,18 +12,25 @@ rewards.TYPE_MANY_DOWNLOADS = 'many_downloads';
|
|||
rewards.TYPE_FIRST_PUBLISH = 'first_publish';
|
||||
rewards.TYPE_FEATURED_DOWNLOAD = 'featured_download';
|
||||
rewards.TYPE_REFERRAL = 'referral';
|
||||
rewards.TYPE_REWARD_CODE = 'reward_code';
|
||||
rewards.YOUTUBE_CREATOR = 'youtube_creator';
|
||||
|
||||
rewards.claimReward = type => {
|
||||
rewards.claimReward = (type, rewardParams) => {
|
||||
function requestReward(resolve, reject, params) {
|
||||
if (!Lbryio.enabled) {
|
||||
reject(new Error(__('Rewards are not enabled.')));
|
||||
return;
|
||||
}
|
||||
|
||||
Lbryio.call('reward', 'new', params, 'post').then(reward => {
|
||||
const message =
|
||||
reward.reward_notification || `You have claimed a ${reward.reward_amount} LBC reward.`;
|
||||
|
||||
// We use a modal in the desktop app for this reward code. Dismiss it before showing the snackbar
|
||||
if (type === rewards.TYPE_REWARD_CODE) {
|
||||
window.store.dispatch(doHideNotification());
|
||||
}
|
||||
|
||||
// Display global notice
|
||||
const action = doNotify({
|
||||
message,
|
||||
|
@ -45,6 +52,7 @@ rewards.claimReward = type => {
|
|||
const params = {
|
||||
reward_type: type,
|
||||
wallet_address: address,
|
||||
...rewardParams,
|
||||
};
|
||||
|
||||
switch (type) {
|
||||
|
|
Loading…
Reference in a new issue