lbry-desktop/ui/js/rewards.js

50 lines
1.4 KiB
JavaScript
Raw Normal View History

import lbry from './lbry.js';
import lbryio from './lbryio.js';
2017-04-10 14:32:40 +02:00
function rewardMessage(type, amount) {
return {
new_developer: "Your reward has been confirmed for registering as a new developer.",
new_user: `You received ${amount} LBC new user reward.`,
confirm_email: "Your reward has been confirmed for verifying your email address.",
first_publish: "Your reward has been confirmed for making your first publication.",
}[type];
}
const rewards = {};
rewards.claimReward = function(type) {
return new Promise((resolve, reject) => {
console.log('top of promise body')
lbry.get_new_address().then((address) => {
const params = {
reward_type: type,
wallet_address: address,
};
lbryio.call('reward', 'new', params, 'post').then(({RewardAmount}) => {
2017-04-10 14:32:40 +02:00
const
message = rewardMessage(type, RewardAmount),
result = {
type: type,
amount: RewardAmount,
message: message
};
// Display global notice
document.dispatchEvent(new CustomEvent('globalNotice', {
detail: {
2017-04-10 14:32:40 +02:00
message: message,
linkText: "Show All",
linkTarget: "?rewards",
2017-04-09 17:06:23 +02:00
isError: false,
},
}));
// Add more events here to display other places
resolve(result);
2017-04-10 14:32:40 +02:00
}, reject);
});
});
}
export default rewards;