@@ -139,8 +139,12 @@ const SimulatorPopup: React.FC<ISimulatorPopup> = ({ amountToStake, isStaking })
139
139
const { address } = useAccount ( ) ;
140
140
const { data : stakeData } = useJurorStakeDetailsQuery ( address ?. toLowerCase ( ) as `0x${string } `) ;
141
141
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 ;
144
148
145
149
const timeframedCourtData = useHomePageExtraStats ( 30 ) ;
146
150
const { prices : pricesData } = useCoinPrice ( [ CoinIds . ETH , CoinIds . PNK ] ) ;
@@ -150,72 +154,108 @@ const SimulatorPopup: React.FC<ISimulatorPopup> = ({ amountToStake, isStaking })
150
154
return timeframedCourtData ?. data ?. courts ?. find ( ( c ) => c . id === id ) ;
151
155
} , [ timeframedCourtData , id ] ) ;
152
156
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 ;
182
214
183
215
const currentDrawingOdds =
184
- effectiveStakeAsNumber && calculateJurorOdds ( currentEffectiveStake , effectiveStakeAsNumber ) ;
216
+ ! isUndefined ( jurorCurrentEffectiveStake ) && ! isUndefined ( courtCurrentEffectiveStake )
217
+ ? calculateJurorOdds ( jurorCurrentEffectiveStake , courtCurrentEffectiveStake )
218
+ : undefined ;
185
219
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 ;
194
234
195
235
const simulatorItems = [
196
236
{
197
237
title : "Votes" ,
198
238
icon : < GavelIcon /> ,
199
- currentValue : ` ${ currentExpectedVotes } ` ,
200
- futureValue : ` ${ futureExpectedVotes } ` ,
239
+ currentValue : currentExpectedVotes ,
240
+ futureValue : futureExpectedVotes ,
201
241
} ,
202
242
{
203
243
title : "Cases" ,
204
244
icon : < LawBalanceIcon /> ,
205
- currentValue : ` ${ currentExpectedCases } ` ,
206
- futureValue : ` ${ futureExpectedCases } ` ,
245
+ currentValue : currentExpectedCases ,
246
+ futureValue : futureExpectedCases ,
207
247
} ,
208
248
{
209
249
title : "Drawing Odds" ,
210
250
icon : < DiceIcon /> ,
211
- currentValue : ` ${ currentDrawingOdds } ` ,
212
- futureValue : ` ${ futureDrawingOdds } ` ,
251
+ currentValue : currentDrawingOdds ,
252
+ futureValue : futureDrawingOdds ,
213
253
} ,
214
254
{
215
255
title : "Rewards" ,
216
256
icon : < DollarIcon /> ,
217
- currentValue : ` ${ currentExpectedRewardsUSD } ` ,
218
- futureValue : ` ${ futureExpectedRewardsUSD } ` ,
257
+ currentValue : currentExpectedRewardsUSD ,
258
+ futureValue : futureExpectedRewardsUSD ,
219
259
tooltipMsg :
220
260
"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." ,
221
261
} ,
@@ -225,7 +265,7 @@ const SimulatorPopup: React.FC<ISimulatorPopup> = ({ amountToStake, isStaking })
225
265
< Container >
226
266
< Header />
227
267
< Divider />
228
- < QuantityToSimulate { ...{ currentEffectiveStake , currentSpecificStake , isStaking, amountToStake } } />
268
+ < QuantityToSimulate { ...{ jurorCurrentEffectiveStake , jurorCurrentSpecificStake , isStaking, amountToStake } } />
229
269
< ItemsContainer >
230
270
{ simulatorItems . map ( ( item , index ) => (
231
271
< SimulatorItem key = { index } >
@@ -241,14 +281,14 @@ const SimulatorPopup: React.FC<ISimulatorPopup> = ({ amountToStake, isStaking })
241
281
</ LeftContent >
242
282
< RightContent >
243
283
< StyledCurrentValue >
244
- { ! item . currentValue . includes ( "undefined" ) ? item . currentValue : < Skeleton width = { 32 } /> }
284
+ { ! isUndefined ( item . currentValue ) ? item . currentValue : < Skeleton width = { 32 } /> }
245
285
</ StyledCurrentValue >
246
286
< StyledArrowRightIcon { ...{ isStaking } } />
247
287
< StyledFutureValue >
248
288
{ ! amountToStake || amountToStake === 0 ? "Enter amount" : null }
249
289
{ ! isUndefined ( amountToStake ) &&
250
290
amountToStake > 0 &&
251
- ( ! item . futureValue . includes ( "undefined" ) ? item . futureValue : < Skeleton width = { 32 } /> ) }
291
+ ( ! isUndefined ( item . futureValue ) ? item . futureValue : < Skeleton width = { 32 } /> ) }
252
292
</ StyledFutureValue >
253
293
</ RightContent >
254
294
</ SimulatorItem >
0 commit comments