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

Bugfixes: Reward claiming and transactions (Incl. PM-682) #413

Merged
merged 3 commits into from
Jun 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"options": {
"address": "0x979861df79c7408553aaf20c01cfb3f81ccf9341",
"symbol": "OLY",
"icon": "/assets/img/icons/olympia_logo_favicon.svg"
"icon": "/assets/img/icons/icon_oly.png"
}
},
"providers": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"options": {
"address": "0x979861df79c7408553aaf20c01cfb3f81ccf9341",
"symbol": "OLY",
"icon": "/assets/img/icons/olympia_logo_favicon.svg"
"icon": "/assets/img/icons/icon_oly.png"
}
},
"providers": {
Expand Down
2 changes: 1 addition & 1 deletion config/environments/olympia/staging/interface.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"options": {
"address": "0x979861df79c7408553aaf20c01cfb3f81ccf9341",
"symbol": "OLY",
"icon": "/assets/img/icons/olympia_logo_favicon.svg"
"icon": "/assets/img/icons/icon_oly.png"
}
},
"providers": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"recompose": "^0.27.1",
"redux": "^4.0.0",
"redux-actions": "^2.4.0",
"redux-form": "^7.4.0",
"redux-form": "^7.4.1",
"redux-thunk": "^2.3.0",
"reselect": "^3.0.1",
"seedrandom": "^2.4.3",
Expand Down
Binary file removed src/assets/img/icons/group.png
Binary file not shown.
Binary file added src/assets/img/icons/icon_oly.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/containers/Modals/ModalClaimReward/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
getCurrentNetworkId,
} from 'integrations/store/selectors'
import { getGasPrice } from 'routes/MarketDetails/store/selectors'
import { claimUserRewards } from 'store/actions/rewards'
import { claimUserRewards } from 'routes/Scoreboard/store/actions'
import { getFeatureConfig } from 'utils/features'
import { requestClaimRewardGasCost } from './action'
import { getClaimRewardGasCost, getRewardValue } from './selectors'
Expand Down
12 changes: 9 additions & 3 deletions src/routes/Scoreboard/components/ClaimReward/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ import Span from 'components/layout/Span'
import Countdown from 'components/Countdown'
import Paragraph from 'components/layout/Paragraph'
import { getFeatureConfig } from 'utils/features'
import { connect } from 'react-redux'
import { areRewardsClaimed } from '../../store'
import style from './ClaimReward.mod.scss'

const rewardsConfig = getFeatureConfig('rewards')
const { rewardToken, claimReward } = rewardsConfig
const claimUntilFormat = 'y[Y] M[M] D[d] h[h] m[m]'
const rewardsClaimed = window ? window.localStorage.getItem('rewardsClaimed') === 'true' : false
const cx = cn.bind(style)

const claimStartDate = moment.utc(claimReward.claimStart)
const claimEndDate = moment.utc(claimReward.claimUntil)

