Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewards/store: Fix claimed rewards' disappearance #1678

Merged
merged 2 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions apps/rewards/app/store/reward.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ const CONVERT_API_BASE = 'https://min-api.cryptocompare.com/data'
const convertApiUrl = symbols =>
`${CONVERT_API_BASE}/price?fsym=USD&tsyms=${symbols.join(',')}`

export async function onRewardAdded({ rewards = [], refTokens = [], balances = [] }, { rewardId }, settings) {
export async function onRewardAdded(
{ rewards = [], refTokens = [], balances = [] },
{ rewardId, adder },
settings
) {
if (!rewards[rewardId]) {
rewards[rewardId] = await getRewardById(rewardId)
rewards[rewardId] = await getRewardById(rewardId, adder)
const { referenceToken } = rewards[rewardId]
const response = await updateBalancesAndRefTokens({ balances, refTokens }, referenceToken, settings)
return { rewards, refTokens: response.refTokens }
Expand All @@ -21,8 +25,11 @@ export async function onRewardAdded({ rewards = [], refTokens = [], balances = [
return { rewards, refTokens }
}

export async function onRewardClaimed({ rewards = [], claims = {} }, { rewardId }) {
rewards[rewardId] = await getRewardById(rewardId)
export async function onRewardClaimed(
{ rewards = [], claims = {} },
{ rewardId, claimant }
) {
rewards[rewardId] = await getRewardById(rewardId, claimant)

let { claimsByToken = [], totalClaimsMade = 0 } = claims

Expand Down
8 changes: 4 additions & 4 deletions apps/rewards/contracts/Rewards.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ contract Rewards is AragonApp {
Vault public vault;

/// Events
event RewardAdded(uint256 rewardId); /// Emitted when a new reward is created
event RewardClaimed(uint256 rewardId); /// Emitted when a reward is claimed
event RewardAdded(uint256 rewardId, address adder);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think keeping the comments would hurt, but on the other hand the events names seem quite intuitive, so I am "ok" with the change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, a bit redundant and unnecessary. But if they're part of some convention or standard practice, it might make sense to leave them.

event RewardClaimed(uint256 rewardId, address claimant);

/**
* @notice Initialize Rewards app for Vault at `_vault`
Expand Down Expand Up @@ -97,7 +97,7 @@ contract Rewards is AragonApp {

_transferReward(reward, rewardAmount);

emit RewardClaimed(_rewardID);
emit RewardClaimed(_rewardID, tx.origin);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not really sure if this should be msg.sender instead... I invoke @Quazia for this or try to read this to ensure tx.origin is what we need: https://ethereum.stackexchange.com/questions/76929/tx-origin-alternative

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ottodevs thank you for pointing this out. I decided to use tx.origin because in some cases the proxy address was showing up instead of the user's. But I'd need to test this more. Also, I'm gonna read about the security implications of tx.origin, which I was totally unaware of: ethereum/solidity#683

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. After reading about it, tx.origin is insecure and not future-proof. I'm going to test if msg.sender works as expected and let you know.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, neither one of these will behave as we want.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Quazia after testing msg.sender it does work as expected for the claim transaction event. Or am I missing something?

return rewardAmount;
}

Expand Down Expand Up @@ -216,7 +216,7 @@ contract Rewards is AragonApp {
reward.delay = _delay;
reward.blockStart = _startBlock;
reward.creator = msg.sender;
emit RewardAdded(rewardId);
emit RewardAdded(rewardId, tx.origin);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here: I am not really sure if this should be msg.sender instead... I invoke @Quazia for this or try to read this to ensure tx.origin is what we need: https://ethereum.stackexchange.com/questions/76929/tx-origin-alternative

if (_occurrences > 1) {
newReward(
_description,
Expand Down