Skip to content

Commit 5acd04a

Browse files
authored
Merge pull request #949 from kleros/refactor(web)/delete-web3-react-files
Refactor(web)/delete web3 react files
2 parents 8e53da5 + 0d717b6 commit 5acd04a

File tree

26 files changed

+305
-485
lines changed

26 files changed

+305
-485
lines changed

web/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@
6565
"@sentry/react": "^7.55.2",
6666
"@sentry/tracing": "^7.55.2",
6767
"@types/react-modal": "^3.16.0",
68-
"@web3-react/core": "^6.1.9",
69-
"@web3-react/injected-connector": "^6.0.7",
70-
"@web3-react/types": "^6.0.7",
7168
"@web3modal/ethereum": "^2.2.2",
7269
"@web3modal/react": "^2.2.2",
7370
"chart.js": "^3.9.1",

web/src/app.tsx

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ import { Routes, Route } from "react-router-dom";
55
import "react-loading-skeleton/dist/skeleton.css";
66
import Web3Provider from "context/Web3Provider";
77
import StyledComponentsProvider from "context/StyledComponentsProvider";
8-
import WrongChainBoundary from "components/WrongChainBoundary";
98
import Layout from "layout/index";
109
import Home from "./pages/Home";
1110
import Cases from "./pages/Cases";
1211
import Dashboard from "./pages/Dashboard";
1312
import Courts from "./pages/Courts";
14-
1513
import "react-toastify/dist/ReactToastify.css";
1614

