Skip to content

Commit 3ce6bd2

Browse files
chore(web): migrate-to-reown
1 parent 227337b commit 3ce6bd2

File tree

7 files changed

+826
-470
lines changed

7 files changed

+826
-470
lines changed

web/package.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,25 @@
7979
"vite-tsconfig-paths": "^4.3.2"
8080
},
8181
"dependencies": {
82+
"@bigmi/react": "^0.1.0",
8283
"@cyntler/react-doc-viewer": "^1.17.0",
8384
"@graphql-tools/batch-execute": "^9.0.11",
8485
"@graphql-tools/utils": "^10.7.2",
8586
"@kleros/kleros-app": "workspace:^",
8687
"@kleros/kleros-sdk": "workspace:^",
8788
"@kleros/kleros-v2-contracts": "workspace:^",
8889
"@kleros/ui-components-library": "^2.20.0",
89-
"@lifi/wallet-management": "^3.4.6",
90-
"@lifi/widget": "^3.12.3",
90+
"@lifi/wallet-management": "^3.6.0",
91+
"@lifi/widget": "^3.14.2",
92+
"@reown/appkit": "^1.6.5",
93+
"@reown/appkit-adapter-wagmi": "^1.6.5",
9194
"@sentry/react": "^7.120.0",
9295
"@sentry/tracing": "^7.120.0",
96+
"@solana/wallet-adapter-react": "^0.15.35",
9397
"@tanstack/react-query": "^5.62.2",
9498
"@types/react-modal": "^3.16.3",
9599
"@wagmi/connectors": "^5.5.0",
96100
"@wagmi/core": "^2.15.0",
97-
"@web3modal/wagmi": "^4.2.3",
98101
"@yornaath/batshit": "^0.9.0",
99102
"chart.js": "^3.9.1",
100103
"chartjs-adapter-moment": "^1.0.1",

web/src/components/ConnectWallet/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useCallback } from "react";
22

3-
import { useWeb3Modal, useWeb3ModalState } from "@web3modal/wagmi/react";
3+
import { useAppKit, useAppKitState } from "@reown/appkit/react";
44
import { useAccount, useSwitchChain } from "wagmi";
55

66
import { Button } from "@kleros/ui-components-library";
@@ -35,8 +35,8 @@ export const SwitchChainButton: React.FC<{ className?: string }> = ({ className
3535
};
3636

3737
const ConnectButton: React.FC<{ className?: string }> = ({ className }) => {
38-
const { open } = useWeb3Modal();
39-
const { open: isOpen } = useWeb3ModalState();
38+
const { open } = useAppKit();
39+
const { open: isOpen } = useAppKitState();
4040
return (
4141
<Button
4242
{...{ className }}

web/src/consts/chains.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import { extractChain } from "viem";
2-
import { Chain, arbitrum, mainnet, arbitrumSepolia, gnosis, gnosisChiado } from "viem/chains";
1+
import { type AppKitNetwork, arbitrum, mainnet, arbitrumSepolia, gnosis, gnosisChiado } from "@reown/appkit/networks";
2+
import { type Chain, extractChain } from "viem";
33

44
import { isProductionDeployment } from "./index";
55

66
export const DEFAULT_CHAIN = isProductionDeployment() ? arbitrum.id : arbitrumSepolia.id;
77

88
// Read/Write
9-
export const SUPPORTED_CHAINS: Record<number, Chain> = {
9+
export const SUPPORTED_CHAINS: Record<number, AppKitNetwork> = {
1010
[isProductionDeployment() ? arbitrum.id : arbitrumSepolia.id]: isProductionDeployment() ? arbitrum : arbitrumSepolia,
1111
};
1212

1313
// Read Only
14-
export const QUERY_CHAINS: Record<number, Chain> = {
14+
export const QUERY_CHAINS: Record<number, AppKitNetwork> = {
1515
[isProductionDeployment() ? gnosis.id : gnosisChiado.id]: isProductionDeployment() ? gnosis : gnosisChiado,
1616
[mainnet.id]: mainnet,
1717
};

web/src/consts/eip712-messages.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { arbitrumSepolia } from "viem/chains";
21
import { DEFAULT_CHAIN } from "./chains";
32

43
export default {
@@ -23,7 +22,7 @@ export default {
2322
telegram,
2423
nonce,
2524
},
26-
} as const),
25+
}) as const,
2726
signingAccount: (address: `0x${string}`, chainId: number = DEFAULT_CHAIN) =>
2827
({
2928
account: address.toLowerCase() as `0x${string}`,
@@ -42,5 +41,5 @@ export default {
4241
"create a secret key for your account. This key is unrelated from your main Ethereum account and will " +
4342
"not be able to send any transactions.",
4443
},
45-
} as const),
44+
}) as const,
4645
};

web/src/context/Web3Provider.tsx

+31-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
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, gnosisChiado, sepolia, gnosis } from "wagmi/chains";
7-
import { walletConnect } from "wagmi/connectors";
3+
import {
4+
mainnet,
5+
arbitrumSepolia,
6+
arbitrum,
7+
gnosisChiado,
8+
sepolia,
9+
gnosis,
10+
type AppKitNetwork,
11+
} from "@reown/appkit/networks";
12+
import { createAppKit } from "@reown/appkit/react";
13+
import { WagmiAdapter } from "@reown/appkit-adapter-wagmi";
14+
import { fallback, http, WagmiProvider, webSocket } from "wagmi";
815

