Skip to content

Commit

Permalink
Implement vote reward system
Browse files Browse the repository at this point in the history
  • Loading branch information
Greateck committed Feb 6, 2019
1 parent e86f0e4 commit 6c43b6b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
37 changes: 35 additions & 2 deletions components/VoteModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
position: 'top center'
});
}
else {
else {
//append this entry into the list of voted posts
if (this.newlyVotedPosts.indexOf(this.postToVote.post_id) === -1){
this.newlyVotedPosts.push(this.postToVote.post_id);
Expand All @@ -96,9 +96,42 @@
group: 'success',
text: 'Your vote has been successfully broadcasted.'
});
console.log(this.newlyVotedPosts.length);
console.log(this.voteWeight);
//if the user votes 3 or more posts at 20%, let's give an additional reward
if (this.newlyVotedPosts.length >= 3 && this.voteWeight >= 20){
this.rewardUserVote();
}
}
});
}
},
async rewardUserVote () {
console.log('rewardUserVote')
//handles rewarding the user for his votes
let url = new URL(process.env.actiAppUrl + 'rewardActifitWebVote/'+this.user.account.name);
//compile all needed data and send it along the request for processing
let params = {
web_vote_token: process.env.webVoteToken,
url: this.postToVote.url,
}
Object.keys(params).forEach(key => url.searchParams.append(key, params[key]))
try{
let res = await fetch(url);
let outcome = await res.json();
if (outcome.rewarded){
// notify the user that he received an additional reward
this.$notify({
group: 'success',
text: 'You\'ve been rewarded '+outcome.amount + ' AFIT tokens for upvoting a min of 3 Actifit reports at 20%. Congrats!',
position: 'top center'
})
}
console.log(outcome);
}catch(err){
console.error(err);
}
}
}
}
</script>
Expand Down
1 change: 1 addition & 0 deletions nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
DELEGATE_ACCOUNT_API_KEY: process.env.DELEGATE_ACCOUNT_API_KEY,
confirmPaymentToken: process.env.CONFIRM_PAYMENT_API_KEY,
webEditToken: process.env.WEB_EDIT_REWARD_KEY,
webVoteToken: process.env.WEB_VOTE_REWARD_KEY,
actiAppUrl: process.env.ACTI_API_URL || 'http://localhost:3120/',
},

Expand Down

0 comments on commit 6c43b6b

Please sign in to comment.