1715
const fetcherBuilder =
@@ -27,26 +25,20 @@ const App: React.FC = () => {
2725
<SWRConfig
2826
value={{
2927
fetcher: fetcherBuilder(
30-
process.env.REACT_APP_SUBGRAPH_ENDPOINT ??
31-
"https://api.thegraph.com/subgraphs/name/alcercu/kleroscoretest"
28+
process.env.REACT_APP_SUBGRAPH_ENDPOINT ?? "https://api.thegraph.com/subgraphs/name/alcercu/kleroscoretest"
3229
),
3330
}}
3431
>
3532
<Web3Provider>
36-
<WrongChainBoundary>
37-
<Routes>
38-
<Route path="/" element={<Layout />}>
39-
<Route index element={<Home />} />
40-
<Route path="cases/*" element={<Cases />} />
41-
<Route path="courts/*" element={<Courts />} />
42-
<Route path="dashboard" element={<Dashboard />} />
43-
<Route
44-
path="*"
45-
element={<h1>Justice not found here ¯\_( ͡° ͜ʖ ͡°)_/¯</h1>}
46-
/>
47-
</Route>
48-
</Routes>
49-
</WrongChainBoundary>
33+
<Routes>
34+
<Route path="/" element={<Layout />}>
35+
<Route index element={<Home />} />
36+
<Route path="cases/*" element={<Cases />} />
37+
<Route path="courts/*" element={<Courts />} />
38+
<Route path="dashboard" element={<Dashboard />} />
39+
<Route path="*" element={<h1>Justice not found here ¯\_( ͡° ͜ʖ ͡°)_/¯</h1>} />
40+
</Route>
41+
</Routes>
5042
</Web3Provider>
5143
</SWRConfig>
5244
</StyledComponentsProvider>
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,10 @@
11
import React from "react";
22
import styled from "styled-components";
3-
import { useAccount, useNetwork } from "wagmi";
4-
import { arbitrumGoerli } from "wagmi/chains";
3+
import { useAccount, useNetwork, useSwitchNetwork } from "wagmi";
54
import { useWeb3Modal } from "@web3modal/react";
65
import { shortenAddress } from "utils/shortenAddress";
76
import { Button } from "@kleros/ui-components-library";
8-
9-
const AccountDisplay: React.FC = () => {
10-
return (
11-
<StyledContainer>
12-
<ChainDisplay />
13-
<AddressDisplay />
14-
</StyledContainer>
15-
);
16-
};
17-
18-
export const ChainDisplay: React.FC = () => {
19-
const { chain } = useNetwork();
20-
return <small>{chain?.name}</small>;
21-
};
22-
23-
export const AddressDisplay: React.FC = () => {
24-
const { address } = useAccount();
25-
return <label>{address && shortenAddress(address)}</label>;
26-
};
7+
import { SUPPORTED_CHAINS, DEFAULT_CHAIN } from "consts/chains";
278

289
const StyledContainer = styled.div`
2910
width: fit-content;
@@ -46,15 +27,63 @@ const StyledContainer = styled.div`
4627
}
4728
`;
4829

30+
const AccountDisplay: React.FC = () => {
31+
return (
32+
<StyledContainer>
33+
<ChainDisplay />
34+
<AddressDisplay />
35+
</StyledContainer>
36+
);
37+
};
38+
39+
export const ChainDisplay: React.FC = () => {
40+
const { chain } = useNetwork();
41+
return <small>{chain?.name}</small>;
42+
};
43+
44+
export const AddressDisplay: React.FC = () => {
45+
const { address } = useAccount();
46+
return <label>{address && shortenAddress(address)}</label>;
47+
};
48+
49+
export const SwitchChainButton: React.FC = () => {
50+
const { switchNetwork, isLoading } = useSwitchNetwork();
51+
const handleSwitch = () => {
52+
if (!switchNetwork) {
53+
console.error("Cannot switch network. Please do it manually.");
54+
return;
55+
}
56+
try {
57+
switchNetwork(DEFAULT_CHAIN);
58+
} catch (err) {
59+
console.error(err);
60+
}
61+
};
62+
return (
63+
<Button
64+
isLoading={isLoading}
65+
disabled={isLoading}
66+
text={`Switch to ${SUPPORTED_CHAINS[DEFAULT_CHAIN].chainName}`}
67+
onClick={handleSwitch}
68+
/>
69+
);
70+
};
71+
4972
const ConnectButton: React.FC = () => {
50-
const { isConnected } = useAccount();
51-
const { open, setDefaultChain, isOpen } = useWeb3Modal();
52-
setDefaultChain(arbitrumGoerli);
53-
return isConnected ? (
54-
<AccountDisplay />
55-
) : (
73+
const { open, isOpen } = useWeb3Modal();
74+
return (
5675
<Button disabled={isOpen} small text={"Connect"} onClick={async () => await open({ route: "ConnectWallet" })} />
5776
);
5877
};
5978

60-
export default ConnectButton;
79+
const ConnectWallet: React.FC = () => {
80+
const { chain } = useNetwork();
81+
const { isConnected } = useAccount();
82+
if (isConnected) {
83+
if (chain && chain.id !== DEFAULT_CHAIN) {
84+
return <SwitchChainButton />;
85+
} else return <AccountDisplay />;
86+
} else return <ConnectButton />;
87+
};
88+
89+
export default ConnectWallet;

web/src/components/DisputeCard/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ const StyledCard = styled(Card)`
1616
min-width: 312px;
1717
width: auto;
1818
height: 260px;
19+
20+
.react-loading-skeleton {
21+
z-index: 0;
22+
}
1923
`;
2024

2125
const Container = styled.div`

web/src/components/EnsureChain.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from "react";
2+
import { DEFAULT_CHAIN } from "consts/chains";
3+
import { useNetwork } from "wagmi";
4+
import ConnectWallet from "components/ConnectWallet";
5+
6+
interface IEnsureChain {
7+
children: React.ReactElement;
8+
}
9+
10+
export const EnsureChain: React.FC<IEnsureChain> = ({ children }) => {
11+
const { chain } = useNetwork();
12+
13+
return chain && chain.id === DEFAULT_CHAIN ? children : <ConnectWallet />;
14+
};

web/src/components/Overlay.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import styled from "styled-components";
2+
3+
export const Overlay = styled.div`
4+
position: fixed;
5+
top: 0;
6+
left: 0;
7+
width: 100vw;
8+
height: 100vh;
9+
background-color: ${({ theme }) => theme.blackLowOpacity};
10+
z-index: 1;
11+
`;

web/src/components/WrongChainBoundary.tsx

Lines changed: 0 additions & 46 deletions
This file was deleted.

web/src/connectors/injected.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

web/src/hooks/useConnect.ts

Lines changed: 0 additions & 46 deletions
This file was deleted.

web/src/hooks/useWeb3.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)