@@ -11,18 +11,21 @@ import { getLocalRounds } from "utils/getLocalRounds";
1111import { useAppealCost } from "queries/useAppealCost" ;
1212import { useClassicAppealQuery , ClassicAppealQuery } from "queries/useClassicAppealQuery" ;
1313import { useDisputeKitClassicMultipliers } from "queries/useDisputeKitClassicMultipliers" ;
14+ import { Answer , DisputeDetails } from "@kleros/kleros-sdk" ;
1415
16+ type Option = Answer & { paidFee ?: string ; funded ?: boolean } ;
1517interface ICountdownContext {
1618 loserSideCountdown ?: number ;
1719 winnerSideCountdown ?: number ;
1820}
21+
1922const CountdownContext = createContext < ICountdownContext > ( { } ) ;
2023
21- const OptionsContext = createContext < string [ ] | undefined > ( undefined ) ;
24+ const OptionsContext = createContext < Option [ ] | undefined > ( undefined ) ;
2225
2326interface ISelectedOptionContext {
24- selectedOption : number | undefined ;
25- setSelectedOption : ( arg0 : number ) => void ;
27+ selectedOption : Option | undefined ;
28+ setSelectedOption : ( arg0 : Option ) => void ;
2629}
2730const SelectedOptionContext = createContext < ISelectedOptionContext > ( {
2831 selectedOption : undefined ,
@@ -32,14 +35,13 @@ const SelectedOptionContext = createContext<ISelectedOptionContext>({
3235
3336interface IFundingContext {
3437 winningChoice : string | undefined ;
35- paidFees : bigint [ ] | undefined ;
3638 loserRequiredFunding : bigint | undefined ;
3739 winnerRequiredFunding : bigint | undefined ;
3840 fundedChoices : string [ ] | undefined ;
3941}
42+
4043const FundingContext = createContext < IFundingContext > ( {
4144 winningChoice : undefined ,
42- paidFees : undefined ,
4345 loserRequiredFunding : undefined ,
4446 winnerRequiredFunding : undefined ,
4547 fundedChoices : undefined ,
@@ -51,17 +53,16 @@ export const ClassicAppealProvider: React.FC<{
5153 const { id } = useParams ( ) ;
5254 const { data } = useClassicAppealQuery ( id ) ;
5355 const dispute = data ?. dispute ;
54- const paidFees = getPaidFees ( data ?. dispute ) ;
5556 const winningChoice = getWinningChoice ( data ?. dispute ) ;
5657 const { data : appealCost } = useAppealCost ( id ) ;
5758 const arbitrable = data ?. dispute ?. arbitrated . id ;
58- const { data : disputeDetails } = usePopulatedDisputeData ( id , arbitrable ) ;
59+ const { data : disputeDetails } = usePopulatedDisputeData ( id , arbitrable as `0x${ string } ` ) ;
5960 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+
6566 const loserSideCountdown = useLoserSideCountdown (
6667 dispute ?. lastPeriodChange ,
6768 dispute ?. court . timesPerPeriod [ Periods . appeal ] ,
@@ -81,7 +82,6 @@ export const ClassicAppealProvider: React.FC<{
8182 [ appealCost , multipliers ]
8283 ) ;
8384 const fundedChoices = getFundedChoices ( data ?. dispute ) ;
84- const [ selectedOption , setSelectedOption ] = useState < number | undefined > ( ) ;
8585
8686 return (
8787 < CountdownContext . Provider
@@ -94,12 +94,11 @@ export const ClassicAppealProvider: React.FC<{
9494 value = { useMemo (
9595 ( ) => ( {
9696 winningChoice,
97- paidFees,
9897 loserRequiredFunding,
9998 winnerRequiredFunding,
10099 fundedChoices,
101100 } ) ,
102- [ winningChoice , paidFees , loserRequiredFunding , winnerRequiredFunding , fundedChoices ]
101+ [ winningChoice , loserRequiredFunding , winnerRequiredFunding , fundedChoices ]
103102 ) }
104103 >
105104 < OptionsContext . Provider value = { options } > { children } </ OptionsContext . Provider >
@@ -126,9 +125,22 @@ const getCurrentLocalRound = (dispute?: ClassicAppealQuery["dispute"]) => {
126125 return getLocalRounds ( dispute . disputeKitDispute ) [ adjustedRoundIndex ] ;
127126} ;
128127
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 ;
132144} ;
133145
134146const getFundedChoices = ( dispute ?: ClassicAppealQuery [ "dispute" ] ) => {
0 commit comments