diff --git a/web/src/components/Popup/Description/StakeWithdraw.tsx b/web/src/components/Popup/Description/StakeWithdraw.tsx index af639ad84..31693d18a 100644 --- a/web/src/components/Popup/Description/StakeWithdraw.tsx +++ b/web/src/components/Popup/Description/StakeWithdraw.tsx @@ -1,9 +1,9 @@ import React from "react"; import styled from "styled-components"; -import { isUndefined } from "utils/index"; +import { formatUnits } from "viem"; import { useAccount } from "wagmi"; +import { isUndefined } from "utils/index"; import { useKlerosCoreGetJurorBalance } from "hooks/contracts/generated"; -import { format } from "src/pages/Dashboard/Courts/CourtCard"; import KlerosLogo from "tsx:svgs/icons/kleros.svg"; const Container = styled.div` @@ -88,7 +88,7 @@ const StakeWithdraw: React.FC = ({ pnkStaked, courtName, isStake My Stake:{" "} - {`${format(jurorBalance?.[0])} PNK`} + {`${formatUnits(jurorBalance?.[0] ?? BigInt(0), 18)} PNK`} ); diff --git a/web/src/pages/Dashboard/Courts/CourtCard.tsx b/web/src/pages/Dashboard/Courts/CourtCard.tsx index 500cfb0a4..c199929e7 100644 --- a/web/src/pages/Dashboard/Courts/CourtCard.tsx +++ b/web/src/pages/Dashboard/Courts/CourtCard.tsx @@ -1,7 +1,7 @@ import React from "react"; import styled from "styled-components"; import { useAccount } from "wagmi"; -import { formatEther } from "viem"; +import { formatUnits } from "viem"; import { Card as _Card, Breadcrumb } from "@kleros/ui-components-library"; import WithHelpTooltip from "../WithHelpTooltip"; import { isUndefined } from "utils/index"; @@ -33,8 +33,6 @@ const tooltipMsg = "The locked stake of incoherent jurors is redistributed as incentives for " + "the coherent jurors."; -export const format = (value: bigint | undefined): string => (value !== undefined ? formatEther(value) : "0"); - interface ICourtCard { id: string; name: string; @@ -44,31 +42,30 @@ const CourtCard: React.FC = ({ id, name }) => { const { address } = useAccount(); const { data: jurorBalance } = useKlerosCoreGetJurorBalance({ enabled: !isUndefined(address), - args: [address, id], + args: [address!, BigInt(id)], watch: true, }); - const stake = format(jurorBalance?.[0]); - const lockedStake = format(jurorBalance?.[1]); + const stake = jurorBalance?.[0] ?? BigInt(0); + const lockedStake = jurorBalance?.[1] ?? BigInt(0); + const formatedStake = formatUnits(stake, 18); + const formatedLockedStake = formatUnits(lockedStake, 18); - return ( - stake !== "0" || - (lockedStake !== "0" && ( - - - - - {`${stake} PNK`} - - - - - - {`${lockedStake} PNK`} - - - )) - ); + return stake > 0 || lockedStake > 0 ? ( + + + + + {`${formatedStake} PNK`} + + + + + + {`${formatedLockedStake} PNK`} + + + ) : null; }; export default CourtCard; diff --git a/web/src/pages/Dashboard/Courts/index.tsx b/web/src/pages/Dashboard/Courts/index.tsx index 2c222b483..f82427133 100644 --- a/web/src/pages/Dashboard/Courts/index.tsx +++ b/web/src/pages/Dashboard/Courts/index.tsx @@ -1,9 +1,10 @@ import React from "react"; import styled from "styled-components"; import { useAccount } from "wagmi"; +import { useFragment as getFragment } from "src/graphql"; +import { useUserQuery, userFragment } from "queries/useUser"; import { isUndefined } from "utils/index"; import CourtCard from "./CourtCard"; -import { useUserQuery } from "queries/useUser"; const Container = styled.div` margin-top: 64px; @@ -22,21 +23,21 @@ const CourtsContainer = styled.div` const Courts: React.FC = () => { const { address } = useAccount(); - const { data } = useUserQuery(address?.toLowerCase()); + const { data } = useUserQuery(address?.toLowerCase() as `0x${string}`); + const user = getFragment(userFragment, data?.user); return ( - <> - -

My Courts

- {!isUndefined(data) &&
} - - {!isUndefined(data) && - data.user?.tokens?.map(({ court: { id, name } }) => { + +

My Courts

+ {!isUndefined(data) ?
: null} + + {!isUndefined(data) + ? user?.tokens?.map(({ court: { id, name } }) => { return ; - })} - -
- + }) + : null} +
+
); };