Skip to content

Commit 6197733

Browse files
committed
feat: add total stake info in stakes tab
1 parent f701d8f commit 6197733

File tree

3 files changed

+54
-31
lines changed

3 files changed

+54
-31
lines changed

web/src/components/NumberDisplay.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from "react";
22

33
import { Tooltip } from "@kleros/ui-components-library";
4+
5+
import { commify } from "utils/commify";
46
interface INumberDisplay {
57
value: string | number;
68
unit?: string;
@@ -31,7 +33,7 @@ const NumberDisplay: React.FC<INumberDisplay> = ({
3133
isCurrency = false,
3234
}) => {
3335
const parsedValue = Number(value);
34-
const formattedValue = getFormattedValue(parsedValue, decimals);
36+
const formattedValue = commify(getFormattedValue(parsedValue, decimals));
3537
const tooltipValue = isCurrency ? `${unit} ${value}` : `${value} ${unit}`;
3638
const displayUnit = showUnitInDisplay ? unit : "";
3739
const displayValue = isCurrency ? `${displayUnit} ${formattedValue}` : `${formattedValue} ${displayUnit}`;

web/src/pages/Profile/Stakes/Header.tsx

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import React from "react";
22
import styled, { css } from "styled-components";
33

4+
import { landscapeStyle } from "styles/landscapeStyle";
5+
import { responsiveSize } from "styles/responsiveSize";
6+
47
import { formatUnits } from "viem";
58

9+
import PnkIcon from "svgs/icons/pnk.svg";
610
import LockerIcon from "svgs/icons/locker.svg";
711

812
import { isUndefined } from "utils/index";
913

10-
import { landscapeStyle } from "styles/landscapeStyle";
11-
import { responsiveSize } from "styles/responsiveSize";
12-
1314
import NumberDisplay from "components/NumberDisplay";
1415

1516
const Container = styled.div`
@@ -28,48 +29,72 @@ const Container = styled.div`
2829
)}
2930
`;
3031

31-
const LockedPnk = styled.div`
32+
const StakedPnk = styled.div`
3233
display: flex;
33-
flex-wrap: nowrap;
3434
gap: 8px;
35-
justify-content: flex-start;
35+
align-items: center;
36+
`;
3637

37-
${landscapeStyle(
38-
() => css`
39-
align-self: center;
40-
`
41-
)}
38+
const LockedPnk = styled.div`
39+
display: flex;
40+
gap: 8px;
41+
align-items: center;
4242
`;
4343

4444
const StyledTitle = styled.h1`
4545
margin-bottom: 0;
4646
font-size: ${responsiveSize(20, 24)};
4747
`;
4848

49+
const TotalStakeAndLockedPnk = styled.div`
50+
display: flex;
51+
flex-direction: row;
52+
gap: 12px 24px;
53+
flex-wrap: wrap;
54+
`;
55+
56+
const StyledPnkIcon = styled(PnkIcon)`
57+
fill: ${({ theme }) => theme.secondaryPurple};
58+
width: 14px;
59+
`;
60+
4961
const StyledLockerIcon = styled(LockerIcon)`
5062
fill: ${({ theme }) => theme.secondaryPurple};
5163
width: 14px;
5264
`;
5365

5466
interface IHeader {
55-
lockedStake: bigint;
67+
totalStake: string;
68+
lockedStake: string;
5669
}
5770

58-
const Header: React.FC<IHeader> = ({ lockedStake }) => {
59-
const formattedLockedStake = !isUndefined(lockedStake) && formatUnits(lockedStake, 18);
71+
const Header: React.FC<IHeader> = ({ totalStake, lockedStake }) => {
72+
const formattedTotalStake = formatUnits(BigInt(totalStake), 18);
73+
const formattedLockedStake = formatUnits(BigInt(lockedStake), 18);
6074

6175
return (
6276
<Container>
6377
<StyledTitle>Stakes</StyledTitle>
64-
{!isUndefined(lockedStake) ? (
65-
<LockedPnk>
66-
<StyledLockerIcon />
67-
<label> Locked Stake: </label>
68-
<small>
69-
<NumberDisplay value={formattedLockedStake.toString()} unit="PNK" />
70-
</small>
71-
</LockedPnk>
72-
) : null}
78+
<TotalStakeAndLockedPnk>
79+
{!isUndefined(totalStake) ? (
80+
<StakedPnk>
81+
<StyledPnkIcon />
82+
<label> Total Stake: </label>
83+
<small>
84+
<NumberDisplay value={formattedTotalStake} unit="PNK" />
85+
</small>
86+
</StakedPnk>
87+
) : null}
88+
{!isUndefined(lockedStake) ? (
89+
<LockedPnk>
90+
<StyledLockerIcon />
91+
<label> Locked Stake: </label>
92+
<small>
93+
<NumberDisplay value={formattedLockedStake} unit="PNK" />
94+
</small>
95+
</LockedPnk>
96+
) : null}
97+
</TotalStakeAndLockedPnk>
7398
</Container>
7499
);
75100
};

web/src/pages/Profile/Stakes/index.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import styled, { css } from "styled-components";
33

44
import Skeleton from "react-loading-skeleton";
55

6-
import { useReadSortitionModuleGetJurorBalance } from "hooks/contracts/generated";
7-
86
import { useJurorStakeDetailsQuery } from "queries/useJurorStakeDetailsQuery";
97

108
import { landscapeStyle } from "styles/landscapeStyle";
@@ -40,16 +38,14 @@ interface IStakes {
4038

4139
const Stakes: React.FC<IStakes> = ({ searchParamAddress }) => {
4240
const { data: stakeData, isLoading } = useJurorStakeDetailsQuery(searchParamAddress);
43-
const { data: jurorBalance } = useReadSortitionModuleGetJurorBalance({
44-
args: [searchParamAddress, BigInt(1)],
45-
});
4641
const stakedCourts = stakeData?.jurorTokensPerCourts?.filter(({ staked }) => staked > 0);
4742
const isStaked = stakedCourts && stakedCourts.length > 0;
48-
const lockedStake = jurorBalance?.[1];
43+
const totalStake = stakeData?.jurorTokensPerCourts?.[0]?.effectiveStake ?? "0";
44+
const lockedStake = stakeData?.jurorTokensPerCourts?.[0]?.locked ?? "0";
4945

5046
return (
5147
<Container>
52-
<Header lockedStake={lockedStake ?? BigInt(0)} />
48+
<Header {...{ totalStake, lockedStake }} />
5349
{isLoading ? <Skeleton /> : null}
5450
{!isStaked && !isLoading ? <StyledLabel>No stakes found</StyledLabel> : null}
5551
{isStaked && !isLoading ? (

0 commit comments

Comments
 (0)