@@ -139,8 +139,12 @@ const SimulatorPopup: React.FC<ISimulatorPopup> = ({ amountToStake, isStaking })
139139 const { address } = useAccount ( ) ;
140140 const { data : stakeData } = useJurorStakeDetailsQuery ( address ?. toLowerCase ( ) as `0x${string } `) ;
141141 const courtStakeData = stakeData ?. jurorTokensPerCourts ?. find ( ( { court } ) => court . id === id ) ;
142- const currentEffectiveStake = ! isUndefined ( courtStakeData ) ? Number ( formatEther ( courtStakeData . effectiveStake ) ) : 0 ;
143- const currentSpecificStake = ! isUndefined ( courtStakeData ) ? Number ( formatEther ( courtStakeData . staked ) ) : 0 ;
142+ const jurorCurrentEffectiveStake = ! isUndefined ( courtStakeData )
143+ ? Number ( formatEther ( courtStakeData . effectiveStake ) )
144+ : undefined ;
145+ const jurorCurrentSpecificStake = ! isUndefined ( courtStakeData )
146+ ? Number ( formatEther ( courtStakeData . staked ) )
147+ : undefined ;
144148
145149 const timeframedCourtData = useHomePageExtraStats ( 30 ) ;
146150 const { prices : pricesData } = useCoinPrice ( [ CoinIds . ETH , CoinIds . PNK ] ) ;
@@ -150,72 +154,108 @@ const SimulatorPopup: React.FC<ISimulatorPopup> = ({ amountToStake, isStaking })
150154 return timeframedCourtData ?. data ?. courts ?. find ( ( c ) => c . id === id ) ;
151155 } , [ timeframedCourtData , id ] ) ;
152156
153- const effectiveStakeAsNumber = foundCourt ? Number ( foundCourt . effectiveStake ) / 1e18 : 0 ;
154-
155- const currentTreeVotesPerPnk = foundCourt ? foundCourt . treeVotesPerPnk : 0 ;
156- const currentTreeDisputesPerPnk = foundCourt ? foundCourt . treeDisputesPerPnk : 0 ;
157- const currentTreeExpectedRewardPerPnk = foundCourt ? foundCourt . treeExpectedRewardPerPnk : 0 ;
158-
159- const totalVotes = effectiveStakeAsNumber * currentTreeVotesPerPnk ;
160- const totalCases = effectiveStakeAsNumber * currentTreeDisputesPerPnk ;
161- const totalRewards = effectiveStakeAsNumber * currentTreeExpectedRewardPerPnk ;
162-
163- const futureTotalEffectiveStake = Math . max (
164- isStaking ? effectiveStakeAsNumber + amountToStake : effectiveStakeAsNumber - amountToStake ,
165- 0
166- ) ;
167-
168- const futureTreeVotesPerPnk = futureTotalEffectiveStake !== 0 ? totalVotes / futureTotalEffectiveStake : 0 ;
169- const futureTreeDisputesPerPnk = futureTotalEffectiveStake !== 0 ? totalCases / futureTotalEffectiveStake : 0 ;
170- const futureTreeExpectedRewardPerPnk = futureTotalEffectiveStake !== 0 ? totalRewards / futureTotalEffectiveStake : 0 ;
171-
172- const futureEffectiveStake = Math . max (
173- isStaking ? currentEffectiveStake + amountToStake : currentEffectiveStake - amountToStake ,
174- 0
175- ) ;
176-
177- const currentExpectedVotes = beautifyStatNumber ( currentEffectiveStake * currentTreeVotesPerPnk ) ;
178- const futureExpectedVotes = beautifyStatNumber ( futureEffectiveStake * futureTreeVotesPerPnk ) ;
179-
180- const currentExpectedCases = beautifyStatNumber ( currentEffectiveStake * currentTreeDisputesPerPnk ) ;
181- const futureExpectedCases = beautifyStatNumber ( futureEffectiveStake * futureTreeDisputesPerPnk ) ;
157+ const courtCurrentEffectiveStake = foundCourt ? Number ( foundCourt . effectiveStake ) / 1e18 : undefined ;
158+
159+ const currentTreeVotesPerPnk = foundCourt ?. treeVotesPerPnk ;
160+ const currentTreeDisputesPerPnk = foundCourt ?. treeDisputesPerPnk ;
161+ const currentTreeExpectedRewardPerPnk = foundCourt ?. treeExpectedRewardPerPnk ;
162+
163+ const totalVotes =
164+ ! isUndefined ( courtCurrentEffectiveStake ) && ! isUndefined ( currentTreeVotesPerPnk )
165+ ? courtCurrentEffectiveStake * currentTreeVotesPerPnk
166+ : undefined ;
167+ const totalCases =
168+ ! isUndefined ( courtCurrentEffectiveStake ) && ! isUndefined ( currentTreeDisputesPerPnk )
169+ ? courtCurrentEffectiveStake * currentTreeDisputesPerPnk
170+ : undefined ;
171+ const totalRewards =
172+ ! isUndefined ( courtCurrentEffectiveStake ) && ! isUndefined ( currentTreeExpectedRewardPerPnk )
173+ ? courtCurrentEffectiveStake * currentTreeExpectedRewardPerPnk
174+ : undefined ;
175+
176+ const courtFutureEffectiveStake = ! isUndefined ( courtCurrentEffectiveStake )
177+ ? Math . max ( isStaking ? courtCurrentEffectiveStake + amountToStake : courtCurrentEffectiveStake - amountToStake , 0 )
178+ : undefined ;
179+
180+ const futureTreeVotesPerPnk =
181+ ! isUndefined ( courtFutureEffectiveStake ) && ! isUndefined ( totalVotes )
182+ ? totalVotes / courtFutureEffectiveStake
183+ : undefined ;
184+ const futureTreeDisputesPerPnk =
185+ ! isUndefined ( courtFutureEffectiveStake ) && ! isUndefined ( totalCases )
186+ ? totalCases / courtFutureEffectiveStake
187+ : undefined ;
188+ const futureTreeExpectedRewardPerPnk =
189+ ! isUndefined ( courtFutureEffectiveStake ) && ! isUndefined ( totalRewards )
190+ ? totalRewards / courtFutureEffectiveStake
191+ : undefined ;
192+
193+ const jurorFutureEffectiveStake = ! isUndefined ( jurorCurrentEffectiveStake )
194+ ? Math . max ( isStaking ? jurorCurrentEffectiveStake + amountToStake : jurorCurrentEffectiveStake - amountToStake , 0 )
195+ : undefined ;
196+
197+ const currentExpectedVotes =
198+ ! isUndefined ( jurorCurrentEffectiveStake ) && ! isUndefined ( currentTreeVotesPerPnk )
199+ ? beautifyStatNumber ( jurorCurrentEffectiveStake * currentTreeVotesPerPnk )
200+ : undefined ;
201+ const futureExpectedVotes =
202+ ! isUndefined ( jurorFutureEffectiveStake ) && ! isUndefined ( futureTreeVotesPerPnk )
203+ ? beautifyStatNumber ( jurorFutureEffectiveStake * futureTreeVotesPerPnk )
204+ : undefined ;
205+
206+ const currentExpectedCases =
207+ ! isUndefined ( jurorCurrentEffectiveStake ) && ! isUndefined ( currentTreeDisputesPerPnk )
208+ ? beautifyStatNumber ( jurorCurrentEffectiveStake * currentTreeDisputesPerPnk )
209+ : undefined ;
210+ const futureExpectedCases =
211+ ! isUndefined ( jurorFutureEffectiveStake ) && ! isUndefined ( futureTreeDisputesPerPnk )
212+ ? beautifyStatNumber ( jurorFutureEffectiveStake * futureTreeDisputesPerPnk )
213+ : undefined ;
182214
183215 const currentDrawingOdds =
184- effectiveStakeAsNumber && calculateJurorOdds ( currentEffectiveStake , effectiveStakeAsNumber ) ;
216+ ! isUndefined ( jurorCurrentEffectiveStake ) && ! isUndefined ( courtCurrentEffectiveStake )
217+ ? calculateJurorOdds ( jurorCurrentEffectiveStake , courtCurrentEffectiveStake )
218+ : undefined ;
185219 const futureDrawingOdds =
186- effectiveStakeAsNumber && calculateJurorOdds ( futureEffectiveStake , futureTotalEffectiveStake ) ;
187-
188- const currentExpectedRewardsUSD = formatUSD (
189- currentEffectiveStake * currentTreeExpectedRewardPerPnk * ( ethPriceUSD || 0 )
190- ) ;
191- const futureExpectedRewardsUSD = formatUSD (
192- futureEffectiveStake * futureTreeExpectedRewardPerPnk * ( ethPriceUSD || 0 )
193- ) ;
220+ ! isUndefined ( jurorFutureEffectiveStake ) && ! isUndefined ( courtFutureEffectiveStake )
221+ ? calculateJurorOdds ( jurorFutureEffectiveStake , courtFutureEffectiveStake )
222+ : undefined ;
223+
224+ const currentExpectedRewardsUSD =
225+ ! isUndefined ( jurorCurrentEffectiveStake ) &&
226+ ! isUndefined ( currentTreeExpectedRewardPerPnk ) &&
227+ ! isUndefined ( ethPriceUSD )
228+ ? formatUSD ( jurorCurrentEffectiveStake * currentTreeExpectedRewardPerPnk * ethPriceUSD )
229+ : undefined ;
230+ const futureExpectedRewardsUSD =
231+ ! isUndefined ( jurorFutureEffectiveStake ) && ! isUndefined ( futureTreeExpectedRewardPerPnk ) && ! isUndefined ( ethPriceUSD )
232+ ? formatUSD ( jurorFutureEffectiveStake * futureTreeExpectedRewardPerPnk * ethPriceUSD )
233+ : undefined ;
194234
195235 const simulatorItems = [
196236 {
197237 title : "Votes" ,
198238 icon : < GavelIcon /> ,
199- currentValue : ` ${ currentExpectedVotes } ` ,
200- futureValue : ` ${ futureExpectedVotes } ` ,
239+ currentValue : currentExpectedVotes ,
240+ futureValue : futureExpectedVotes ,
201241 } ,
202242 {
203243 title : "Cases" ,
204244 icon : < LawBalanceIcon /> ,
205- currentValue : ` ${ currentExpectedCases } ` ,
206- futureValue : ` ${ futureExpectedCases } ` ,
245+ currentValue : currentExpectedCases ,
246+ futureValue : futureExpectedCases ,
207247 } ,
208248 {
209249 title : "Drawing Odds" ,
210250 icon : < DiceIcon /> ,
211- currentValue : ` ${ currentDrawingOdds } ` ,
212- futureValue : ` ${ futureDrawingOdds } ` ,
251+ currentValue : currentDrawingOdds ,
252+ futureValue : futureDrawingOdds ,
213253 } ,
214254 {
215255 title : "Rewards" ,
216256 icon : < DollarIcon /> ,
217- currentValue : ` ${ currentExpectedRewardsUSD } ` ,
218- futureValue : ` ${ futureExpectedRewardsUSD } ` ,
257+ currentValue : currentExpectedRewardsUSD ,
258+ futureValue : futureExpectedRewardsUSD ,
219259 tooltipMsg :
220260 "Estimated rewards in USD, assuming 100% coherent voting. If other jurors vote incoherently, additional rewards in the form of PNK tokens may be earned beyond this estimate." ,
221261 } ,
@@ -225,7 +265,7 @@ const SimulatorPopup: React.FC<ISimulatorPopup> = ({ amountToStake, isStaking })
225265 < Container >
226266 < Header />
227267 < Divider />
228- < QuantityToSimulate { ...{ currentEffectiveStake , currentSpecificStake , isStaking, amountToStake } } />
268+ < QuantityToSimulate { ...{ jurorCurrentEffectiveStake , jurorCurrentSpecificStake , isStaking, amountToStake } } />
229269 < ItemsContainer >
230270 { simulatorItems . map ( ( item , index ) => (
231271 < SimulatorItem key = { index } >
@@ -241,14 +281,14 @@ const SimulatorPopup: React.FC<ISimulatorPopup> = ({ amountToStake, isStaking })
241281 </ LeftContent >
242282 < RightContent >
243283 < StyledCurrentValue >
244- { ! item . currentValue . includes ( "undefined" ) ? item . currentValue : < Skeleton width = { 32 } /> }
284+ { ! isUndefined ( item . currentValue ) ? item . currentValue : < Skeleton width = { 32 } /> }
245285 </ StyledCurrentValue >
246286 < StyledArrowRightIcon { ...{ isStaking } } />
247287 < StyledFutureValue >
248288 { ! amountToStake || amountToStake === 0 ? "Enter amount" : null }
249289 { ! isUndefined ( amountToStake ) &&
250290 amountToStake > 0 &&
251- ( ! item . futureValue . includes ( "undefined" ) ? item . futureValue : < Skeleton width = { 32 } /> ) }
291+ ( ! isUndefined ( item . futureValue ) ? item . futureValue : < Skeleton width = { 32 } /> ) }
252292 </ StyledFutureValue >
253293 </ RightContent >
254294 </ SimulatorItem >
0 commit comments