2017-04-02 12:05:34 +02:00
|
|
|
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];
|
|
|
|
}
|
2017-04-02 12:05:34 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
};
|
2017-04-02 12:05:34 +02:00
|
|
|
|
|
|
|
// 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,
|
2017-04-02 12:05:34 +02:00
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
|
|
|
// Add more events here to display other places
|
|
|
|
|
|
|
|
resolve(result);
|
2017-04-10 14:32:40 +02:00
|
|
|
}, reject);
|
2017-04-02 12:05:34 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export default rewards;
|