Skip to content

Commit 44b00b3

Browse files
committed
fix: more correct calculations
1 parent 86162f0 commit 44b00b3

File tree

1 file changed

+38
-48
lines changed
  • web/src/pages/Courts/CourtDetails/StakePanel/SimulatorPopup

1 file changed

+38
-48
lines changed

web/src/pages/Courts/CourtDetails/StakePanel/SimulatorPopup/index.tsx

Lines changed: 38 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -150,57 +150,47 @@ const SimulatorPopup: React.FC<ISimulatorPopup> = ({ amountToStake, isStaking })
150150
return timeframedCourtData?.data?.courts?.find((c) => c.id === id);
151151
}, [timeframedCourtData, id]);
152152

153-
const effectiveStakeAsNumber = foundCourt && Number(foundCourt.effectiveStake) / 1e18;
154-
155-
const currentExpectedVotes = foundCourt && beautifyStatNumber(currentEffectiveStake * foundCourt.treeVotesPerPnk);
156-
const futureExpectedVotes =
157-
foundCourt &&
158-
beautifyStatNumber(
159-
Math.max(
160-
isStaking
161-
? (currentEffectiveStake + amountToStake) * foundCourt.treeVotesPerPnk
162-
: (currentEffectiveStake - amountToStake) * foundCourt.treeVotesPerPnk,
163-
0
164-
)
165-
);
166-
167-
const currentExpectedCases = foundCourt && beautifyStatNumber(currentEffectiveStake * foundCourt.treeDisputesPerPnk);
168-
const futureExpectedCases =
169-
foundCourt &&
170-
beautifyStatNumber(
171-
Math.max(
172-
isStaking
173-
? (currentEffectiveStake + amountToStake) * foundCourt.treeDisputesPerPnk
174-
: (currentEffectiveStake - amountToStake) * foundCourt.treeDisputesPerPnk,
175-
0
176-
)
177-
);
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);
178182

179183
const currentDrawingOdds =
180-
effectiveStakeAsNumber && calculateJurorOdds(currentEffectiveStake, effectiveStakeAsNumber + currentEffectiveStake);
184+
effectiveStakeAsNumber && calculateJurorOdds(currentEffectiveStake, effectiveStakeAsNumber);
181185
const futureDrawingOdds =
182-
effectiveStakeAsNumber &&
183-
calculateJurorOdds(
184-
Math.max(isStaking ? currentEffectiveStake + amountToStake : currentEffectiveStake - amountToStake, 0),
185-
Math.max(
186-
effectiveStakeAsNumber +
187-
(isStaking ? currentEffectiveStake + amountToStake : currentEffectiveStake - amountToStake),
188-
0
189-
)
190-
);
191-
192-
const currentExpectedRewardsUSD =
193-
foundCourt && formatUSD(foundCourt.treeExpectedRewardPerPnk * currentEffectiveStake * ethPriceUSD);
194-
const futureExpectedRewardsUSD =
195-
foundCourt &&
196-
formatUSD(
197-
Math.max(
198-
foundCourt.treeExpectedRewardPerPnk *
199-
(isStaking ? currentEffectiveStake + amountToStake : currentEffectiveStake - amountToStake) *
200-
ethPriceUSD,
201-
0
202-
)
203-
);
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+
);
204194

205195
const simulatorItems = [
206196
{

0 commit comments

Comments
 (0)