Skip to content

Commit 418f8aa

Browse files
committed
feat: add new stake simulator design, add new juror effectivestake metric to subgraph
1 parent 7e5779c commit 418f8aa

File tree

13 files changed

+359
-215
lines changed

13 files changed

+359
-215
lines changed

subgraph/core/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ type JurorTokensPerCourt @entity {
120120
id: ID! # user.id-court.id
121121
juror: User!
122122
court: Court!
123+
effectiveStake: BigInt!
123124
staked: BigInt!
124125
locked: BigInt!
125126
delayed: BigInt!

subgraph/core/src/entities/JurorTokensPerCourt.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export function createJurorTokensPerCourt(jurorAddress: string, courtID: string)
2323
const jurorTokens = new JurorTokensPerCourt(id);
2424
jurorTokens.juror = jurorAddress;
2525
jurorTokens.court = courtID;
26+
jurorTokens.effectiveStake = ZERO;
2627
jurorTokens.staked = ZERO;
2728
jurorTokens.locked = ZERO;
2829
jurorTokens.delayed = ZERO;
@@ -31,6 +32,37 @@ export function createJurorTokensPerCourt(jurorAddress: string, courtID: string)
3132
return jurorTokens;
3233
}
3334

35+
export function updateJurorEffectiveStake(jurorAddress: string, courtID: string): void {
36+
let court = Court.load(courtID);
37+
if (!court) {
38+
return;
39+
}
40+
41+
while (court) {
42+
const jurorTokensPerCourt = ensureJurorTokensPerCourt(jurorAddress, court.id);
43+
let totalStake = jurorTokensPerCourt.staked;
44+
const childrenCourts = court.children.load();
45+
46+
for (let i = 0; i < childrenCourts.length; i++) {
47+
const childCourtID = childrenCourts[i].id;
48+
const childCourt = Court.load(childCourtID);
49+
if (childCourt) {
50+
const childJurorTokensPerCourt = ensureJurorTokensPerCourt(jurorAddress, childCourt.id);
51+
totalStake = totalStake.plus(childJurorTokensPerCourt.effectiveStake);
52+
}
53+
}
54+
55+
jurorTokensPerCourt.effectiveStake = totalStake;
56+
jurorTokensPerCourt.save();
57+
58+
if (court.parent && court.parent !== null) {
59+
court = Court.load(court.parent as string);
60+
} else {
61+
break;
62+
}
63+
}
64+
}
65+
3466
export function updateJurorStake(
3567
jurorAddress: string,
3668
courtID: string,
@@ -61,6 +93,7 @@ export function updateJurorStake(
6193
juror.save();
6294
court.save();
6395
updateEffectiveStake(courtID);
96+
updateJurorEffectiveStake(jurorAddress, courtID);
6497
}
6598

6699
export function updateJurorDelayedStake(jurorAddress: string, courtID: string, amount: BigInt): void {
Lines changed: 10 additions & 0 deletions
Loading

web/src/assets/svgs/icons/clock.svg

Lines changed: 1 addition & 1 deletion
Loading
Lines changed: 10 additions & 0 deletions
Loading

web/src/hooks/queries/useJurorStakeDetailsQuery.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const jurorStakeDetailsQuery = graphql(`
1414
id
1515
name
1616
}
17+
effectiveStake
1718
staked
1819
locked
1920
}

web/src/pages/Courts/CourtDetails/Info.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const Container = styled.div`
66
display: flex;
77
align-items: flex-start;
88
gap: 8px;
9+
padding-top: 4px;
910
`;
1011

1112
const StyledSpan = styled.span`
@@ -14,11 +15,9 @@ const StyledSpan = styled.span`
1415
`;
1516

1617
const StyledInfoCircle = styled(InfoCircle)`
17-
display: inline-block;
1818
width: 16px;
1919
height: 16px;
2020
flex-shrink: 0;
21-
vertical-align: top;
2221
`;
2322

2423
const Info: React.FC = () => {

web/src/pages/Courts/CourtDetails/StakePanel/InputDisplay.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import React, { useState, useMemo, useEffect } from "react";
2-
import styled from "styled-components";
2+
import styled, { css } from "styled-components";
3+
import { landscapeStyle } from "styles/landscapeStyle";
34

45
import { useParams } from "react-router-dom";
56
import { useDebounce } from "react-use";
67
import { useAccount } from "wagmi";
78

89
import { REFETCH_INTERVAL } from "consts/index";
10+
911
import { useReadSortitionModuleGetJurorBalance, useReadPnkBalanceOf } from "hooks/contracts/generated";
1012
import { useParsedAmount } from "hooks/useParsedAmount";
13+
1114
import { commify, uncommify } from "utils/commify";
1215
import { formatPNK, roundNumberDown } from "utils/format";
1316
import { isUndefined } from "utils/index";
1417

1518
import { NumberInputField } from "components/NumberInputField";
16-
1719
import StakeWithdrawButton, { ActionType } from "./StakeWithdrawButton";
1820

1921
const StyledField = styled(NumberInputField)`
@@ -23,6 +25,12 @@ const StyledField = styled(NumberInputField)`
2325
const LabelArea = styled.div`
2426
display: flex;
2527
justify-content: space-between;
28+
29+
${landscapeStyle(
30+
() => css`
31+
width: 92%;
32+
`
33+
)}
2634
`;
2735

2836
const StyledLabel = styled.label`
@@ -36,6 +44,12 @@ const InputArea = styled.div`
3644
align-items: center;
3745
gap: 12px;
3846
width: 100%;
47+
48+
${landscapeStyle(
49+
() => css`
50+
width: 92%;
51+
`
52+
)}
3953
`;
4054

4155
const InputFieldAndButton = styled.div`

web/src/pages/Courts/CourtDetails/StakePanel/JurorStakeDisplay.tsx

Lines changed: 0 additions & 121 deletions
This file was deleted.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const Container = styled.div`
88
display: flex;
99
align-items: center;
1010
justify-content: space-between;
11+
flex-wrap: wrap;
12+
gap: 8px;
1113
`;
1214

1315
const PNKLogoAndTitle = styled.div`

0 commit comments

Comments
 (0)