Skip to content
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
341d0e5
refactor(web/WIP): migrate to wagmi
alcercu Mar 24, 2023
2162e56
feat(wip/web): migrate contract interactions to wagmi
alcercu Mar 30, 2023
d9b299d
feat(wip/web): migrate queries to wagmi
alcercu Mar 31, 2023
7d54418
fix(web): add wagmi cli
alcercu Jun 2, 2023
af72998
feat(web/WIP): migrate hooks to wagmi/viem
alcercu Jun 5, 2023
4142f6d
Merge branch 'dev' into refactor(web)/migrate-to-wagmi
alcercu Jun 8, 2023
84da0e9
refactor: jurorbalance, policyregistry & disputekitclassic hooks
kemuru Jun 8, 2023
0c57e6b
fix: hook import order
kemuru Jun 8, 2023
8833a1e
feat(web): migrate queries to wagmi
alcercu Jun 9, 2023
3f637bb
refactor: migrate hooks to viem/wagmi
nhestrompia Jun 9, 2023
05b01a4
fix: change publicClient provider
nhestrompia Jun 9, 2023
09e8890
fix: provider error
nhestrompia Jun 9, 2023
dd9e0d7
Merge pull request #899 from kleros/migrate-hooks-to-viem
alcercu Jun 9, 2023
2de836f
fix: fix provider
kemuru Jun 9, 2023
07d1138
Merge branch 'refactor(web)/migrate-to-wagmi' into refactor(web)/migr…
alcercu Jun 9, 2023
bce0b8a
Merge pull request #895 from kleros/refactor(web)/migrate-viem-marino…
alcercu Jun 9, 2023
8daa141
Merge branch 'refactor(web)/migrate-to-wagmi' of github.com:kleros/kl…
alcercu Jun 9, 2023
566ad40
Merge branch 'dev' into refactor(web)/migrate-to-wagmi
alcercu Jun 9, 2023
c16be02
refactor: started migration
kemuru Jun 10, 2023
348af60
refactor: migrating from ethers to viem
nhestrompia Jun 12, 2023
e7b15a9
fix: error fixes
nhestrompia Jun 12, 2023
300c2d0
refactor: promise resolve waiting
nhestrompia Jun 12, 2023
2a4838c
feat: submitEvidenceModal migration
nhestrompia Jun 12, 2023
4e40807
fix: fund file error fix
nhestrompia Jun 12, 2023
cd69c43
fix: inputDisplay error fix
nhestrompia Jun 12, 2023
7955e8f
fix: bug fixes
kemuru Jun 12, 2023
42feb59
fix: stakewithdrawbutton type fix
kemuru Jun 12, 2023
4d8a007
fix: sonarcloud error commify.ts
kemuru Jun 12, 2023
b9bde73
refactor: change commify function
kemuru Jun 12, 2023
db0018c
fix: optional chain & duplicate imports code smells
kemuru Jun 12, 2023
c625440
fix: bigint type
nhestrompia Jun 12, 2023
c47ecbd
fix: another bigint notation fix
nhestrompia Jun 12, 2023
9698245
refactor(web): useParsedAmount
alcercu Jun 13, 2023
56bd3a8
chore(web): update es version to es2020
alcercu Jun 13, 2023
61d0000
refactor(web): use numbern syntax
alcercu Jun 13, 2023
87d7c6f
fix: bigint notation
nhestrompia Jun 12, 2023
a2a9294
Merge pull request #912 from kleros/refactor(web)/migrate-files-to-viem
alcercu Jun 13, 2023
ae586e2
Merge branch 'refactor(web)/migrate-to-wagmi' into refactor(web)/ethe…
alcercu Jun 13, 2023
0a53259
refactor: change bigint syntax to n
kemuru Jun 13, 2023
4ceee36
refactor(web): use autogenerated function
alcercu Jun 13, 2023
fdd2630
refactor(web): use autogenerated function to prepare transaction
alcercu Jun 13, 2023
792af5f
refactor(web): remove unused import
alcercu Jun 13, 2023
4f3abc5
fix(web): use ethers commify
alcercu Jun 13, 2023
edc8301
Merge pull request #913 from kleros/refactor(web)/ethers-to-viem-mari…
alcercu Jun 13, 2023
d2801c9
feat: add links to solutions and help
nhestrompia Jun 14, 2023
e1fda64
Merge pull request #915 from kleros/refactor(web)/add-links-solutions…
alcercu Jun 14, 2023
b4b57ac
Merge 'dev' into refactor(web)/migrate-to-wagmi
nhestrompia Jun 16, 2023
235939b
chore: use correct prettier config
alcercu Jun 16, 2023
3953923
fix: revert updates to parcel version as it breaks wagmi
alcercu Jun 16, 2023
3288285
feat: isUndefined returns a type predicate to play nice with typescript
alcercu Jun 16, 2023
4e9e40b
refactor: started assertion refactoring
kemuru Jun 16, 2023
1e03469
fix: code smell
nhestrompia Jun 16, 2023
23ba21b
Merge pull request #948 from kleros/fix(web)/fix-assertions-undefined
alcercu Jun 16, 2023
875d04f
Merge branch 'dev' into refactor(web)/migrate-to-wagmi
jaybuidl Jun 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions contracts/.solhint.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"extends": "solhint:recommended",
"plugins": ["prettier"],
"plugins": [
"prettier"
],
"rules": {
"compiler-version": ["error", "^0.8.0"],
"compiler-version": [
"error",
"^0.8.0"
],
"func-visibility": [
"warn",
{
Expand Down
12 changes: 10 additions & 2 deletions contracts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{
"extends": "@kleros/kleros-v2-tsconfig/base.json",
"include": ["./src", "./scripts", "./test", "./typechain-types", "./deploy"],
"files": ["./hardhat.config.ts"]
"include": [
"./src",
"./scripts",
"./test",
"./typechain-types",
"./deploy"
],
"files": [
"./hardhat.config.ts"
]
}
6 changes: 5 additions & 1 deletion cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
"version": "0.2",
"ignorePaths": [],
"dictionaryDefinitions": [],
"dictionaries": ["en_US", "companies", "softwareTerms"],
"dictionaries": [
"en_US",
"companies",
"softwareTerms"
],
"words": [
"arbitrum",
"commitlint",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"devDependencies": {
"@commitlint/cli": "^17.6.5",
"@commitlint/config-conventional": "^17.6.5",
"buffer": "^5.5.0",
"conventional-changelog-cli": "^2.2.2",
"husky": "^8.0.3",
"lint-staged": "^13.2.2",
Expand Down
4 changes: 3 additions & 1 deletion tsconfig/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@
"resolveJsonModule": true,
"experimentalDecorators": true
},
"exclude": ["node_modules"]
"exclude": [
"node_modules"
]
}
7 changes: 6 additions & 1 deletion tsconfig/react-library.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
"extends": "./base.json",
"compilerOptions": {
"jsx": "react",
"lib": ["es6", "dom", "esnext.asynciterable", "es2017"],
"lib": [
"es6",
"dom",
"esnext.asynciterable",
"es2017"
],
"module": "ESNext",
"target": "es6"
}
Expand Down
2 changes: 1 addition & 1 deletion web/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"max-len": [
"warn",
{
"code": 80
"code": 120
}
],
"react/prop-types": 0,
Expand Down
1 change: 1 addition & 0 deletions web/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ parcel-bundle-reports
.env.development.local
.env.test.local
.env.production.local
src/hooks/contracts/*

npm-debug.log*
yarn-debug.log*
Expand Down
24 changes: 18 additions & 6 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,29 @@
"clean": "rm dist/bundle.js",
"start": "parcel",
"start-local": "REACT_APP_SUBGRAPH_ENDPOINT=http://localhost:8000/subgraphs/name/kleros/kleros-v2-core-local parcel",
"build": "parcel build",
"build": "yarn run generate-hooks && yarn run parcel build",
"check-style": "eslint 'src/**/*.{js,jsx,ts,tsx}'",
"check-types": "tsc --noEmit",
"generate": "graphql-codegen"
"generate-gql": "graphql-codegen",
"generate-hooks": "wagmi generate"
},
"prettier": "@kleros/kleros-v2-prettier-config",
"devDependencies": {
"@kleros/kleros-v2-eslint-config": "workspace:^",
"@kleros/kleros-v2-prettier-config": "workspace:^",
"@kleros/kleros-v2-tsconfig": "workspace:^",
"@netlify/functions": "^1.6.0",
"@parcel/transformer-svg-react": "~2.9.2",
"@parcel/transformer-svg-react": "~2.8.0",
"@parcel/watcher": "~2.1.0",
"@types/react": "^18.2.12",
"@types/react-dom": "^18.2.5",
"@types/styled-components": "^5.1.26",
"@typescript-eslint/eslint-plugin": "^5.58.0",
"@typescript-eslint/parser": "^5.58.0",
"@typescript-eslint/utils": "^5.58.0",
"@wagmi/cli": "^1.1.0",
"eslint": "^8.38.0",
"eslint-config-prettier": "^8.8.0",
"eslint-import-resolver-parcel": "^1.10.6",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
Expand All @@ -60,14 +68,16 @@
"@web3-react/core": "^6.1.9",
"@web3-react/injected-connector": "^6.0.7",
"@web3-react/types": "^6.0.7",
"@web3modal/ethereum": "^2.2.2",
"@web3modal/react": "^2.2.2",
"chart.js": "^3.9.1",
"chartjs-adapter-moment": "^1.0.1",
"core-js": "^3.31.0",
"ethers": "^5.7.2",
"graphql": "^16.6.0",
"graphql-request": "~5.1.0",
"moment": "^2.29.4",
"parcel": "~2.9.2",
"parcel": "~2.8.0",
"react": "^18.2.0",
"react-chartjs-2": "^4.3.1",
"react-dom": "^18.2.0",
Expand All @@ -82,8 +92,10 @@
"react-scripts": "^5.0.1",
"react-toastify": "^9.1.3",
"react-use": "^17.4.0",
"styled-components": "^5.3.11",
"swr": "^1.3.0"
"styled-components": "^5.3.9",
"swr": "^1.3.0",
"viem": "^0.3.48",
"wagmi": "^1.1.0"
},
"volta": {
"node": "16.18.1",
Expand Down
27 changes: 15 additions & 12 deletions web/src/components/ConnectButton.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from "react";
import styled from "styled-components";
import { useAccount, useNetwork } from "wagmi";
import { arbitrumGoerli } from "wagmi/chains";
import { useWeb3Modal } from "@web3modal/react";
import { shortenAddress } from "utils/shortenAddress";
import { Button } from "@kleros/ui-components-library";
import { useWeb3 } from "hooks/useWeb3";
import { useConnect } from "hooks/useConnect";
import { SUPPORTED_CHAINS } from "consts/chains";

const AccountDisplay: React.FC = () => {
return (
Expand All @@ -16,15 +16,13 @@ const AccountDisplay: React.FC = () => {
};

export const ChainDisplay: React.FC = () => {
const { chainId } = useWeb3();
const chainName = chainId ? SUPPORTED_CHAINS[chainId].chainName : undefined;
return <small>{chainName}</small>;
const { chain } = useNetwork();
return <small>{chain?.name}</small>;
};

export const AddressDisplay: React.FC = () => {
const { account } = useWeb3();
const shortAddress = account ? shortenAddress(account) : undefined;
return <label>{shortAddress}</label>;
const { address } = useAccount();
return <label>{address && shortenAddress(address)}</label>;
};

const StyledContainer = styled.div`
Expand All @@ -49,9 +47,14 @@ const StyledContainer = styled.div`
`;

const ConnectButton: React.FC = () => {
const { active } = useWeb3();
const { activate, connecting } = useConnect();
return active ? <AccountDisplay /> : <Button disabled={connecting} small text={"Connect"} onClick={activate} />;
const { isConnected } = useAccount();
const { open, setDefaultChain, isOpen } = useWeb3Modal();
setDefaultChain(arbitrumGoerli);
return isConnected ? (
<AccountDisplay />
) : (
<Button disabled={isOpen} small text={"Connect"} onClick={async () => await open({ route: "ConnectWallet" })} />
);
};

export default ConnectButton;
4 changes: 2 additions & 2 deletions web/src/components/DisputeCard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import styled from "styled-components";
import { useNavigate } from "react-router-dom";
import { utils } from "ethers";
import { formatEther } from "viem";
import Skeleton from "react-loading-skeleton";
import { Card } from "@kleros/ui-components-library";
import { Periods } from "consts/periods";
Expand Down Expand Up @@ -42,7 +42,7 @@ const DisputeCard: React.FC<CasesPageQuery["disputes"][number]> = ({
court,
}) => {
const currentPeriodIndex = Periods[period];
const rewards = `≥ ${utils.formatEther(court.feeForJuror)} ETH`;
const rewards = `≥ ${formatEther(court.feeForJuror)} ETH`;
const date =
currentPeriodIndex === 4
? lastPeriodChange
Expand Down
9 changes: 1 addition & 8 deletions web/src/components/StatDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,7 @@ export interface IStatDisplay {
color: "red" | "orange" | "green" | "blue" | "purple";
}

const StatDisplay: React.FC<IStatDisplay> = ({
title,
text,
subtext,
icon: Icon,
color,
...props
}) => {
const StatDisplay: React.FC<IStatDisplay> = ({ title, text, subtext, icon: Icon, color, ...props }) => {
const theme = useTheme();
const COLORS = {
red: createPair(theme.error, theme.errorLight),
Expand Down
4 changes: 1 addition & 3 deletions web/src/consts/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
import { BigNumber } from "ethers";

export const ONE_BASIS_POINT = BigNumber.from("10000");
export const ONE_BASIS_POINT = 10000n;
38 changes: 26 additions & 12 deletions web/src/context/Web3Provider.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
import React from "react";
import { Web3ReactProvider } from "@web3-react/core";
import {
Web3Provider as EthersProvider,
ExternalProvider,
} from "@ethersproject/providers";

const getLibrary = (provider: ExternalProvider): EthersProvider =>
new EthersProvider(provider);

const Web3Provider: React.FC<{ children: React.ReactNode }> = ({
children,
}) => <Web3ReactProvider {...{ getLibrary }}> {children} </Web3ReactProvider>;
import { EthereumClient, w3mConnectors } from "@web3modal/ethereum";
import { alchemyProvider } from "@wagmi/core/providers/alchemy";
import { Web3Modal } from "@web3modal/react";
import { configureChains, createConfig, WagmiConfig } from "wagmi";
import { arbitrumGoerli, gnosisChiado } from "wagmi/chains";
import { publicProvider } from "wagmi/providers/public";

const chains = [arbitrumGoerli, gnosisChiado];
const projectId = "6efaa26765fa742153baf9281e218217";

const { publicClient } = configureChains(chains, [alchemyProvider({ apiKey: "" }), publicProvider()]);

const wagmiConfig = createConfig({
autoConnect: false,
connectors: w3mConnectors({ projectId, version: 1, chains }),
publicClient,
});

const ethereumClient = new EthereumClient(wagmiConfig, chains);

const Web3Provider: React.FC<{ children: React.ReactNode }> = ({ children }) => (
<>
<WagmiConfig config={wagmiConfig}> {children} </WagmiConfig>
<Web3Modal {...{ projectId, ethereumClient }} />
</>
);

export default Web3Provider;
10 changes: 5 additions & 5 deletions web/src/hooks/queries/useAppealCost.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import useSWRImmutable from "swr/immutable";
import { useConnectedContract } from "hooks/useConnectedContract";
import { getKlerosCore } from "hooks/contracts/generated";

export const useAppealCost = (disputeID?: string) => {
const KlerosCore = useConnectedContract("KlerosCore");
const klerosCore = getKlerosCore({});
return useSWRImmutable(
() => (KlerosCore ? `AppealCost${disputeID}` : false),
() => (klerosCore && disputeID ? `AppealCost${disputeID}` : false),
async () => {
if (!KlerosCore) return;
return KlerosCore.appealCost(disputeID);
if (!klerosCore || typeof disputeID === "undefined") return;
return await klerosCore.read.appealCost([BigInt(disputeID)]);
}
);
};
17 changes: 8 additions & 9 deletions web/src/hooks/queries/useDisputeKitClassicMultipliers.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import useSWRImmutable from "swr/immutable";
import { BigNumber } from "ethers";
import { useConnectedContract } from "hooks/useConnectedContract";
import { getDisputeKitClassic } from "hooks/contracts/generated";

export const useDisputeKitClassicMultipliers = () => {
const disputeKitClassic = useConnectedContract("DisputeKitClassic");
const disputeKitClassic = getDisputeKitClassic({});
return useSWRImmutable(
() => (disputeKitClassic ? `Multipliers` : false),
async () => {
if (!disputeKitClassic) return;
const winner_stake_multiplier = await disputeKitClassic.WINNER_STAKE_MULTIPLIER();
const loser_stake_multiplier = await disputeKitClassic.LOSER_STAKE_MULTIPLIER();
const loser_appeal_period_multiplier = await disputeKitClassic.LOSER_APPEAL_PERIOD_MULTIPLIER();
const winner_stake_multiplier = await disputeKitClassic.read.WINNER_STAKE_MULTIPLIER();
const loser_stake_multiplier = await disputeKitClassic.read.LOSER_STAKE_MULTIPLIER();
const loser_appeal_period_multiplier = await disputeKitClassic.read.LOSER_APPEAL_PERIOD_MULTIPLIER();
return {
winner_stake_multiplier,
loser_stake_multiplier,
Expand All @@ -21,7 +20,7 @@ export const useDisputeKitClassicMultipliers = () => {
};

export interface IDisputeKitClassicMultipliers {
winner_stake_multiplier: BigNumber;
loser_stake_multiplier: BigNumber;
loser_appeal_period_multiplier: BigNumber;
winner_stake_multiplier: bigint;
loser_stake_multiplier: bigint;
loser_appeal_period_multiplier: bigint;
}
17 changes: 0 additions & 17 deletions web/src/hooks/queries/useETHBalance.ts

This file was deleted.

Loading