Skip to content

Commit 206efad

Browse files
committed
fix(web): stake-simulator
1 parent 54bcb9f commit 206efad

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"dependencies": {
7676
"@cyntler/react-doc-viewer": "^1.16.3",
7777
"@kleros/kleros-sdk": "workspace:^",
78+
"@kleros/kleros-v2-contracts": "workspace:^",
7879
"@kleros/ui-components-library": "^2.15.0",
7980
"@lifi/wallet-management": "^3.0.3",
8081
"@lifi/widget": "^3.2.0",

web/src/consts/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const ETH_ADDRESS_REGEX = /^0x[a-fA-F0-9]{40}$/;
2828
export const ETH_SIGNATURE_REGEX = /^0x[a-fA-F0-9]{130}$/;
2929

3030
export const isProductionDeployment = () => import.meta.env.REACT_APP_DEPLOYMENT === "mainnet";
31+
export const isTestnetDeployment = () => import.meta.env.REACT_APP_DEPLOYMENT === "testnet";
3132

3233
export const isKlerosUniversity = () => getArbitratorType() === ArbitratorTypes.university;
3334
export const isKlerosNeo = () => getArbitratorType() === ArbitratorTypes.neo;

web/src/hooks/queries/useHomePageBlockQuery.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { isUndefined } from "utils/index";
55

66
import { graphql } from "src/graphql";
77
import { HomePageBlockQuery } from "src/graphql/graphql";
8+
import useGenesisBlock from "../useGenesisBlock";
89
export type { HomePageBlockQuery };
910

1011
const homePageBlockQuery = graphql(`
@@ -58,18 +59,20 @@ export type HomePageBlockStats = {
5859
};
5960

6061
export const useHomePageBlockQuery = (blockNumber: number | undefined, allTime: boolean) => {
61-
const isEnabled = !isUndefined(blockNumber) || allTime;
62+
const genesisBlock = useGenesisBlock();
63+
const isEnabled = !isUndefined(blockNumber) || allTime || !isUndefined(genesisBlock);
6264
const { graphqlBatcher } = useGraphqlBatcher();
6365

6466
return useQuery<HomePageBlockStats>({
6567
queryKey: [`homePageBlockQuery${blockNumber}-${allTime}`],
6668
enabled: isEnabled,
6769
staleTime: Infinity,
6870
queryFn: async () => {
71+
const targetBlock = Math.max(blockNumber!, genesisBlock!);
6972
const data = await graphqlBatcher.fetch({
7073
id: crypto.randomUUID(),
7174
document: homePageBlockQuery,
72-
variables: { blockNumber },
75+
variables: { blockNumber: targetBlock },
7376
});
7477

7578
return processData(data, allTime);

web/src/hooks/useGenesisBlock.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { useEffect, useState } from "react";
2+
import { isKlerosNeo, isKlerosUniversity, isTestnetDeployment } from "~src/consts";
3+
4+
/**
5+
* @returns genesis block for kleros core contract
6+
*/
7+
const useGenesisBlock = () => {
8+
const [genesisBlock, setGenesisBlock] = useState<number>();
9+
useEffect(() => {
10+
if (isKlerosUniversity()) {
11+
import("@kleros/kleros-v2-contracts/deployments/arbitrumSepoliaDevnet/KlerosCoreUniversity.json").then((json) =>
12+
setGenesisBlock(json.receipt.blockNumber)
13+
);
14+
}
15+
16+
if (isKlerosNeo()) {
17+
import("@kleros/kleros-v2-contracts/deployments/arbitrum/KlerosCoreNeo.json").then((json) =>
18+
setGenesisBlock(json.receipt.blockNumber)
19+
);
20+
}
21+
22+
if (isTestnetDeployment()) {
23+
import("@kleros/kleros-v2-contracts/deployments/arbitrumSepolia/KlerosCore.json").then((json) =>
24+
setGenesisBlock(json.receipt.blockNumber)
25+
);
26+
} else {
27+
import("@kleros/kleros-v2-contracts/deployments/arbitrumSepoliaDevnet/KlerosCore.json").then((json) =>
28+
setGenesisBlock(json.receipt.blockNumber)
29+
);
30+
}
31+
}, []);
32+
33+
return genesisBlock;
34+
};
35+
36+
export default useGenesisBlock;

0 commit comments

Comments
 (0)