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

Commit

Permalink
feat(dispute): vote on disputes with hasRuled = false
Browse files Browse the repository at this point in the history
  • Loading branch information
epiqueras committed Feb 14, 2018
1 parent 17adfbf commit e537ed8
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 11 deletions.
13 changes: 12 additions & 1 deletion src/actions/dispute.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,24 @@ import { createActions } from '../utils/redux'

// Disputes
export const disputes = createActions('DISPUTES')
export const dispute = createActions('DISPUTE')

// Dispute
export const dispute = {
...createActions('DISPUTE', { withUpdate: true }),
VOTE_ON: 'VOTE_ON_DISPUTE'
}

/* Action Creators */

// Disputes
export const fetchDisputes = () => ({ type: disputes.FETCH })

// Dispute
export const fetchDispute = disputeID => ({
type: dispute.FETCH,
payload: { disputeID }
})
export const voteOnDispute = (disputeID, votes, ruling) => ({
type: dispute.VOTE_ON,
payload: { disputeID, votes, ruling }
})
10 changes: 9 additions & 1 deletion src/components/button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@ import PropTypes from 'prop-types'

import './button.css'

const Button = ({ children, onClick, disabled, className, labelClassName }) => (
const Button = ({
children,
onClick,
disabled,
className,
labelClassName,
...rest
}) => (
<div
className={`Button ${disabled ? 'is-disabled' : ''} ${className}`}
onClick={onClick}
{...rest}
>
<h5 className={`Button-label ${labelClassName}`}>{children}</h5>
</div>
Expand Down
5 changes: 5 additions & 0 deletions src/containers/dispute/dispute.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@
}
}
}

&-vote {
display: flex;
justify-content: space-between;
}
}
45 changes: 37 additions & 8 deletions src/containers/dispute/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { renderIf } from '../../utils/redux'
import { dateToString } from '../../utils/date'
import AnchoredList from '../../components/anchored-list'
import Identicon from '../../components/identicon'
import Button from '../../components/button'

import Details from './components/details'
import Evidence from './components/evidence'
Expand All @@ -27,14 +28,24 @@ class Dispute extends PureComponent {
dispute: disputeSelectors.disputeShape.isRequired,

// Action Dispatchers
fetchDispute: PropTypes.func.isRequired
fetchDispute: PropTypes.func.isRequired,
voteOnDispute: PropTypes.func.isRequired
}

componentDidMount() {
const { match: { params: { disputeID } }, fetchDispute } = this.props
fetchDispute(Number(disputeID))
}

handleVoteButtonClick = event => {
const { dispute, voteOnDispute } = this.props
voteOnDispute(
dispute.data.disputeId,
dispute.data.votes,
event.currentTarget.id
)
}

render() {
const { dispute } = this.props

Expand All @@ -55,7 +66,7 @@ class Dispute extends PureComponent {
</small>
<div className="Dispute-header-title">
<Identicon
seed="Placeholder"
seed={dispute.data.arbitrableContractAddress}
size={12}
className="Dispute-header-title-identicon"
/>
Expand Down Expand Up @@ -94,14 +105,31 @@ class Dispute extends PureComponent {
anchor: 'Ruling',
element: (
<Ruling
key={3}
key={2}
date={new Date()}
votesForPartyA={33}
votesForPartyB={78}
netPNK={10}
votesForPartyA={dispute.data.ruling}
votesForPartyB={dispute.data.ruling}
netPNK={0}
/>
)
}
},
...(dispute.data.hasRuled
? []
: [
{
anchor: 'Vote',
element: (
<div key={3} className="Dispute-vote">
<Button id={0} onClick={this.handleVoteButtonClick}>
Vote for Party A
</Button>
<Button id={1} onClick={this.handleVoteButtonClick}>
Vote for Party B
</Button>
</div>
)
}
])
]}
/>
),
Expand All @@ -113,5 +141,6 @@ class Dispute extends PureComponent {
}

export default connect(state => ({ dispute: state.dispute.dispute }), {
fetchDispute: disputeActions.fetchDispute
fetchDispute: disputeActions.fetchDispute,
voteOnDispute: disputeActions.voteOnDispute
})(Dispute)
2 changes: 1 addition & 1 deletion src/reducers/dispute.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const {
const {
shape: disputeShape,
initialState: disputeInitialState
} = createResource(dispute)
} = createResource(dispute, { withUpdate: true })
export { disputesShape, disputeShape }

// Reducer
Expand Down
35 changes: 35 additions & 0 deletions src/sagas/dispute.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,47 @@ function* fetchDispute({ payload: { disputeID } }) {
}
}

/**
* Votes on a dispute by dispute ID.
*/
function* voteOnDispute({ payload: { disputeID, votes, ruling } }) {
try {
yield put(action(disputeActions.dispute.UPDATE))

yield call(
kleros.disputes.submitVotesForDispute,
ARBITRATOR_ADDRESS,
disputeID,
ruling,
votes,
yield select(walletSelectors.getAccount)
)

const dispute = yield call(
kleros.disputes.getDataForDispute,
ARBITRATOR_ADDRESS,
disputeID,
yield select(walletSelectors.getAccount)
)

yield put(
action(disputeActions.dispute.RECEIVE_UPDATED, {
dispute
})
)
} catch (err) {
yield put(errorAction(disputeActions.dispute.FAIL_UPDATE, err))
}
}

/**
* The root of the dispute saga.
*/
export default function* disputeSaga() {
// Disputes
yield takeLatest(disputeActions.disputes.FETCH, fetchDisputes)

// Dispute
yield takeLatest(disputeActions.dispute.FETCH, fetchDispute)
yield takeLatest(disputeActions.dispute.VOTE_ON, voteOnDispute)
}
2 changes: 2 additions & 0 deletions src/utils/redux.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import PropTypes from 'prop-types'
import ReactTooltip from 'react-tooltip'

import { constantToCamelCase } from './string'

Expand Down Expand Up @@ -35,6 +36,7 @@ export default function createReducer(initialState, reducerMap) {
const typePrefixLen = typePrefix.length
const actionTypePrefix = action.type.slice(0, typePrefixLen)
if (typePrefix === actionTypePrefix) {
setTimeout(ReactTooltip.rebuild, 1000) // Attach Tooltips
const resource = constantToCamelCase(
action.type.slice(typePrefixLen + 1)
)
Expand Down

0 comments on commit e537ed8

Please sign in to comment.