Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Commit

Permalink
feat(notifications): add pending actions notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
epiqueras committed Feb 25, 2018
1 parent a842a0c commit 560dc95
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/actions/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export const notification = {
DISMISS: 'DISMISS_NOTIFICATION'
}

// Pending Actions
export const pendingActions = createActions('PENDING_ACTIONS')

/* Action Creators */

// Notifications
Expand All @@ -23,3 +26,6 @@ export const dismissNotification = (txHash, logIndex) => ({
type: notification.DISMISS,
payload: { txHash, logIndex }
})

// Pending Actions
export const fetchPendingActions = () => ({ type: pendingActions.FETCH })
4 changes: 4 additions & 0 deletions src/containers/home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Home extends PureComponent {
// Action Dispatchers
fetchBalance: PropTypes.func.isRequired,
fetchNotifications: PropTypes.func.isRequired,
fetchPendingActions: PropTypes.func.isRequired,
dismissNotification: PropTypes.func.isRequired,
fetchPNKBalance: PropTypes.func.isRequired,
activatePNK: PropTypes.func.isRequired,
Expand All @@ -52,11 +53,13 @@ class Home extends PureComponent {
const {
fetchBalance,
fetchNotifications,
fetchPendingActions,
fetchPNKBalance,
fetchArbitratorData
} = this.props
fetchBalance()
fetchNotifications()
fetchPendingActions()
fetchPNKBalance()
fetchArbitratorData()
}
Expand Down Expand Up @@ -292,6 +295,7 @@ export default connect(
{
fetchBalance: walletActions.fetchBalance,
fetchNotifications: notificationActions.fetchNotifications,
fetchPendingActions: notificationActions.fetchPendingActions,
dismissNotification: notificationActions.dismissNotification,
fetchPNKBalance: arbitratorActions.fetchPNKBalance,
activatePNK: arbitratorActions.activatePNK,
Expand Down
27 changes: 24 additions & 3 deletions src/reducers/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,34 @@ import createReducer, { createResource } from '../utils/redux'
const {
shape: notificationsShape,
initialState: notificationsInitialState
} = createResource(PropTypes.arrayOf(PropTypes.string))
export { notificationsShape }
} = createResource(
PropTypes.arrayOf(
PropTypes.shape({
txHash: PropTypes.string.isRequired,
notificationType: PropTypes.number.isRequired,
logIndex: PropTypes.number.isRequired,
message: PropTypes.string.isRequired,
data: PropTypes.shape({
disputeId: PropTypes.number.isRequired,
arbitratorAddress: PropTypes.string.isRequired
}).isRequired,
_id: PropTypes.string.isRequired,
created_at: PropTypes.string.isRequired,
read: PropTypes.bool.isRequired
})
)
)
const {
shape: pendingActionsShape,
initialState: pendingActionsInitialState
} = createResource(PropTypes.arrayOf(PropTypes.shape({})))
export { notificationsShape, pendingActionsShape }

// Reducer
export default createReducer(
{
notifications: notificationsInitialState
notifications: notificationsInitialState,
pendingActions: pendingActionsInitialState
},
{
[notificationActions.notification.RECEIVE]: (state, action) => ({
Expand Down
26 changes: 26 additions & 0 deletions src/sagas/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,26 @@ function* dismissNotification({ payload: { txHash, logIndex } }) {
}
}

/**
* Fetches the current account's pending actions.
*/
function* fetchPendingActions() {
try {
const account = yield select(walletSelectors.getAccount)
const pendingActions = yield call(
kleros.notifications.getStatefulNotifications,
ARBITRATOR_ADDRESS,
account
)
console.log(pendingActions)
yield put(
action(notificationActions.pendingActions.RECEIVE, { pendingActions })
)
} catch (err) {
yield put(errorAction(notificationActions.pendingActions.FAIL_FETCH, err))
}
}

/**
* The root of the notification saga.
*/
Expand All @@ -115,4 +135,10 @@ export default function* notificationSaga() {
notificationActions.notification.DISMISS,
dismissNotification
)

// Pending Actions
yield takeLatest(
notificationActions.pendingActions.FETCH,
fetchPendingActions
)
}

0 comments on commit 560dc95

Please sign in to comment.