Skip to content

(Don't merge) support v2 arbitrator #258

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<a href="https://standardjs.com"><img src="https://img.shields.io/badge/code_style-standard-brightgreen.svg" alt="JavaScript Style Guide"></a>
<a href="https://conventionalcommits.org"><img src="https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg" alt="Conventional Commits"></a>
<a href="http://commitizen.github.io/cz-cli/"><img src="https://img.shields.io/badge/commitizen-friendly-brightgreen.svg" alt="Commitizen Friendly"></a>
<a href="https://app.netlify.com/sites/gtcr-dev/deploys"><img src="https://api.netlify.com/api/v1/badges/ff0eb1e7-e70c-4319-9e5c-f8532b053900/deploy-status"></a>
<a href="https://app.netlify.com/sites/kleros-v2-curate/deploys"><img src="https://api.netlify.com/api/v1/badges/172b66ab-d9f3-4c1f-9b29-f24653369655/deploy-status"></a>
</p>

## Get Started
Expand Down Expand Up @@ -42,4 +42,4 @@ When setting up the repo for publishing on netlify:
REACT_APP_RPC_URLS
REACT_APP_FORMATIC_API_KEYS
REACT_APP_NOTIFICATIONS_API_URL
```
```
10 changes: 2 additions & 8 deletions src/hooks/appeal-time.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import { useMemo } from 'react'
import { DISPUTE_STATUS } from '../utils/item-status'
import { bigNumberify } from 'ethers/utils'

const useAppealTime = item =>
useMemo(() => {
if (!item || item.disputeStatus !== DISPUTE_STATUS.APPEALABLE) return {}
const { appealStart, appealEnd } = item
const appealDuration = appealEnd.sub(appealStart)
const appealEndLoser = appealStart.add(appealDuration.div(bigNumberify(2)))
const { appealEnd } = item

const appealRemainingTime =
appealEnd.toNumber() * 1000 - Math.floor(Date.now())
const appealRemainingTimeLoser =
appealEndLoser.toNumber() * 1000 - Math.floor(Date.now())

return {
appealRemainingTime,
appealRemainingTimeLoser
appealRemainingTime
}
}, [item])

Expand Down
134 changes: 28 additions & 106 deletions src/pages/item-details/crowdfunding-card.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import React, { useContext } from 'react'
import { Card, Typography, Progress } from 'antd'
import { Card, Typography } from 'antd'
import styled from 'styled-components/macro'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import {
DISPUTE_STATUS,
PARTY,
itemToStatusCode,
STATUS_CODE
} from 'utils/item-status'
import { TCRViewContext } from 'contexts/tcr-view-context'
import useRequiredFees from 'hooks/required-fees'
import { formatEther } from 'ethers/utils'
import itemPropType from 'prop-types/item'
import BNPropType from 'prop-types/bn'
import useNativeCurrency from 'hooks/native-currency'
import { WalletContext } from 'contexts/wallet-context'
import getNetworkEnv from 'utils/network-env'

const StyledCard = styled(Card)`
background: linear-gradient(111.6deg, #4d00b4 46.25%, #6500b4 96.25%);
Expand Down Expand Up @@ -57,34 +55,14 @@ const StyledIcon = styled(FontAwesomeIcon)`
margin: 12px;
`

const CrowdfundingCard = ({ item, timestamp }) => {
const {
challengePeriodDuration,
sharedStakeMultiplier,
winnerStakeMultiplier,
loserStakeMultiplier,
MULTIPLIER_DIVISOR
} = useContext(TCRViewContext)
const nativeCurrency = useNativeCurrency()

const requesterFees = useRequiredFees({
side: PARTY.REQUESTER,
sharedStakeMultiplier,
winnerStakeMultiplier,
loserStakeMultiplier,
currentRuling: item && item.currentRuling,
item,
MULTIPLIER_DIVISOR
})
const challengerFees = useRequiredFees({
side: PARTY.CHALLENGER,
sharedStakeMultiplier,
winnerStakeMultiplier,
loserStakeMultiplier,
currentRuling: item && item.currentRuling,
item,
MULTIPLIER_DIVISOR
})
const CrowdfundingCard = ({ item, timestamp, request }) => {
const { networkId } = useContext(WalletContext)
const { arbitrator: klerosAddress, uiURL } =
getNetworkEnv('REACT_APP_KLEROS_ADDRESSES', networkId) || {}

const { disputeID, arbitrator } = request || {}

const { challengePeriodDuration } = useContext(TCRViewContext)

if (
!item ||
Expand All @@ -93,93 +71,37 @@ const CrowdfundingCard = ({ item, timestamp }) => {
)
return null

const { hasPaid, amountPaid, currentRuling } = item

if (
!requesterFees ||
!challengerFees ||
!challengerFees.requiredForSide ||
!challengerFees.potentialReward ||
!requesterFees.requiredForSide ||
!requesterFees.potentialReward
)
return null

const statusCode = itemToStatusCode(item, timestamp, challengePeriodDuration)

if (statusCode === STATUS_CODE.WAITING_ENFORCEMENT) return null

const requesterPercentage =
amountPaid[PARTY.REQUESTER]
.mul(MULTIPLIER_DIVISOR)
.div(requesterFees.requiredForSide)
.toNumber() / 100
const challengerPercentage =
amountPaid[PARTY.CHALLENGER]
.mul(MULTIPLIER_DIVISOR)
.div(challengerFees.requiredForSide)
.toNumber() / 100

return (
<StyledCard>
<StyledContent>
<StyledSection>
<StyledTitle strong level={4}>
Appeal Crowdfunding
Appeal Phase
</StyledTitle>
<StyledIcon icon="coins" size="2x" />
<StyledParagraph>
Contribute appeal fees and earn rewards if the side you back wins
the round
</StyledParagraph>
</StyledSection>
<StyledSection>
<StyledTitle strong level={4}>
Submitter
</StyledTitle>
<Progress
percent={hasPaid[PARTY.REQUESTER] ? 100 : requesterPercentage}
status={hasPaid[PARTY.REQUESTER] ? 'success' : 'active'}
showInfo={false}
/>
<br />
<StyledParagraph>
{hasPaid[PARTY.REQUESTER]
? `Submitter funded. The challenger must now fully fund his side of the appeal before the deadline in order not to lose the dispute.`
: `Contribute arbitration fees to the submitter's appeal for a chance to win at most ${formatEther(
requesterFees.potentialReward
)} ${nativeCurrency}.`}
</StyledParagraph>
</StyledSection>
<StyledSection>
<StyledTitle strong level={4}>
Challenger
</StyledTitle>
<Progress
percent={hasPaid[PARTY.CHALLENGER] ? 100 : challengerPercentage}
status={hasPaid[PARTY.CHALLENGER] ? 'success' : 'active'}
showInfo={false}
/>
<br />
<StyledParagraph>
{hasPaid[PARTY.CHALLENGER]
? 'Challenger fully funded. The submitter must now fully fund his side of the appeal before the deadline in order not to lose the dispute.'
: `Contribute arbitration fees to the challenger's appeal for a chance to win at most ${formatEther(
challengerFees.potentialReward
)} ${nativeCurrency}.`}
</StyledParagraph>
</StyledSection>
<StyledSection>
<StyledIcon icon="info-circle" size="2x" />
<StyledParagraph>
{currentRuling === PARTY.NONE
? 'The arbitrator did not give a decisive ruling. If a party fully funds his side of an appeal, the other must also fund in order to not lose the dispute.'
: `If the ${
currentRuling === PARTY.REQUESTER ? 'challenger' : 'submitter'
} fully funds his side of the appeal, the ${
currentRuling === PARTY.REQUESTER ? 'submitter' : 'challenger'
} must also fund his side of the appeal in order not to lose the case.`}
the round.
</StyledParagraph>
{klerosAddress.toLowerCase() === arbitrator.toLowerCase() ? (
<StyledParagraph>
Please{' '}
<a href={uiURL.replace(':disputeID', disputeID.toString())}>
go to the Kleros Court
</a>{' '}
to manage this step.
</StyledParagraph>
) : (
<StyledParagraph>
The arbitrator that rules the inclusion of this item is not
compatible with Kleros Court. If you wanted to appeal, please
request assistance in Telegram.
</StyledParagraph>
)}
</StyledSection>
</StyledContent>
</StyledCard>
Expand Down
7 changes: 6 additions & 1 deletion src/pages/item-details/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,12 @@ const ItemDetails = ({ itemID, search }) => {
itemMetaEvidence={itemMetaEvidence}
/>
{/* Crowdfunding card is only rendered if the item has an appealable dispute. */}
<CrowdfundingCard item={decodedItem || item} timestamp={timestamp} />
{/* V2 arbitrator handles appeals internally, so appeal logic is removed. */}
<CrowdfundingCard
item={decodedItem || item}
timestamp={timestamp}
request={requests ? requests[requests.length - 1] : {}}
/>

{/* Spread the `requests` parameter to convert elements from array to an object */}
<RequestTimelines
Expand Down
18 changes: 1 addition & 17 deletions src/pages/item-details/item-status-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ const ItemStatusCard = ({
} = useContext(TCRViewContext)

// Get remaining appeal time, if any and build countdown.
const { appealRemainingTime, appealRemainingTimeLoser } = useAppealTime(item)
const { appealRemainingTime } = useAppealTime(item)
const appealCountdown = useHumanizedCountdown(appealRemainingTime)
const appealLoserCountdown = useHumanizedCountdown(appealRemainingTimeLoser)
const { arbitrator: klerosAddress, uiURL } =
getNetworkEnv('REACT_APP_KLEROS_ADDRESSES', networkId) || {}

Expand Down Expand Up @@ -274,21 +273,6 @@ const ItemStatusCard = ({
{appealCountdown}
</Descriptions.Item>
)}
{/* Decisive ruling winner countdown. */}
{currentRuling !== PARTY.NONE &&
(statusCode === STATUS_CODE.CROWDFUNDING ||
statusCode === STATUS_CODE.CROWDFUNDING_WINNER) && (
<Descriptions.Item label="Winner Appeal Time">
{appealCountdown}
</Descriptions.Item>
)}
{/* Decisive ruling loser countdown. */}
{currentRuling !== PARTY.NONE &&
statusCode === STATUS_CODE.CROWDFUNDING && (
<Descriptions.Item label="Loser Appeal Time">
{appealLoserCountdown}
</Descriptions.Item>
)}
</StyledDescriptions>
</Card>
{/* Only render modal if the item status requires it. */}
Expand Down
Loading