11import React , { useMemo , useState , createContext , useContext } from "react" ;
22import { useParams } from "react-router-dom" ;
3- import { BigNumber } from "ethers" ;
43import { ONE_BASIS_POINT } from "consts/index" ;
54import { Periods } from "consts/periods" ;
65import { notUndefined } from "utils/index" ;
76import { useGetMetaEvidence } from "queries/useGetMetaEvidence" ;
87import { useAppealCost } from "queries/useAppealCost" ;
98import { useDisputeKitClassicMultipliers } from "queries/useDisputeKitClassicMultipliers" ;
10- import {
11- useClassicAppealQuery ,
12- ClassicAppealQuery ,
13- } from "queries/useClassicAppealQuery" ;
9+ import { useClassicAppealQuery , ClassicAppealQuery } from "queries/useClassicAppealQuery" ;
1410import { useCountdown } from "hooks/useCountdown" ;
1511
1612const LoserSideCountdownContext = createContext < number | undefined > ( undefined ) ;
@@ -29,9 +25,9 @@ const SelectedOptionContext = createContext<ISelectedOptionContext>({
2925
3026interface IFundingContext {
3127 winningChoice : string | undefined ;
32- paidFees : BigNumber [ ] | undefined ;
33- loserRequiredFunding : BigNumber | undefined ;
34- winnerRequiredFunding : BigNumber | undefined ;
28+ paidFees : bigint [ ] | undefined ;
29+ loserRequiredFunding : bigint | undefined ;
30+ winnerRequiredFunding : bigint | undefined ;
3531 fundedChoices : string [ ] | undefined ;
3632}
3733const FundingContext = createContext < IFundingContext > ( {
@@ -54,31 +50,20 @@ export const ClassicAppealProvider: React.FC<{
5450 const arbitrable = data ?. dispute ?. arbitrated . id ;
5551 const { data : metaEvidence } = useGetMetaEvidence ( id , arbitrable ) ;
5652 const { data : multipliers } = useDisputeKitClassicMultipliers ( ) ;
57- const options = [ "Refuse to Arbitrate" ] . concat (
58- metaEvidence ?. rulingOptions ?. titles
59- ) ;
53+ const options = [ "Refuse to Arbitrate" ] . concat ( metaEvidence ?. rulingOptions ?. titles ) ;
6054 const loserSideCountdown = useLoserSideCountdown (
6155 dispute ?. lastPeriodChange ,
6256 dispute ?. court . timesPerPeriod [ Periods . appeal ] ,
63- multipliers ?. loser_appeal_period_multiplier . toString ( )
64- ) ;
65- const loserRequiredFunding = getLoserRequiredFunding (
66- appealCost ,
67- multipliers ?. loser_stake_multiplier
68- ) ;
69- const winnerRequiredFunding = getWinnerRequiredFunding (
70- appealCost ,
71- multipliers ?. winner_stake_multiplier
57+ multipliers ?. loser_appeal_period_multiplier . toString ( ) !
7258 ) ;
59+ const loserRequiredFunding = getLoserRequiredFunding ( appealCost ! , multipliers ?. loser_stake_multiplier ! ) ;
60+ const winnerRequiredFunding = getWinnerRequiredFunding ( appealCost ! , multipliers ?. winner_stake_multiplier ! ) ;
7361 const fundedChoices = getFundedChoices ( data ?. dispute ) ;
7462 const [ selectedOption , setSelectedOption ] = useState < number | undefined > ( ) ;
7563 return (
7664 < LoserSideCountdownContext . Provider value = { loserSideCountdown } >
7765 < SelectedOptionContext . Provider
78- value = { useMemo (
79- ( ) => ( { selectedOption, setSelectedOption } ) ,
80- [ selectedOption , setSelectedOption ]
81- ) }
66+ value = { useMemo ( ( ) => ( { selectedOption, setSelectedOption } ) , [ selectedOption , setSelectedOption ] ) }
8267 >
8368 < FundingContext . Provider
8469 value = { useMemo (
@@ -89,39 +74,29 @@ export const ClassicAppealProvider: React.FC<{
8974 winnerRequiredFunding,
9075 fundedChoices,
9176 } ) ,
92- [
93- winningChoice ,
94- paidFees ,
95- loserRequiredFunding ,
96- winnerRequiredFunding ,
97- fundedChoices ,
98- ]
77+ [ winningChoice , paidFees , loserRequiredFunding , winnerRequiredFunding , fundedChoices ]
9978 ) }
10079 >
101- < OptionsContext . Provider value = { options } >
102- { children }
103- </ OptionsContext . Provider >
80+ < OptionsContext . Provider value = { options } > { children } </ OptionsContext . Provider >
10481 </ FundingContext . Provider >
10582 </ SelectedOptionContext . Provider >
10683 </ LoserSideCountdownContext . Provider >
10784 ) ;
10885} ;
10986
110- export const useLoserSideCountdownContext = ( ) =>
111- useContext ( LoserSideCountdownContext ) ;
87+ export const useLoserSideCountdownContext = ( ) => useContext ( LoserSideCountdownContext ) ;
11288export const useSelectedOptionContext = ( ) => useContext ( SelectedOptionContext ) ;
11389export const useFundingContext = ( ) => useContext ( FundingContext ) ;
11490export const useOptionsContext = ( ) => useContext ( OptionsContext ) ;
11591
11692const getCurrentLocalRound = ( dispute ?: ClassicAppealQuery [ "dispute" ] ) => {
117- const currentLocalRoundIndex =
118- dispute ?. disputeKitDispute ?. currentLocalRoundIndex ;
93+ const currentLocalRoundIndex = dispute ?. disputeKitDispute ?. currentLocalRoundIndex ;
11994 return dispute ?. disputeKitDispute ?. localRounds [ currentLocalRoundIndex ] ;
12095} ;
12196
12297const getPaidFees = ( dispute ?: ClassicAppealQuery [ "dispute" ] ) => {
12398 const currentLocalRound = getCurrentLocalRound ( dispute ) ;
124- return currentLocalRound ?. paidFees . map ( ( amount ) => BigNumber . from ( amount ) ) ;
99+ return currentLocalRound ?. paidFees . map ( ( amount ) => BigInt ( amount ) ) ;
125100} ;
126101
127102const getFundedChoices = ( dispute ?: ClassicAppealQuery [ "dispute" ] ) => {
@@ -134,57 +109,29 @@ const getWinningChoice = (dispute?: ClassicAppealQuery["dispute"]) => {
134109 return currentLocalRound ?. winningChoice ;
135110} ;
136111
137- const getLoserRequiredFunding = (
138- appealCost : BigNumber ,
139- loser_stake_multiplier : BigNumber
140- ) : BigNumber =>
112+ const getLoserRequiredFunding = ( appealCost : bigint , loser_stake_multiplier : bigint ) : bigint =>
141113 notUndefined ( [ appealCost , loser_stake_multiplier ] )
142- ? appealCost . add (
143- loser_stake_multiplier . mul ( appealCost ) . div ( ONE_BASIS_POINT )
144- )
145- : BigNumber . from ( 0 ) ;
114+ ? appealCost + ( loser_stake_multiplier * appealCost ) / ONE_BASIS_POINT
115+ : 0n ;
146116
147- const getWinnerRequiredFunding = (
148- appealCost : BigNumber ,
149- winner_stake_multiplier : BigNumber
150- ) : BigNumber =>
117+ const getWinnerRequiredFunding = ( appealCost : bigint , winner_stake_multiplier : bigint ) : bigint =>
151118 notUndefined ( [ appealCost , winner_stake_multiplier ] )
152- ? appealCost . add (
153- winner_stake_multiplier . mul ( appealCost ) . div ( ONE_BASIS_POINT )
154- )
155- : BigNumber . from ( 0 ) ;
119+ ? appealCost + ( winner_stake_multiplier * appealCost ) / ONE_BASIS_POINT
120+ : 0n ;
156121
157- const getDeadline = (
158- lastPeriodChange : string ,
159- appealPeriodDuration : string ,
160- loserTimeMultiplier : string
161- ) : number => {
162- const parsedLastPeriodChange = BigNumber . from ( lastPeriodChange ) ;
163- const parsedAppealPeriodDuration = BigNumber . from ( appealPeriodDuration ) ;
164- const parsedLoserTimeMultiplier = BigNumber . from ( loserTimeMultiplier ) ;
165- const loserAppealPeriodDuration = parsedAppealPeriodDuration
166- . mul ( parsedLoserTimeMultiplier )
167- . div ( ONE_BASIS_POINT ) ;
168- return loserAppealPeriodDuration . add ( parsedLastPeriodChange ) . toNumber ( ) ;
122+ const getDeadline = ( lastPeriodChange : string , appealPeriodDuration : string , loserTimeMultiplier : string ) : number => {
123+ const parsedLastPeriodChange = BigInt ( lastPeriodChange ) ;
124+ const parsedAppealPeriodDuration = BigInt ( appealPeriodDuration ) ;
125+ const parsedLoserTimeMultiplier = BigInt ( loserTimeMultiplier ) ;
126+ const loserAppealPeriodDuration = ( parsedAppealPeriodDuration * parsedLoserTimeMultiplier ) / ONE_BASIS_POINT ;
127+ return Number ( loserAppealPeriodDuration + parsedLastPeriodChange ) ;
169128} ;
170129
171- function useLoserSideCountdown (
172- lastPeriodChange : string ,
173- appealPeriodDuration : string ,
174- loserTimeMultiplier : string
175- ) {
130+ function useLoserSideCountdown ( lastPeriodChange : string , appealPeriodDuration : string , loserTimeMultiplier : string ) {
176131 const deadline = useMemo (
177132 ( ) =>
178- notUndefined ( [
179- lastPeriodChange ,
180- appealPeriodDuration ,
181- loserTimeMultiplier ,
182- ] )
183- ? getDeadline (
184- lastPeriodChange ,
185- appealPeriodDuration ,
186- loserTimeMultiplier
187- )
133+ notUndefined ( [ lastPeriodChange , appealPeriodDuration , loserTimeMultiplier ] )
134+ ? getDeadline ( lastPeriodChange , appealPeriodDuration , loserTimeMultiplier )
188135 : 0 ,
189136 [ lastPeriodChange , appealPeriodDuration , loserTimeMultiplier ]
190137 ) ;
0 commit comments