Skip to content

Commit

Permalink
feat(cases): show cases with pending votes on their own tab
Browse files Browse the repository at this point in the history
  • Loading branch information
epiqueras committed Mar 10, 2019
1 parent c601a0e commit a85ffdb
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 62 deletions.
102 changes: 58 additions & 44 deletions src/components/cases-list-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,51 +55,64 @@ const CasesListCard = () => {
)
const disputes = useCacheCall(['KlerosLiquid'], call =>
draws
? draws.reduce(
? Object.values(
draws.reduce((acc, d) => {
acc[d.returnValues._disputeID] = d
return acc
}, {})
).reduce(
(acc, d) => {
if (!acc.IDs[d.returnValues._disputeID]) {
acc.IDs[d.returnValues._disputeID] = true
acc.total++
const dispute = call(
'KlerosLiquid',
'disputes',
d.returnValues._disputeID
)
if (dispute) {
acc[dispute.period === '4' ? 'executed' : 'active']++
if (dispute.period === '1' || dispute.period === '2') {
const dispute2 = call(
'KlerosLiquid',
'getDispute',
d.returnValues._disputeID
)
if (dispute2) {
if (
Number(d.returnValues._appeal) ===
dispute2.votesLengths.length - 1
) {
const subcourt = call(
'KlerosLiquid',
'getSubcourt',
dispute.subcourtID
acc.total++
const dispute = call(
'KlerosLiquid',
'disputes',
d.returnValues._disputeID
)
if (dispute)
if (dispute.period === '1' || dispute.period === '2') {
const dispute2 = call(
'KlerosLiquid',
'getDispute',
d.returnValues._disputeID
)
if (dispute2)
if (
Number(d.returnValues._appeal) ===
dispute2.votesLengths.length - 1
) {
const vote = call(
'KlerosLiquid',
'getVote',
d.returnValues._disputeID,
d.returnValues._appeal,
d.returnValues._voteID
)
if (vote)
acc[vote.voted ? 'active' : 'votePending'].push(
d.returnValues._disputeID
)
else acc.loading = true
const subcourt = call(
'KlerosLiquid',
'getSubcourt',
dispute.subcourtID
)
if (subcourt) {
const deadline = new Date(
(Number(dispute.lastPeriodChange) +
Number(subcourt.timesPerPeriod[dispute.period])) *
1000
)
if (subcourt) {
const deadline = new Date(
(Number(dispute.lastPeriodChange) +
Number(subcourt.timesPerPeriod[dispute.period])) *
1000
)
if (!acc.deadline || deadline < acc.deadline)
acc.deadline = deadline
} else acc.loading = true
}
} else acc.loading = true
}
} else acc.loading = true
}
if (!acc.deadline || deadline < acc.deadline)
acc.deadline = deadline
} else acc.loading = true
} else acc.active++
else acc.loading = true
} else acc[dispute.period === '4' ? 'executed' : 'active']++
else acc.loading = true
return acc
},
{ IDs: {}, active: 0, executed: 0, loading: false, total: 0 }
{ active: 0, executed: 0, loading: false, total: 0, votePending: 0 }
)
: { loading: true }
)
Expand All @@ -109,10 +122,11 @@ const CasesListCard = () => {
prefix={disputes.total}
title="Cases"
>
<StyledListItem extra={String(disputes.active)}>Active</StyledListItem>
<StyledListItem extra={String(disputes.executed)}>
Executed
<StyledListItem extra={String(disputes.votePending)}>
Vote Pending
</StyledListItem>
<StyledListItem extra={String(disputes.active)}>Active</StyledListItem>
<StyledListItem extra={String(disputes.executed)}>Closed</StyledListItem>
{disputes.deadline && (
<StyledDiv className="primary-color theme-color">
<StyledDeadlineDiv>Next voting deadline</StyledDeadlineDiv>
Expand Down
67 changes: 49 additions & 18 deletions src/containers/cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default () => {
const drizzleState = useDrizzleState(drizzleState => ({
account: drizzleState.accounts[0]
}))
const [filter, setFilter] = useState(true)
const [filter, setFilter] = useState(0)
const draws = useCacheEvents(
'KlerosLiquid',
'Draw',
Expand All @@ -31,28 +31,57 @@ export default () => {
)
const disputes = useCacheCall(['KlerosLiquid'], call =>
draws
? draws.reduce(
? Object.values(
draws.reduce((acc, d) => {
acc[d.returnValues._disputeID] = d
return acc
}, {})
).reduce(
(acc, d) => {
if (!acc.IDs[d.returnValues._disputeID]) {
acc.IDs[d.returnValues._disputeID] = true
const dispute = call(
'KlerosLiquid',
'disputes',
d.returnValues._disputeID
)
if (dispute)
const dispute = call(
'KlerosLiquid',
'disputes',
d.returnValues._disputeID
)
if (dispute)
if (dispute.period === '1' || dispute.period === '2') {
const dispute2 = call(
'KlerosLiquid',
'getDispute',
d.returnValues._disputeID
)
if (dispute2)
if (
Number(d.returnValues._appeal) ===
dispute2.votesLengths.length - 1
) {
const vote = call(
'KlerosLiquid',
'getVote',
d.returnValues._disputeID,
d.returnValues._appeal,
d.returnValues._voteID
)
if (vote)
acc[vote.voted ? 'activeIDs' : 'votePendingIDs'].push(
d.returnValues._disputeID
)
else acc.loading = true
} else acc.activeIDs.push(d.returnValues._disputeID)
else acc.loading = true
} else
acc[dispute.period === '4' ? 'executedIDs' : 'activeIDs'].push(
d.returnValues._disputeID
)
else acc.loading = true
}
else acc.loading = true
return acc
},
{ IDs: {}, activeIDs: [], executedIDs: [], loading: false }
{ activeIDs: [], executedIDs: [], loading: false, votePendingIDs: [] }
)
: { activeIDs: [], executedIDs: [], loading: true }
: { activeIDs: [], executedIDs: [], loading: true, votePendingIDs: [] }
)
const filteredDisputes = disputes[filter ? 'activeIDs' : 'executedIDs']
const filteredDisputes =
disputes[['votePendingIDs', 'activeIDs', 'executedIDs'][filter]]
return (
<>
<TopBanner
Expand All @@ -73,15 +102,17 @@ export default () => {
onChange={useCallback(e => setFilter(e.target.value), [])}
value={filter}
>
<Radio.Button value>In Progress</Radio.Button>
<Radio.Button value={false}>Closed</Radio.Button>
<Radio.Button value={0}>Vote Pending</Radio.Button>
<Radio.Button value={1}>In Progress</Radio.Button>
<Radio.Button value={2}>Closed</Radio.Button>
</StyledRadioGroup>
<Divider />
<Spin spinning={disputes.loading}>
<Row gutter={48}>
{filteredDisputes.length === 0 ? (
<StyledCol>
You don't have any {filter ? 'active' : 'executed'} disputes.
You don't have any {['vote pending', 'active', 'closed'][filter]}{' '}
cases.
</StyledCol>
) : (
filteredDisputes.map(ID => (
Expand Down

0 comments on commit a85ffdb

Please sign in to comment.