const ClaimReward = ({ openClaimRewardModal, rewardValue }) => {
const ClaimReward = ({ openClaimRewardModal, rewardValue, rewardsClaimed }) => {
const isInTimeframe = moment.utc().isBetween(claimStartDate, claimEndDate)
const hasRewards = Decimal(rewardValue || 0).gt(0)

Expand Down Expand Up @@ -68,6 +69,11 @@ const ClaimReward = ({ openClaimRewardModal, rewardValue }) => {
ClaimReward.propTypes = {
openClaimRewardModal: PropTypes.func.isRequired,
rewardValue: PropTypes.number.isRequired,
rewardsClaimed: PropTypes.bool.isRequired,
}

export default ClaimReward
const mapStateToProps = state => ({
rewardsClaimed: areRewardsClaimed(state),
})

export default connect(mapStateToProps, null)(ClaimReward)
1 change: 1 addition & 0 deletions src/routes/Scoreboard/store/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export { default as fetchTournamentUsers } from './fetchTournamentUsers'
export * from './addUsers'
export * from './mainnetRegistry'
export { default as addUsers } from './addUsers'
export * from './rewards'
13 changes: 13 additions & 0 deletions src/routes/Scoreboard/store/actions/rewards.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { claimRewards } from 'api'
import { createAction } from 'redux-actions'

export const rewardsClaimed = createAction('REWARDS_CLAIMED')

export const claimUserRewards = contractAddress => async (dispatch) => {
try {
await claimRewards(contractAddress)
dispatch(rewardsClaimed())
} catch (e) {
console.error(e)
}
}
23 changes: 23 additions & 0 deletions src/routes/Scoreboard/store/reducers/rewards.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Map } from 'immutable'
import { handleActions } from 'redux-actions'
import { LOAD_LOCALSTORAGE } from 'store/middlewares/LocalStorageLoad'
import { rewardsClaimed } from '../actions'

const defaultState = Map({
rewardsClaimed: false,
})

export default handleActions(
{
[rewardsClaimed]: state => state.set('rewardsClaimed', true),
[LOAD_LOCALSTORAGE]: (
state,
{
payload: {
tournament: { rewards },
},
},
) => state.set('rewardsClaimed', rewards.rewardsClaimed),
},
defaultState,
)
2 changes: 2 additions & 0 deletions src/routes/Scoreboard/store/selectors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ export const meSelector = createSelector(
getCurrentAccount,
(users, account) => (users ? users.find(user => normalizeHex(user.account) === normalizeHex(account)) : undefined),
)

export const areRewardsClaimed = state => state.tournament.rewards.get('rewardsClaimed')
10 changes: 0 additions & 10 deletions src/store/actions/rewards.js

This file was deleted.

17 changes: 9 additions & 8 deletions src/store/middlewares/LocalStorageDump.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { pick, set } from 'lodash'
import { set } from 'lodash'
import { isFeatureEnabled } from 'utils/features'

import { LOAD_LOCALSTORAGE } from './LocalStorageLoad'
import { LOAD_SESSIONSTORAGE } from './SessionStorageLoad'
Expand All @@ -8,26 +9,26 @@ const CLEAR_LOCAL_STORAGE = 'CLEAR_LOCAL_STORAGE'
const INIT = 'INIT'
const forbiddenActions = [INIT, CLEAR_LOCAL_STORAGE, LOAD_LOCALSTORAGE, LOAD_SESSIONSTORAGE]

const PERSIST_PATHS = [
'transactions.log',
]
const PERSIST_PATHS = ['transactions']

export default store => next => (action) => {
const state = store.getState()

if (forbiddenActions.indexOf(action.type) === -1) {
let storage = {}
const storage = {}

PERSIST_PATHS.forEach((path) => {
storage = {
...pick(state, path),
}
storage[path] = { ...state[path].toJS() }
})

// FIX-ME: Temporary to remember ToS Acceptance
const tosAccepted = state.integrations.get('termsAndConditionsAccepted').toJS()
set(storage, 'integrations.termsAndConditionsAccepted', tosAccepted)

if (isFeatureEnabled('rewards')) {
set(storage, 'tournament.rewards.rewardsClaimed', state.tournament.rewards.get('rewardsClaimed'))
}

// eslint-disable-next-line no-undef
window.localStorage.setItem(`GNOSIS_${process.env.VERSION}`, JSON.stringify(storage))

Expand Down
2 changes: 2 additions & 0 deletions src/store/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { routerReducer } from 'react-router-redux'
import { reducer as formReducer } from 'redux-form'
import integrations from 'integrations/store/reducers'
import users from 'routes/Scoreboard/store/reducers/users'
import rewards from 'routes/Scoreboard/store/reducers/rewards'
import transactions from 'routes/Transactions/store/reducers/transactions'
import market, { REDUCER_ID } from 'store/reducers/market'
import { isFeatureEnabled } from 'utils/features'
Expand Down Expand Up @@ -30,6 +31,7 @@ const reducers = {
if (tournamentEnabled) {
reducers.tournament = combineReducers({
ranking: users,
rewards,
})
}

Expand Down