@@ -11,18 +11,21 @@ import { getLocalRounds } from "utils/getLocalRounds";
11
11
import { useAppealCost } from "queries/useAppealCost" ;
12
12
import { useClassicAppealQuery , ClassicAppealQuery } from "queries/useClassicAppealQuery" ;
13
13
import { useDisputeKitClassicMultipliers } from "queries/useDisputeKitClassicMultipliers" ;
14
+ import { Answer , DisputeDetails } from "@kleros/kleros-sdk" ;
14
15
16
+ type Option = Answer & { paidFee ?: string ; funded ?: boolean } ;
15
17
interface ICountdownContext {
16
18
loserSideCountdown ?: number ;
17
19
winnerSideCountdown ?: number ;
18
20
}
21
+
19
22
const CountdownContext = createContext < ICountdownContext > ( { } ) ;
20
23
21
- const OptionsContext = createContext < string [ ] | undefined > ( undefined ) ;
24
+ const OptionsContext = createContext < Option [ ] | undefined > ( undefined ) ;
22
25
23
26
interface ISelectedOptionContext {
24
- selectedOption : number | undefined ;
25
- setSelectedOption : ( arg0 : number ) => void ;
27
+ selectedOption : Option | undefined ;
28
+ setSelectedOption : ( arg0 : Option ) => void ;
26
29
}
27
30
const SelectedOptionContext = createContext < ISelectedOptionContext > ( {
28
31
selectedOption : undefined ,
@@ -32,14 +35,13 @@ const SelectedOptionContext = createContext<ISelectedOptionContext>({
32
35
33
36
interface IFundingContext {
34
37
winningChoice : string | undefined ;
35
- paidFees : bigint [ ] | undefined ;
36
38
loserRequiredFunding : bigint | undefined ;
37
39
winnerRequiredFunding : bigint | undefined ;
38
40
fundedChoices : string [ ] | undefined ;
39
41
}
42
+
40
43
const FundingContext = createContext < IFundingContext > ( {
41
44
winningChoice : undefined ,
42
- paidFees : undefined ,
43
45
loserRequiredFunding : undefined ,
44
46
winnerRequiredFunding : undefined ,
45
47
fundedChoices : undefined ,
@@ -51,17 +53,16 @@ export const ClassicAppealProvider: React.FC<{
51
53
const { id } = useParams ( ) ;
52
54
const { data } = useClassicAppealQuery ( id ) ;
53
55
const dispute = data ?. dispute ;
54
- const paidFees = getPaidFees ( data ?. dispute ) ;
55
56
const winningChoice = getWinningChoice ( data ?. dispute ) ;
56
57
const { data : appealCost } = useAppealCost ( id ) ;
57
58
const arbitrable = data ?. dispute ?. arbitrated . id ;
58
- const { data : disputeDetails } = usePopulatedDisputeData ( id , arbitrable ) ;
59
+ const { data : disputeDetails } = usePopulatedDisputeData ( id , arbitrable as `0x${ string } ` ) ;
59
60
const { data : multipliers } = useDisputeKitClassicMultipliers ( ) ;
60
- const options = [ "Refuse to Arbitrate" ] . concat (
61
- disputeDetails ?. answers ?. map ( ( answer : { title : string ; description : string } ) => {
62
- return answer . title ;
63
- } )
64
- ) ;
61
+
62
+ const [ selectedOption , setSelectedOption ] = useState < Option > ( ) ;
63
+
64
+ const options = useMemo ( ( ) => getOptions ( disputeDetails , data ?. dispute ) , [ disputeDetails , data ] ) ;
65
+
65
66
const loserSideCountdown = useLoserSideCountdown (
66
67
dispute ?. lastPeriodChange ,
67
68
dispute ?. court . timesPerPeriod [ Periods . appeal ] ,
@@ -81,7 +82,6 @@ export const ClassicAppealProvider: React.FC<{
81
82
[ appealCost , multipliers ]
82
83
) ;
83
84
const fundedChoices = getFundedChoices ( data ?. dispute ) ;
84
- const [ selectedOption , setSelectedOption ] = useState < number | undefined > ( ) ;
85
85
86
86
return (
87
87
< CountdownContext . Provider
@@ -94,12 +94,11 @@ export const ClassicAppealProvider: React.FC<{
94
94
value = { useMemo (
95
95
( ) => ( {
96
96
winningChoice,
97
- paidFees,
98
97
loserRequiredFunding,
99
98
winnerRequiredFunding,
100
99
fundedChoices,
101
100
} ) ,
102
- [ winningChoice , paidFees , loserRequiredFunding , winnerRequiredFunding , fundedChoices ]
101
+ [ winningChoice , loserRequiredFunding , winnerRequiredFunding , fundedChoices ]
103
102
) }
104
103
>
105
104
< OptionsContext . Provider value = { options } > { children } </ OptionsContext . Provider >
@@ -126,9 +125,22 @@ const getCurrentLocalRound = (dispute?: ClassicAppealQuery["dispute"]) => {
126
125
return getLocalRounds ( dispute . disputeKitDispute ) [ adjustedRoundIndex ] ;
127
126
} ;
128
127
129
- const getPaidFees = ( dispute ?: ClassicAppealQuery [ "dispute" ] ) => {
130
- const currentLocalRound = getCurrentLocalRound ( dispute ) ;
131
- return currentLocalRound ?. paidFees . map ( ( amount : string ) => BigInt ( amount ) ) ;
128
+ const getOptions = ( dispute ?: DisputeDetails , classicDispute ?: ClassicAppealQuery [ "dispute" ] ) => {
129
+ if ( ! dispute ) return [ ] ;
130
+ const currentLocalRound = getCurrentLocalRound ( classicDispute ) ;
131
+ const classicAnswers = currentLocalRound ?. answers ;
132
+
133
+ const options = dispute . answers . map ( ( answer ) => {
134
+ const classicAnswer = classicAnswers ?. find ( ( classicAnswer ) => BigInt ( classicAnswer . answerId ) == BigInt ( answer . id ) ) ;
135
+ // converting hexadecimal id to stringified bigint to match id fomr subgraph
136
+ return {
137
+ ...answer ,
138
+ id : BigInt ( answer . id ) . toString ( ) ,
139
+ paidFee : classicAnswer ?. paidFee ?? "0" ,
140
+ funded : classicAnswer ?. funded ?? false ,
141
+ } ;
142
+ } ) ;
143
+ return options ;
132
144
} ;
133
145
134
146
const getFundedChoices = ( dispute ?: ClassicAppealQuery [ "dispute" ] ) => {
0 commit comments