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/MyRewards: add etherscan link #1653

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
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
Prev Previous commit
Next Next commit
Rewards/MyRewards: add etherscan link: get tx hash from past events i…
…n store
  • Loading branch information
e18r committed Dec 10, 2019
commit babfc387ad400e92b0be94ab1a84d44900ba7e29
10 changes: 2 additions & 8 deletions apps/rewards/app/components/App/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class App extends React.Component {
this.state = {
selected: 0,
tabs: [ 'Overview', 'My Rewards' ],
claimHashes: {},
}
this.updateRewards()
}
Expand Down Expand Up @@ -197,12 +196,7 @@ class App extends React.Component {
}

claimReward = reward => {
this.props.api.claimReward(reward.rewardId + reward.claims)
.subscribe(claimHash => {
const { claimHashes } = this.state
claimHashes[reward.rewardId] = claimHash
this.setState({ claimHashes })
})
this.props.api.claimReward(reward.rewardId + reward.claims).toPromise()
}

openDetailsView = reward => {
Expand Down Expand Up @@ -279,7 +273,7 @@ class App extends React.Component {
isMyReward: true
})}
claimReward={this.claimReward}
claimHashes={this.state.claimHashes}
claimHashes={this.props.claims.claimHashes}
/>
) : (
<Overview
Expand Down
13 changes: 11 additions & 2 deletions apps/rewards/app/store/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { addressesEqual } from '../utils/web3-utils'
import { INITIALIZATION_TRIGGER } from './'

export const handleEvent = async (state, event, settings) => {
const { event: eventName, returnValues, address: eventAddress, } = event
const {
event: eventName,
returnValues,
address: eventAddress,
transactionHash,
} = event
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we access the network here, rather than in the frontend? We don't want the link to change, depending on which network the user is currently connected to. We want to link them to the URL where they can view the actual transaction, whichever network that happened to be on!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you're on one network you won't see any rewards made on another network in the first place, so I think it's safe to access the network from the frontend.

const { vault } = settings

let nextState = { ...state, }
Expand All @@ -25,7 +30,11 @@ export const handleEvent = async (state, event, settings) => {
nextState.isSyncing = false
break
case 'RewardClaimed':
nextState = await onRewardClaimed(nextState, returnValues)
nextState = await onRewardClaimed(
nextState,
returnValues,
transactionHash
)
break
case 'RewardAdded':
nextState = await onRewardAdded(nextState, returnValues, settings)
Expand Down
9 changes: 6 additions & 3 deletions apps/rewards/app/store/reward.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ export async function onRewardAdded({ rewards = [], refTokens = [], balances = [

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

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

claimHashes[rewardId] = transactionHash

const tokenIndex = claimsByToken.findIndex(token => addressesEqual(token.address, rewards[rewardId].rewardToken))

Expand All @@ -43,7 +46,7 @@ export async function onRewardClaimed(

totalClaimsMade = await getTotalClaims()

return { rewards, claims: { claimsByToken, totalClaimsMade } }
return { rewards, claims: { claimsByToken, totalClaimsMade, claimHashes } }

}

Expand Down