diff --git a/web/.env.devnet-neo.public b/web/.env.devnet-neo.public index c1a2d7d2d..0883348ef 100644 --- a/web/.env.devnet-neo.public +++ b/web/.env.devnet-neo.public @@ -3,7 +3,6 @@ export REACT_APP_DEPLOYMENT=devnet export REACT_APP_CORE_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-coreneo-devnet/version/latest export REACT_APP_DRT_ARBSEPOLIA_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-drt-arbisep-devnet/version/latest export REACT_APP_STATUS_URL=https://kleros-v2-devnet.betteruptime.com/badge -export REACT_APP_GENESIS_BLOCK_ARBSEPOLIA=3084598 export REACT_APP_DEVTOOLS_URL=https://dev--kleros-v2-neo-devtools.netlify.app export REACT_APP_ARBITRATOR_TYPE=neo export REACT_APP_ATLAS_URI=http://localhost:3000 diff --git a/web/.env.devnet-university.public b/web/.env.devnet-university.public index 2e65b57cd..f1cf57f76 100644 --- a/web/.env.devnet-university.public +++ b/web/.env.devnet-university.public @@ -3,7 +3,6 @@ export REACT_APP_DEPLOYMENT=devnet export REACT_APP_CORE_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-coreuni-devnet/version/latest export REACT_APP_DRT_ARBSEPOLIA_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-drt-arbisep-devnet/version/latest export REACT_APP_STATUS_URL=https://kleros-v2-devnet.betteruptime.com/badge -export REACT_APP_GENESIS_BLOCK_ARBSEPOLIA=3084598 export REACT_APP_ARBITRATOR_TYPE=university export REACT_APP_ATLAS_URI=http://localhost:3000 export WALLETCONNECT_PROJECT_ID= diff --git a/web/.env.devnet.public b/web/.env.devnet.public index 14a2be637..15cb7c81b 100644 --- a/web/.env.devnet.public +++ b/web/.env.devnet.public @@ -3,7 +3,6 @@ export REACT_APP_DEPLOYMENT=devnet export REACT_APP_CORE_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-core-devnet/version/latest export REACT_APP_DRT_ARBSEPOLIA_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-drt-arbisep-devnet/version/latest export REACT_APP_STATUS_URL=https://kleros-v2-devnet.betteruptime.com/badge -export REACT_APP_GENESIS_BLOCK_ARBSEPOLIA=3084598 export REACT_APP_ATLAS_URI=http://localhost:3000 export REACT_APP_DEVTOOLS_URL=https://dev--kleros-v2-testnet-devtools.netlify.app export NODE_OPTIONS='--max-old-space-size=7680' diff --git a/web/.env.mainnet-neo.public b/web/.env.mainnet-neo.public index de5c58216..a2aa0f93f 100644 --- a/web/.env.mainnet-neo.public +++ b/web/.env.mainnet-neo.public @@ -3,7 +3,6 @@ export REACT_APP_DEPLOYMENT=mainnet export REACT_APP_CORE_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-coreneo/version/latest export REACT_APP_DRT_ARBMAINNET_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-drt/version/latest export REACT_APP_STATUS_URL=https://kleros-v2-devnet.betteruptime.com/badge -export REACT_APP_GENESIS_BLOCK_ARBMAINNET=190274403 export REACT_APP_DEVTOOLS_URL=https://devtools.v2.kleros.builders export REACT_APP_ARBITRATOR_TYPE=neo export REACT_APP_ATLAS_URI=http://localhost:3000 diff --git a/web/.env.testnet.public b/web/.env.testnet.public index e91ba5ea6..96e7381ec 100644 --- a/web/.env.testnet.public +++ b/web/.env.testnet.public @@ -4,7 +4,6 @@ export REACT_APP_CORE_SUBGRAPH=https://api.studio.thegraph.com/query/61738/klero export REACT_APP_DRT_ARBSEPOLIA_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-drt-arbisep-devnet/version/latest export REACT_APP_STATUS_URL=https://kleros-v2.betteruptime.com/badge export REACT_APP_ATLAS_URI=http://localhost:3000 -export REACT_APP_GENESIS_BLOCK_ARBSEPOLIA=3842783 export REACT_APP_DEVTOOLS_URL=https://devtools.v2-testnet.kleros.builders export WALLETCONNECT_PROJECT_ID= export ALCHEMY_API_KEY= diff --git a/web/package.json b/web/package.json index 3da8825dc..cd93ab570 100644 --- a/web/package.json +++ b/web/package.json @@ -75,6 +75,7 @@ "dependencies": { "@cyntler/react-doc-viewer": "^1.16.3", "@kleros/kleros-sdk": "workspace:^", + "@kleros/kleros-v2-contracts": "workspace:^", "@kleros/ui-components-library": "^2.15.0", "@lifi/wallet-management": "^3.0.3", "@lifi/widget": "^3.2.0", diff --git a/web/src/consts/index.ts b/web/src/consts/index.ts index 0afe42514..9592cedac 100644 --- a/web/src/consts/index.ts +++ b/web/src/consts/index.ts @@ -28,6 +28,7 @@ export const ETH_ADDRESS_REGEX = /^0x[a-fA-F0-9]{40}$/; export const ETH_SIGNATURE_REGEX = /^0x[a-fA-F0-9]{130}$/; export const isProductionDeployment = () => import.meta.env.REACT_APP_DEPLOYMENT === "mainnet"; +export const isTestnetDeployment = () => import.meta.env.REACT_APP_DEPLOYMENT === "testnet"; export const isKlerosUniversity = () => getArbitratorType() === ArbitratorTypes.university; export const isKlerosNeo = () => getArbitratorType() === ArbitratorTypes.neo; @@ -36,10 +37,6 @@ export const getArbitratorType = (): ArbitratorTypes => export const getDevToolsUrl = () => import.meta.env.REACT_APP_DEVTOOLS_URL || "https://devtools.v2.kleros.builders"; -export const GENESIS_BLOCK_ARBSEPOLIA = BigInt(import.meta.env.REACT_APP_GENESIS_BLOCK_ARBSEPOLIA ?? 0); -export const GENESIS_BLOCK_ARBMAINNET = BigInt(import.meta.env.REACT_APP_GENESIS_BLOCK_ARBMAINNET ?? 0); -export const genesisBlock = () => (isProductionDeployment() ? GENESIS_BLOCK_ARBMAINNET : GENESIS_BLOCK_ARBSEPOLIA); - export const INVALID_DISPUTE_DATA_ERROR = `The dispute data is not valid, please vote "Refuse to arbitrate"`; export const RPC_ERROR = `RPC Error: Unable to fetch dispute data. Please avoid voting.`; diff --git a/web/src/consts/processEnvConsts.ts b/web/src/consts/processEnvConsts.ts index b4a119b88..8de7b7fc9 100644 --- a/web/src/consts/processEnvConsts.ts +++ b/web/src/consts/processEnvConsts.ts @@ -26,10 +26,6 @@ export const isKlerosNeo = () => getArbitratorType() === ArbitratorTypes.neo; export const getArbitratorType = (): ArbitratorTypes => _getArbitratorType(process.env.REACT_APP_ARBITRATOR_TYPE?.toLowerCase()); -export const GENESIS_BLOCK_ARBSEPOLIA = BigInt(process.env.REACT_APP_GENESIS_BLOCK_ARBSEPOLIA ?? 0); -export const GENESIS_BLOCK_ARBMAINNET = BigInt(process.env.REACT_APP_GENESIS_BLOCK_ARBMAINNET ?? 0); -export const genesisBlock = () => (isProductionDeployment() ? GENESIS_BLOCK_ARBMAINNET : GENESIS_BLOCK_ARBSEPOLIA); - export const INVALID_DISPUTE_DATA_ERROR = `The dispute data is not valid, please vote "Refuse to arbitrate"`; export const RPC_ERROR = `RPC Error: Unable to fetch dispute data. Please avoid voting.`; diff --git a/web/src/hooks/queries/useHomePageBlockQuery.ts b/web/src/hooks/queries/useHomePageBlockQuery.ts index 33bb47ffe..0e66b195e 100644 --- a/web/src/hooks/queries/useHomePageBlockQuery.ts +++ b/web/src/hooks/queries/useHomePageBlockQuery.ts @@ -5,6 +5,7 @@ import { isUndefined } from "utils/index"; import { graphql } from "src/graphql"; import { HomePageBlockQuery } from "src/graphql/graphql"; +import useGenesisBlock from "../useGenesisBlock"; export type { HomePageBlockQuery }; const homePageBlockQuery = graphql(` @@ -58,7 +59,8 @@ export type HomePageBlockStats = { }; export const useHomePageBlockQuery = (blockNumber: number | undefined, allTime: boolean) => { - const isEnabled = !isUndefined(blockNumber) || allTime; + const genesisBlock = useGenesisBlock(); + const isEnabled = !isUndefined(blockNumber) || allTime || !isUndefined(genesisBlock); const { graphqlBatcher } = useGraphqlBatcher(); return useQuery({ @@ -66,10 +68,11 @@ export const useHomePageBlockQuery = (blockNumber: number | undefined, allTime: enabled: isEnabled, staleTime: Infinity, queryFn: async () => { + const targetBlock = Math.max(blockNumber!, genesisBlock!); const data = await graphqlBatcher.fetch({ id: crypto.randomUUID(), document: homePageBlockQuery, - variables: { blockNumber }, + variables: { blockNumber: targetBlock }, }); return processData(data, allTime); diff --git a/web/src/hooks/useGenesisBlock.ts b/web/src/hooks/useGenesisBlock.ts new file mode 100644 index 000000000..1041391fd --- /dev/null +++ b/web/src/hooks/useGenesisBlock.ts @@ -0,0 +1,32 @@ +import { useEffect, useState } from "react"; +import { isKlerosNeo, isKlerosUniversity, isTestnetDeployment } from "~src/consts"; + +/** + * @returns genesis block for kleros core contract + */ +const useGenesisBlock = () => { + const [genesisBlock, setGenesisBlock] = useState(); + useEffect(() => { + if (isKlerosUniversity()) { + import("@kleros/kleros-v2-contracts/deployments/arbitrumSepoliaDevnet/KlerosCoreUniversity.json").then((json) => + setGenesisBlock(json.receipt.blockNumber) + ); + } else if (isKlerosNeo()) { + import("@kleros/kleros-v2-contracts/deployments/arbitrum/KlerosCoreNeo.json").then((json) => + setGenesisBlock(json.receipt.blockNumber) + ); + } else if (isTestnetDeployment()) { + import("@kleros/kleros-v2-contracts/deployments/arbitrumSepolia/KlerosCore.json").then((json) => + setGenesisBlock(json.receipt.blockNumber) + ); + } else { + import("@kleros/kleros-v2-contracts/deployments/arbitrumSepoliaDevnet/KlerosCore.json").then((json) => + setGenesisBlock(json.receipt.blockNumber) + ); + } + }, []); + + return genesisBlock; +}; + +export default useGenesisBlock; diff --git a/yarn.lock b/yarn.lock index 6425ed733..1f8f21ec7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6553,7 +6553,7 @@ __metadata: languageName: unknown linkType: soft -"@kleros/kleros-v2-contracts@workspace:contracts": +"@kleros/kleros-v2-contracts@workspace:^, @kleros/kleros-v2-contracts@workspace:contracts": version: 0.0.0-use.local resolution: "@kleros/kleros-v2-contracts@workspace:contracts" dependencies: @@ -6707,6 +6707,7 @@ __metadata: "@graphql-codegen/cli": "npm:^4.0.1" "@graphql-codegen/client-preset": "npm:^4.2.0" "@kleros/kleros-sdk": "workspace:^" + "@kleros/kleros-v2-contracts": "workspace:^" "@kleros/kleros-v2-eslint-config": "workspace:^" "@kleros/kleros-v2-prettier-config": "workspace:^" "@kleros/kleros-v2-tsconfig": "workspace:^"