Skip to content

Commit a596f10

Browse files
authored
Merge pull request #72 from kleros/chore/migrate-to-reown
chore(web): migrate-to-reown
2 parents 5c075eb + d265744 commit a596f10

File tree

4 files changed

+565
-273
lines changed

4 files changed

+565
-273
lines changed

web/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,12 @@
7272
"@kleros/curate-v2-templates": "workspace:^",
7373
"@kleros/kleros-app": "^2.0.2",
7474
"@kleros/ui-components-library": "^2.20.0",
75+
"@reown/appkit": "^1.6.6",
76+
"@reown/appkit-adapter-wagmi": "^1.6.6",
7577
"@sentry/react": "^7.93.0",
7678
"@sentry/tracing": "^7.93.0",
77-
"@tanstack/react-query": "^5.59.20",
79+
"@tanstack/react-query": "^5.66.0",
7880
"@web3modal/ethereum": "^2.7.1",
79-
"@web3modal/react": "^2.2.2",
8081
"@web3modal/wagmi": "^5.1.6",
8182
"@yornaath/batshit": "^0.9.0",
8283
"chart.js": "^3.9.1",
@@ -105,7 +106,7 @@
105106
"react-use": "^17.4.3",
106107
"styled-components": "^5.3.11",
107108
"subgraph-status": "^1.2.3",
108-
"viem": "^2.21.51",
109-
"wagmi": "^2.13.0"
109+
"viem": "^2.22.22",
110+
"wagmi": "^2.14.10"
110111
}
111112
}

web/src/components/ConnectWallet/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useAccount, useSwitchChain } from "wagmi";
33
import { Button } from "@kleros/ui-components-library";
44
import { SUPPORTED_CHAINS, DEFAULT_CHAIN } from "consts/chains";
55
import AccountDisplay from "./AccountDisplay";
6-
import { useWeb3Modal, useWeb3ModalState } from "@web3modal/wagmi/react";
6+
import { useAppKit, useAppKitState } from "@reown/appkit/react";
77

88
export const SwitchChainButton: React.FC = () => {
99
const { switchChain, isLoading } = useSwitchChain();
@@ -30,8 +30,8 @@ export const SwitchChainButton: React.FC = () => {
3030
};
3131

3232
const ConnectButton: React.FC<{ className?: string }> = ({ className }) => {
33-
const { open } = useWeb3Modal();
34-
const { open: isOpen } = useWeb3ModalState();
33+
const { open } = useAppKit();
34+
const { open: isOpen } = useAppKitState();
3535
return (
3636
<Button
3737
{...{ className }}

web/src/context/Web3Provider.tsx

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import React from "react";
22

3-
import { createWeb3Modal } from "@web3modal/wagmi/react";
4-
import { type Chain } from "viem";
5-
import { createConfig, fallback, http, WagmiProvider, webSocket } from "wagmi";
6-
import { mainnet, arbitrumSepolia, arbitrum, sepolia } from "wagmi/chains";
7-
import { walletConnect } from "wagmi/connectors";
8-
3+
import { fallback, http, WagmiProvider, webSocket } from "wagmi";
4+
import { mainnet, arbitrumSepolia, arbitrum, sepolia, type AppKitNetwork } from "@reown/appkit/networks";
5+
import { createAppKit } from "@reown/appkit/react";
6+
import { WagmiAdapter } from "@reown/appkit-adapter-wagmi";
97
import { ALL_CHAINS, DEFAULT_CHAIN } from "consts/chains";
108
import { isProductionDeployment } from "consts/index";
119

@@ -25,10 +23,10 @@ const alchemyToViemChain = {
2523
type AlchemyProtocol = "https" | "wss";
2624

2725
// https://github.com/alchemyplatform/alchemy-sdk-js/blob/96b3f62/src/util/const.ts#L16-L18
28-
const alchemyURL = (protocol: AlchemyProtocol, chainId: number) =>
26+
const alchemyURL = (protocol: AlchemyProtocol, chainId: number | string) =>
2927
`${protocol}://${alchemyToViemChain[chainId]}.g.alchemy.com/v2/${alchemyApiKey}`;
3028

31-
export const getChainRpcUrl = (protocol: AlchemyProtocol, chainId: number) => {
29+
export const getChainRpcUrl = (protocol: AlchemyProtocol, chainId: number | string) => {
3230
return alchemyURL(protocol, chainId);
3331
};
3432

@@ -37,7 +35,7 @@ export const getDefaultChainRpcUrl = (protocol: AlchemyProtocol) => {
3735
};
3836

3937
export const getTransports = () => {
40-
const alchemyTransport = (chain: Chain) =>
38+
const alchemyTransport = (chain: AppKitNetwork) =>
4139
fallback([http(alchemyURL("https", chain.id)), webSocket(alchemyURL("wss", chain.id))]);
4240

4341
return {
@@ -48,28 +46,29 @@ export const getTransports = () => {
4846
};
4947
};
5048

51-
const chains = ALL_CHAINS as [Chain, ...Chain[]];
49+
const chains = ALL_CHAINS as [AppKitNetwork, ...AppKitNetwork[]];
5250
const transports = getTransports();
5351
const projectId = import.meta.env.WALLETCONNECT_PROJECT_ID ?? "";
54-
55-
const wagmiConfig = createConfig({
56-
chains,
52+
const wagmiAdapter = new WagmiAdapter({
53+
networks: chains,
54+
projectId,
5755
transports,
58-
connectors: [walletConnect({ projectId, showQrModal: false })],
5956
});
6057

61-
createWeb3Modal({
62-
wagmiConfig,
58+
createAppKit({
59+
adapters: [wagmiAdapter],
60+
networks: chains,
61+
defaultNetwork: isProduction ? arbitrum : arbitrumSepolia,
6362
projectId,
64-
defaultChain: isProductionDeployment() ? arbitrum : arbitrumSepolia,
6563
themeVariables: {
6664
"--w3m-color-mix": lightTheme.primaryPurple,
6765
"--w3m-color-mix-strength": 20,
66+
// overlay portal is at 9999
67+
"--w3m-z-index": 10000,
6868
},
6969
});
70-
7170
const Web3Provider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
72-
return <WagmiProvider config={wagmiConfig}> {children} </WagmiProvider>;
71+
return <WagmiProvider config={wagmiAdapter.wagmiConfig}> {children} </WagmiProvider>;
7372
};
7473

7574
export default Web3Provider;

0 commit comments

Comments
 (0)