916
import { configureSDK } from "@kleros/kleros-sdk/src/sdk";
1017

@@ -66,18 +73,18 @@ export const getTransports = () => {
6673
};
6774
};
6875

69-
const chains = ALL_CHAINS as [Chain, ...Chain[]];
76+
const chains = ALL_CHAINS as [AppKitNetwork, ...AppKitNetwork[]];
7077
const transports = getTransports();
7178

7279
const projectId = import.meta.env.WALLETCONNECT_PROJECT_ID;
7380
if (!projectId) {
7481
throw new Error("WalletConnect project ID is not set in WALLETCONNECT_PROJECT_ID environment variable.");
7582
}
7683

77-
const wagmiConfig = createConfig({
78-
chains,
84+
const wagmiAdapter = new WagmiAdapter({
85+
networks: chains,
86+
projectId,
7987
transports,
80-
connectors: [walletConnect({ projectId, showQrModal: false })],
8188
});
8289

8390
configureSDK({
@@ -87,18 +94,28 @@ configureSDK({
8794
},
8895
});
8996

90-
createWeb3Modal({
91-
wagmiConfig,
97+
createAppKit({
98+
adapters: [wagmiAdapter],
99+
networks: chains,
100+
defaultNetwork: isProduction ? arbitrum : arbitrumSepolia,
92101
projectId,
93-
defaultChain: isProduction ? arbitrum : arbitrumSepolia,
102+
allowUnsupportedChain: true,
94103
themeVariables: {
95104
"--w3m-color-mix": lightTheme.primaryPurple,
96105
"--w3m-color-mix-strength": 20,
106+
// overlay portal is at 9999
107+
"--w3m-z-index": 10000,
108+
},
109+
features: {
110+
// adding these here to toggle in futute if needed
111+
// email: false,
112+
// socials: false,
113+
// onramp:false,
114+
// swap: false
97115
},
98116
});
99-
100117
const Web3Provider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
101-
return <WagmiProvider config={wagmiConfig}> {children} </WagmiProvider>;
118+
return <WagmiProvider config={wagmiAdapter.wagmiConfig}> {children} </WagmiProvider>;
102119
};
103120

104121
export default Web3Provider;

web/src/pages/GetPnk/WalletProvider.tsx

+19-15
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import React, { useRef, type FC, type PropsWithChildren } from "react";
22

33
import { useSyncWagmiConfig } from "@lifi/wallet-management";
44
import { useAvailableChains } from "@lifi/widget";
5+
import { mainnet, arbitrumSepolia, arbitrum } from "@reown/appkit/networks";
6+
import { createAppKit } from "@reown/appkit/react";
7+
import { WagmiAdapter } from "@reown/appkit-adapter-wagmi";
58
import { injected, walletConnect } from "@wagmi/connectors";
6-
import { createWeb3Modal } from "@web3modal/wagmi";
79
import { createClient, http } from "viem";
8-
import { arbitrum, arbitrumSepolia, mainnet } from "viem/chains";
9-
import type { Config } from "wagmi";
10-
import { createConfig, WagmiProvider } from "wagmi";
10+
import { WagmiProvider } from "wagmi";
1111

1212
import { isProductionDeployment } from "consts/index";
1313

@@ -19,32 +19,36 @@ const connectors = [injected(), walletConnect({ projectId })];
1919

2020
export const WalletProvider: FC<PropsWithChildren> = ({ children }) => {
2121
const { chains } = useAvailableChains();
22-
const wagmi = useRef<Config>();
22+
const adapter = useRef<WagmiAdapter>();
2323

24-
if (!wagmi.current) {
25-
wagmi.current = createConfig({
26-
chains: [mainnet],
24+
if (!adapter.current) {
25+
adapter.current = new WagmiAdapter({
26+
networks: [mainnet],
27+
projectId,
2728
client({ chain }) {
2829
return createClient({ chain, transport: http() });
2930
},
30-
ssr: true,
3131
});
3232
}
3333

34-
useSyncWagmiConfig(wagmi.current, connectors, chains);
34+
useSyncWagmiConfig(adapter.current.wagmiConfig, connectors, chains);
3535

36-
createWeb3Modal({
37-
wagmiConfig: wagmi.current,
38-
projectId,
39-
defaultChain: isProductionDeployment() ? arbitrum : arbitrumSepolia,
36+
createAppKit({
37+
adapters: [adapter.current],
38+
networks: [mainnet],
39+
defaultNetwork: isProductionDeployment() ? arbitrum : arbitrumSepolia,
4040
allowUnsupportedChain: true,
41+
projectId,
4142
themeVariables: {
4243
"--w3m-color-mix": lightTheme.primaryPurple,
4344
"--w3m-color-mix-strength": 20,
45+
// overlay portal is at 9999
46+
"--w3m-z-index": 10000,
4447
},
4548
});
49+
4650
return (
47-
<WagmiProvider config={wagmi.current} reconnectOnMount={false}>
51+
<WagmiProvider config={adapter.current.wagmiConfig} reconnectOnMount={false}>
4852
{children}
4953
</WagmiProvider>
5054
);

0 commit comments

Comments
 (0)