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

Dispute actions info box: Consider cases where the round is appealed #84

Merged
merged 3 commits into from
Mar 17, 2021
Merged
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
136 changes: 87 additions & 49 deletions src/components/Disputes/DisputeActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ function InformationSection({
`}
/>
</div>
<div>
<div
css={`
max-width: 550px;
`}
>
<div
css={`
${textStyle('body1')}
Expand Down Expand Up @@ -203,11 +207,6 @@ const useInfoAttributes = ({
return useMemo(() => {
if (!jurorDraft) return {}

// If the dispute is in the execute ruling phase it means that the final ruling can already be ensured.
// If the dispute is closed it means that the final ruling was already ensured.
const finalRulingConfirmed =
status === DisputeStatus.Closed || phase === DisputePhase.ExecuteRuling

// Note that we can assume that the evidence submission and drafting phases have already passed since we do an early return above
const votingPeriodEnded =
phase !== DisputePhase.VotingPeriod && phase !== DisputePhase.RevealVote
Expand Down Expand Up @@ -239,46 +238,18 @@ const useInfoAttributes = ({
}
}

// Juror has revealed
// Check if has voted in consensus with the plurality for the last round
const hasVotedInConsensus =
lastRound.vote && jurorDraft.outcome === lastRound.vote.winningOutcome

// We must check if the penalties were already settled so we can tell the jurors
// wether their HNY locked balance has been discounted or they can claim rewards
// Note that if the penalties for the round are settled it means that the dispute has already ended
const settledPenalties = lastRound.settledPenalties

const title = hasVotedInConsensus
? 'You have voted in consensus with the plurality'
: 'You have not voted in consensus with the plurality'
const background = hasVotedInConsensus
? positiveBackground
: negativeBackground

// If penalties settled then the locked HNY has been redistributed
if (settledPenalties) {
return {
title,
paragraph: hasVotedInConsensus ? (
<HNYRewardsMessage />
) : (
<HNYSlashedMessage />
),
background,
icon: hasVotedInConsensus ? IconRewardsGreen : IconVotingFailed,
}
}
// If the dispute is in the execute ruling phase it means that the final ruling can already be ensured.
// If the dispute is closed it means that the final ruling was already ensured.
const finalRulingConfirmed =
status === DisputeStatus.Closed || phase === DisputePhase.ExecuteRuling

// Includes the cases where penalties weren't settled or the last round hasn't ended
return {
title,
paragraph: (
<HNYLockedMessage finalRulingConfirmed={finalRulingConfirmed} />
),
background,
icon: hasVotedInConsensus ? IconVotingSuccess : IconVotingFailed,
}
// Juror has revealed
return getAttributesWhenRevealed(
lastRound,
jurorDraft,
finalRulingConfirmed,
{ positive: positiveBackground, negative: negativeBackground }
)
}

// Juror has voted and reveal period hasn't ended
Expand All @@ -299,8 +270,7 @@ const useInfoAttributes = ({
}, [
hasJurorVoted,
jurorDraft,
lastRound.settledPenalties,
lastRound.vote,
lastRound,
negativeBackground,
phase,
positiveBackground,
Expand All @@ -320,8 +290,8 @@ const HNYLockedMessage = ({ finalRulingConfirmed }) => {
)
}

const HNYSlashMessage = () => {
return <HNYMessage result="will be slashed" />
const HNYSlashMessage = ({ extra = '' }) => {
return <HNYMessage result={`will be slashed ${extra}`} />
}

const HNYSlashedMessage = () => {
Expand Down Expand Up @@ -406,4 +376,72 @@ const VoteInfo = ({ commitmentDate, outcome, revealDate }) => {
)
}

// Assumes juror revealed vote
function getAttributesWhenRevealed(
lastRound,
jurorDraft,
finalRulingConfirmed,
backgroundColor
) {
const { appeal, vote } = lastRound

// Check if has voted in consensus with the plurality for the last round
const hasVotedInConsensus = vote && jurorDraft.outcome === vote.winningOutcome
// We must check if the penalties were already settled so we can tell the jurors
// wether their HNY locked balance has been discounted or they can claim rewards
// Note that if the penalties for the round are settled it means that the dispute has already ended
const settledPenalties = lastRound.settledPenalties

let background, icon, paragraph, title

// Juror voted in consensus during voting phase
if (hasVotedInConsensus) {
background = backgroundColor[appeal ? 'negative' : 'positive']
icon = appeal ? IconVotingFailed : IconRewardsGreen
paragraph = appeal ? (
Copy link
Member

Choose a reason for hiding this comment

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

maybe we can have this as an use memo or maybe get the data from a function instead of doing so many ? :

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah i'll try to do an early return and see how it looks.
What do you mean getting the dats from a function? As you may notice i already separated this part in its own function, but there are so many different cases and conditions that i couldn't find a way to separate it and make it cleaner.

But we can try to do the early return. Also regarding the useMemo, note that the function is already inside an useMemo

Copy link
Member Author

Choose a reason for hiding this comment

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

created an issue #90

settledPenalties ? (
<HNYSlashedMessage />
) : (
<HNYSlashMessage extra="if no one confirms the appeal starting a new round of voting" />
)
) : settledPenalties ? (
<HNYRewardsMessage />
) : (
<HNYLockedMessage finalRulingConfirmed={finalRulingConfirmed} />
)
title = appeal
? 'Although you voted in consensus with the plurality during the voting phase, the dispute was appealed with a different outcome'
: 'You have voted in consensus with the plurality'
} else {
// Juror didn't vote in consenus during voting pahse
// Check if juror voted in favor of the appealed outcome
const inConsensusWithAppealer =
appeal && jurorDraft.outcome === appeal.appealedRuling
background =
backgroundColor[inConsensusWithAppealer ? 'positive' : 'negative']
icon = inConsensusWithAppealer ? IconRewardsGreen : IconVotingFailed
paragraph = inConsensusWithAppealer ? (
settledPenalties ? (
<HNYRewardsMessage />
) : (
<HNYLockedMessage finalRulingConfirmed={finalRulingConfirmed} />
)
) : settledPenalties ? (
<HNYSlashedMessage />
) : (
<HNYSlashMessage />
)
title = inConsensusWithAppealer
? "Altough you didn't vote in consensus with the plurality during the voting phase, the dispute was appealed with the outcome you voted for"
: 'You have not voted in consensus with the plurality'
}

return {
background,
icon,
paragraph,
title,
}
}

export default DisputeActions