Skip to content

Commit c1c2f97

Browse files
authored
Merge branch 'dev' into feat(web)/top-jurors-component
2 parents 0f80e6c + a5aa14c commit c1c2f97

File tree

9 files changed

+58
-47
lines changed

9 files changed

+58
-47
lines changed

.github/workflows/deploy-subgraph.yml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
default: 'arbitrum-goerli'
1010
type: choice
1111
options:
12+
- arbitrum-goerli-devnet
1213
- arbitrum-goerli
1314
- arbitrum
1415
update:

subgraph/schema.graphql

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ interface DisputeKitDispute {
1919
coreDispute: Dispute!
2020
localRounds: [DisputeKitRound!]! @derivedFrom(field: "localDispute")
2121
currentLocalRoundIndex: BigInt!
22+
timestamp: BigInt!
2223
}
2324

2425
interface DisputeKitRound {
@@ -237,6 +238,7 @@ type ClassicDispute implements DisputeKitDispute @entity {
237238
coreDispute: Dispute!
238239
localRounds: [DisputeKitRound!]! @derivedFrom(field: "localDispute")
239240
currentLocalRoundIndex: BigInt!
241+
timestamp: BigInt!
240242

241243
numberOfChoices: BigInt!
242244
extraData: Bytes!

subgraph/src/entities/ClassicDispute.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ export function createClassicDisputeFromEvent(event: DisputeCreation): void {
99
classicDispute.currentLocalRoundIndex = ZERO;
1010
classicDispute.numberOfChoices = event.params._numberOfChoices;
1111
classicDispute.extraData = event.params._extraData;
12+
classicDispute.timestamp = event.block.timestamp;
1213
classicDispute.save();
1314
}

web/src/components/Popup/Description/StakeWithdraw.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from "react";
22
import styled from "styled-components";
3-
import { isUndefined } from "utils/index";
3+
import { formatUnits } from "viem";
44
import { useAccount } from "wagmi";
5+
import { isUndefined } from "utils/index";
56
import { useKlerosCoreGetJurorBalance } from "hooks/contracts/generated";
6-
import { format } from "src/pages/Dashboard/Courts/CourtCard";
77
import KlerosLogo from "tsx:svgs/icons/kleros.svg";
88

99
const Container = styled.div`
@@ -88,7 +88,7 @@ const StakeWithdraw: React.FC<IStakeWithdraw> = ({ pnkStaked, courtName, isStake
8888

8989
<TotalStakeContainer>
9090
<StyledKlerosLogo /> <MyStakeContainer>My Stake:</MyStakeContainer>{" "}
91-
<AmountContainer>{`${format(jurorBalance?.[0])} PNK`} </AmountContainer>
91+
<AmountContainer>{`${formatUnits(jurorBalance?.[0] ?? BigInt(0), 18)} PNK`} </AmountContainer>
9292
</TotalStakeContainer>
9393
</Container>
9494
);

web/src/hooks/queries/useClassicAppealQuery.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { graphqlQueryFnHelper } from "utils/graphqlQueryFnHelper";
55
export type { ClassicAppealQuery };
66

77
const classicAppealQuery = graphql(`
8-
query ClassicAppeal($disputeID: ID!) {
8+
query ClassicAppeal($disputeID: ID!, $orderBy: DisputeKitDispute_orderBy, $orderDirection: OrderDirection) {
99
dispute(id: $disputeID) {
1010
period
1111
court {
@@ -16,7 +16,7 @@ const classicAppealQuery = graphql(`
1616
id
1717
}
1818
lastPeriodChange
19-
disputeKitDispute {
19+
disputeKitDispute(orderBy: $orderBy, orderDirection: $orderDirection) {
2020
id
2121
currentLocalRoundIndex
2222
localRounds {
@@ -37,6 +37,13 @@ export const useClassicAppealQuery = (id?: string | number) => {
3737
return useQuery<ClassicAppealQuery>({
3838
queryKey: ["refetchOnBlock", `classicAppealQuery${id}`],
3939
enabled: isEnabled,
40-
queryFn: async () => await graphqlQueryFnHelper(classicAppealQuery, { disputeID: id?.toString() }),
40+
queryFn: async () =>
41+
isEnabled
42+
? await graphqlQueryFnHelper(classicAppealQuery, {
43+
disputeID: id?.toString(),
44+
orderBy: "timestamp",
45+
orderDirection: "asc",
46+
})
47+
: undefined,
4148
});
4249
};

web/src/hooks/useClassicAppealContext.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ const getCurrentLocalRound = (dispute?: ClassicAppealQuery["dispute"]) => {
102102
if (!dispute) return undefined;
103103

104104
const period = dispute.period;
105-
const currentLocalRoundIndex = dispute.disputeKitDispute?.currentLocalRoundIndex;
105+
const currentLocalRoundIndex = dispute.disputeKitDispute.at(-1)?.currentLocalRoundIndex;
106106
const adjustedRoundIndex = ["appeal", "execution"].includes(period)
107107
? currentLocalRoundIndex
108108
: currentLocalRoundIndex - 1;

web/src/pages/Cases/CaseDetails/Appeal/Classic/Options/StageOne.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
useOptionsContext,
99
useSelectedOptionContext,
1010
} from "hooks/useClassicAppealContext";
11+
import { isUndefined } from "utils/index";
1112
import { formatUnitsWei } from "utils/format";
1213

1314
const Container = styled.div`
@@ -30,14 +31,15 @@ const StageOne: React.FC<IStageOne> = ({ setAmount }) => {
3031
const options = useOptionsContext();
3132
const loserSideCountdown = useLoserSideCountdownContext();
3233
const { selectedOption, setSelectedOption } = useSelectedOptionContext();
34+
3335
return (
3436
<Container>
3537
<StageExplainer {...{ loserSideCountdown }} />
3638
<label> Which option do you want to fund? </label>
3739
<OptionsContainer>
38-
{typeof paidFees !== "undefined" &&
39-
typeof winnerRequiredFunding !== "undefined" &&
40-
typeof loserRequiredFunding !== "undefined" &&
40+
{!isUndefined(paidFees) &&
41+
!isUndefined(winnerRequiredFunding) &&
42+
!isUndefined(loserRequiredFunding) &&
4143
options?.map((answer: string, i: number) => {
4244
const requiredFunding = i.toString() === winningChoice ? winnerRequiredFunding : loserRequiredFunding;
4345
return (

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

+21-24
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

+14-13
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,21 @@ 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);
2628

2729
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 } }) => {
30+
<Container>
31+
<h1> My Courts </h1>
32+
{!isUndefined(data) ? <hr /> : null}
33+
<CourtsContainer>
34+
{!isUndefined(data)
35+
? user?.tokens?.map(({ court: { id, name } }) => {
3536
return <CourtCard key={id} id={id} name={name ?? ""} />;
36-
})}
37-
</CourtsContainer>
38-
</Container>
39-
</>
37+
})
38+
: null}
39+
</CourtsContainer>
40+
</Container>
4041
);
4142
};
4243

0 commit comments

Comments
 (0)