Skip to content

Commit aa7390e

Browse files
committed
fix(web): my courts section not working on dashboard
1 parent 0ff85f8 commit aa7390e

File tree

2 files changed

+36
-37
lines changed

2 files changed

+36
-37
lines changed

web/src/pages/Dashboard/Courts/CourtCard.tsx

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react";
22
import styled from "styled-components";
33
import { useAccount } from "wagmi";
4-
import { formatEther } from "viem";
4+
import { formatUnits } from "viem";
55
import { Card as _Card, Breadcrumb } from "@kleros/ui-components-library";
66
import WithHelpTooltip from "../WithHelpTooltip";
77
import { isUndefined } from "utils/index";
@@ -33,8 +33,6 @@ const tooltipMsg =
3333
"The locked stake of incoherent jurors is redistributed as incentives for " +
3434
"the coherent jurors.";
3535

36-
export const format = (value: bigint | undefined): string => (value !== undefined ? formatEther(value) : "0");
37-
3836
interface ICourtCard {
3937
id: string;
4038
name: string;
@@ -44,31 +42,30 @@ const CourtCard: React.FC<ICourtCard> = ({ id, name }) => {
4442
const { address } = useAccount();
4543
const { data: jurorBalance } = useKlerosCoreGetJurorBalance({
4644
enabled: !isUndefined(address),
47-
args: [address, id],
45+
args: [address!, BigInt(id)],
4846
watch: true,
4947
});
5048

51-
const stake = format(jurorBalance?.[0]);
52-
const lockedStake = format(jurorBalance?.[1]);
49+
const stake = jurorBalance?.[0] ?? BigInt(0);
50+
const lockedStake = jurorBalance?.[1] ?? BigInt(0);
51+
const formatedStake = formatUnits(stake, 18);
52+
const formatedLockedStake = formatUnits(lockedStake, 18);
5353

54-
return (
55-
stake !== "0" ||
56-
(lockedStake !== "0" && (
57-
<Card>
58-
<StyledBreadcrumb items={[{ text: name, value: 0 }]} />
59-
<ValueContainer>
60-
<label> Stake: </label>
61-
<small>{`${stake} PNK`}</small>
62-
</ValueContainer>
63-
<ValueContainer>
64-
<WithHelpTooltip {...{ place: "bottom", tooltipMsg }}>
65-
<label> Locked Stake: </label>
66-
</WithHelpTooltip>
67-
<small>{`${lockedStake} PNK`}</small>
68-
</ValueContainer>
69-
</Card>
70-
))
71-
);
54+
return stake > 0 || lockedStake > 0 ? (
55+
<Card>
56+
<StyledBreadcrumb items={[{ text: name, value: 0 }]} />
57+
<ValueContainer>
58+
<label> Stake: </label>
59+
<small>{`${formatedStake} PNK`}</small>
60+
</ValueContainer>
61+
<ValueContainer>
62+
<WithHelpTooltip {...{ place: "bottom", tooltipMsg }}>
63+
<label> Locked Stake: </label>
64+
</WithHelpTooltip>
65+
<small>{`${formatedLockedStake} PNK`}</small>
66+
</ValueContainer>
67+
</Card>
68+
) : null;
7269
};
7370

7471
export default CourtCard;

web/src/pages/Dashboard/Courts/index.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from "react";
22
import styled from "styled-components";
33
import { useAccount } from "wagmi";
4+
import { useFragment as getFragment } from "src/graphql";
5+
import { useUserQuery, userFragment } from "queries/useUser";
46
import { isUndefined } from "utils/index";
57
import CourtCard from "./CourtCard";
6-
import { useUserQuery } from "queries/useUser";
78

89
const Container = styled.div`
910
margin-top: 64px;
@@ -22,21 +23,22 @@ const CourtsContainer = styled.div`
2223

2324
const Courts: React.FC = () => {
2425
const { address } = useAccount();
25-
const { data } = useUserQuery(address?.toLowerCase());
26+
const { data } = useUserQuery(address?.toLowerCase() as `0x${string}`);
27+
const user = getFragment(userFragment, data?.user);
28+
console.log(user);
2629

2730
return (
28-
<>
29-
<Container>
30-
<h1> My Courts </h1>
31-
{!isUndefined(data) && <hr />}
32-
<CourtsContainer>
33-
{!isUndefined(data) &&
34-
data.user?.tokens?.map(({ court: { id, name } }) => {
31+
<Container>
32+
<h1> My Courts </h1>
33+
{!isUndefined(data) ? <hr /> : null}
34+
<CourtsContainer>
35+
{!isUndefined(data)
36+
? user?.tokens?.map(({ court: { id, name } }) => {
3537
return <CourtCard key={id} id={id} name={name ?? ""} />;
36-
})}
37-
</CourtsContainer>
38-
</Container>
39-
</>
38+
})
39+
: null}
40+
</CourtsContainer>
41+
</Container>
4042
);
4143
};
4244

0 commit comments

Comments
 (0)